PHP – проверьте, существует ли индекс в SQL ⇐ Php
-
Гость
PHP – проверьте, существует ли индекс в SQL
I'm new to PHP and am practicing by programming a very basic signup form, which dumps the info into a MySQL database. However, I'm having a problem where, even if the name is taken, my program still adds the account to the SQL table. This is my code to check if the name exists:
$sql = "SELECT * FROM accounts WHERE name = '$name'"; $result = $conn->query($sql); if (mysql_fetch_array($result) === true) { die("Error: Username has been taken"); } else { //register account } Every time I run this, no matter what the name is, the program runs the block of code inside the else statement. I can provide more info if needed.
Источник: https://stackoverflow.com/questions/454 ... sts-in-sql
I'm new to PHP and am practicing by programming a very basic signup form, which dumps the info into a MySQL database. However, I'm having a problem where, even if the name is taken, my program still adds the account to the SQL table. This is my code to check if the name exists:
$sql = "SELECT * FROM accounts WHERE name = '$name'"; $result = $conn->query($sql); if (mysql_fetch_array($result) === true) { die("Error: Username has been taken"); } else { //register account } Every time I run this, no matter what the name is, the program runs the block of code inside the else statement. I can provide more info if needed.
Источник: https://stackoverflow.com/questions/454 ... sts-in-sql
Мобильная версия