Hello I have te following PDO insert into database function, how I can check if there is such a recored inside the database already to give error that the user is already registred with this information ? My table is organized like that
id | curso_id | user_id
1 | 12 | 43
2 | 5 | 56
so if a combination of curso_id = 12 and user_id = 43 is inside the database do not register second one of this kind, give error.
$userid = $_SESSION['userID'];
$cursoid = $_GET["id"];
try {
$con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); //our new PDO Object
$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$stmt = $con->prepare( "Insert Into subscriptions ( curso_id, user_id ) Values ('$cursoid', '$userid')" );
$stmt->execute();
} catch (PDOException $e) {
echo "I'm sorry there is a problem with your operation.."; $e->getMessage(); //catch and show the error
}
$con = null;
header( 'Location: cursos.php' ) ;
}
Thanks for the help in advance