Problem with: (!mysql_query($sql,$connection))
Posted: Sat Oct 12, 2002 5:18 pm
I am trying to create a login using php4 and mysql, the database exists and the general mysql access is in an include which is called at the start of the script.
The problem I am having is with the following line:
The script is below.
Thanks.
The problem I am having is with the following line:
as I keep getting the errorif (!mysql_query($sql,$connection)) {
thrown back at me from my script, anyone any ideas as to what the problem might be that is causing this?"Error cannot add record..Check out MySQL";
The script is below.
Thanks.
Code: Select all
<?php
<HTML>
<BODY>
<?php
# register_add.php
# load include login to mysql
require("conn_inc_reg.php");
$login=$_POSTї'login'];
$password=$_POSTї'password'];
$password2=$_POSTї'password2'];
echo "<CENTER><B>Delivery etc Registration Form</B><CENTER>";
$error=false;
$pass_error=false;
if (( $login == "" ) || ( $password == "" ) || ( $password2 == "" ) ) {
$error=true;
}
if ( $password != $password2 ) {
$pass_error=true;
}
if ($error) {
echo "<BR>All fields need to be filled in";
}
if ($pass_error) {
echo "<BR>Both the passwords fields need to match";
}
if (($error) || ($pass_error)) {
echo "<BR>Back to the register <A HREF="register.php"> form</A>";
exit;
}
# if we are here then we have OK
$sql="INSERT INTO users (login,password) VALUES ('$login','$password')";
$sql2="SELECT * FROM users WHERE login='$login' AND password='$password'";
# check for duplicate entry in the users table
$mysql_result=mysql_query($sql2,$connection);
# supress any errors with @
$num_rows=@mysql_num_rows($mysql_result);
if ( $num_rows != 0 ) {
echo "<BR>This login is already in use, choose another <A HREF="register.php"> back</A>";
exit;
}
# insert login/password
if (!mysql_query($sql,$connection)) {
echo "Error cannot add record..Check out MySQL";
echo "<BR><A HREF="register.php"> back</A>";
exit;
} else {
# insert OK inform user
echo "Table updated ї".mysql_affected_rows()."] record added<BR>";
echo "Welcome.....Please make a note of your details<BR>";
echo "Login ID:<B>$login</B> Password:<B>$password</B>";
echo "<BR>Go to Members <A HREF="loginpage.php"> login page</A>";
}
mysql_close($connection);
?>
</BODY>
</HTML>
?>