Forum Moderators: coopster
<?phpmysql_connect("localhost", "username", "password")
or die("Sorry We are unable to Connect to the Database at this time");
mysql_select_db("webvisits")
or die("We are unable to locate the required table for this operation");
$message = 'Username';
$checkusername = $_POST['username'];
$check = mysql_query("SELECT username FROM auth_users WHERE username = '$checkusername'");
$check2 = mysql_num_rows($check);
if ($_POST) {
if ($check2 != 0) {
$message = 'Username taken. Please try another';
}
else
{
$_POST['password'] = md5($_POST['password']);
if (!get_magic_quotes_gpc()) {
$_POST['password'] = addslashes($_POST['password']);
$_POST['username'] = addslashes($_POST['username']);
}
$insert = "INSERT INTO auth_users (username, password)
VALUES ('".$_POST['username']."', '".$_POST['password']."')
INSERT INTO users_detail (username, first_name)
VALUES ('".$_POST['username']."', '".$_POST['firstname']."')";
$add_member = mysql_query($insert)
or die ("Unable to Execute Query");
If ($add_member) {header( "Location:loginform.html");}
}
}
?>
For some reason the query does not execute resulting in the die message "unable to execute Query" I have checked the db, table and field names and they all match (assuming I have not overlooked something). Can anyone assist.....also any general comments or pointers always welcome.
Many thanks for your time.
P.S Also can anyone tell me a better way to insert sample code onto the forum as to retain formatting of the code (its been a long day) :)
Here it is...
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO users_detail (username, first_name) VALUES ('John', 'John'' at line 3
does this mean line 3 of the insert section or line 3 of the script (Line 3 on my script is currently a comment - taken out for the purpose of posting here)
Thanks
So, change this:
$insert = "INSERT INTO auth_users (username, password)
VALUES ('".$_POST['username']."', '".$_POST['password']."')
INSERT INTO users_detail (username, first_name)
VALUES ('".$_POST['username']."', '".$_POST['firstname']."')"; $add_member = mysql_query($insert)
or die ("Unable to Execute Query");
to this:
$insert1 = "INSERT INTO auth_users (username, password)
VALUES ('".$_POST['username']."', '".$_POST['password']."')";
$insert2 = "INSERT INTO users_detail (username, first_name)
VALUES ('".$_POST['username']."', '".$_POST['firstname']."')"; $add_member = mysql_query($insert1)
or die ("Unable to Execute Query 1");
$add_member = mysql_query($insert2)
or die ("Unable to Execute Query 2");
It's hard to read what I'm writing on here, but that should work.
You should print out the exact value of $insert to make sure that the constructed statement is exactly what you expect.
Can any one point me in the right direction in to how the data can be remembered. At this time in my head I think it will have something to do with a cookie or using POST.
Thanks for all your assistance.