This question already has an answer here:
- Can I mix MySQL APIs in PHP? 4 answers
My code was working but after I inserted a query to check if the first name in MYSQL database already exists, it does not work anymore. Here you can see my code, if you have any tip on how to make this work, I will appreciate it. Thank you very much!
I have tried to work with mysql_num_rows command, but it seems like I didn't use it correctly.
<?php
require_once __DIR__.'/connect.php';
$sName = $_POST['txtName'];
$query = mysql_query("SELECT * FROM users WHERE firstName = '$sName' ");
if (mysql_num_rows ($query) > 0){
echo 'User with this name already exists';
}else{
try {
$stmt = $db->prepare('INSERT INTO users
VALUES (null, :sName, :sLastName, :sEmail, :sCountry )');
$stmt->bindValue(':sName', $sName);
$stmt->execute();
echo 'New user was successfully inserted';
} catch (PDOEXception $ex) {
echo $ex;
}
}
</div>