This was working fine while I was testing it locally, but after trying to use a remote mysql server its started throwing errors. The main one I cant figure out being,
"Parse error: syntax error, unexpected T_STRING in G:\wamp\www\OnlineBank\bank.php on line 92"
$query = "SELECT user_name FROM Customers";
$result = mysql_query($query);
(--> line 92) while ($row = mysql_fetch_array($result) or die mysql_error())
开发者_JS百科 {
if ($username == $row['user_name'])
{
echo "<script>alert('User name is taken')</script>";
...
}
as far as i'm aware that error is usually thrown for unescaped quotes and stuff, I just can't figure out why its happening here, any help is greatly appreciated.
That particular parse error stems from the fact that you need to surround arguments to die
in parentheses:
or die(mysql_error())
The other answers hit on other points that may be wrong in your code though.
I doubt that this was ever working; the error is caused by the or die mysql_error()
within the while-condition.
Move that to the line above, like
$result = mysql_query($query) or die mysql_error();
There will be no (mysql related) errors when using mysql_fetch_array(), so the check is pointless there anyway.
If you insist on keeping it in the while-condition you have to use parentheses -> die( mysql_error() )
while ($row = mysql_fetch_array($result) or die mysql_error())
Firstly, you do not need to call mysql_error()
in this situation. All you have to do is to call it if mysql_query()
returns FALSE
:
$query = "SELECT user_name FROM Customers";
$result = mysql_query($query);
if( $result==false ){
die(mysql_error());
}
Furthermore, mysql_fetch_array()
returns FALSE
every time it reaches the end of set of elements retrieved from MySQL. So, in common way, you have no need to use or die mysql_error()
in this loop.
精彩评论