Rother2005 Posted December 31, 2006 Share Posted December 31, 2006 hi im new to PHP, im just having a play about really before i begin college next yearive tried to do a login form, real basic just one page with a form to compelete and once you submit the data goes into the databaseive got this so far:<?phpinclude('connect1.inc');?><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Booze Cruise Reg</title></head><body><?php if(!$_POST['register']){echo'<p align="center"><strong>Member Registration</strong></p><form name="form1" method="POST" action=""><p align="center">Username: <input type="text" name="username"></p><p align="center">Password: <input type="text" name="password"></p><p align="center">Firsname: <input type="text" name="firstname"></p><p align="center">Surname: <input type="text" name="surname"></p><p align="center">Address1: <input type="text" name="address1"></p><p align="center">Address2: <input type="text" name="address2"></p><p align="center">Town: <input type="text" name="town"></p><p align="center">County: <input type="text" name="county"></p><p align="center">Postcode: <input type="text" name="postcode"></p><p align="center">Tel No: <input type="text" name="telno"></p><p align="center">Mobile: <input type="text" name="mobile"></p><p align="center">Email: <input type="text" name="email"></p><p align="center"><input type="submit" name="register" value="Enter Details"></p></form>';} else{$username=$_POST['username'];$password=$_POST['password'];$firstname=$_POST['firstname'];$surname=$_POST['surname'];$address1=$_POST['address1'];$address2=$_POST['address2'];$town=$_POST['town'];$county=$_POST['county'];$postcode=$_POST['postcode'];$telno=$_POST['telno'];$mobile=$_POST['mobile'];$email=$_POST['email'];$sql = "INSERT INTO member(Username,Password,Firstname,Surname,Address 1,Address 2,Town,County,Postcode,Tel No,Mobile,Email) VALUES ('"$_POST['username']."',$_POST['password']."',$_POST['firstname']."',$_POST['surname']."',$_POST['address1']."',$_POST['address2']."',=$_POST['town']."',$_POST['county']."',$_POST['postcode']."',$_POST['telno']."',$_POST['mobile']."',$_POST['email']."')";mysql_query($sql) or die("Couldn't execute query - add new member. Sorry $username");echo("You are registered! $username");}?></body></html>the error i get is "Couldn't execute query - add new member. Sorry $username" , the $username works no probs and displays it on the next screen so its writing the data to memory (if that what is does!!) but not to my database now ive been tryin for 3 weeks so finally ive broken down with stress and thought i need help ???here is the .inc file also:<?php$connection=mysql_connect("localhost","root","");mysql_select_db(booze) or die(mysql_error());?>many thanks in advance Link to comment https://forums.phpfreaks.com/topic/32408-solved-help-with-login-form/ Share on other sites More sharing options...
dcro2 Posted December 31, 2006 Share Posted December 31, 2006 Try echoing mysql_error() to see what the error is.Also, never use .inc as an include extension, use .inc.php so the source doesn't show up in a browser when that file is accessed. Link to comment https://forums.phpfreaks.com/topic/32408-solved-help-with-login-form/#findComment-150521 Share on other sites More sharing options...
fert Posted December 31, 2006 Share Posted December 31, 2006 change[code]or die("Couldn't execute query - add new member. Sorry $username");[/code]to[code]or die(mysql_error());[/code] Link to comment https://forums.phpfreaks.com/topic/32408-solved-help-with-login-form/#findComment-150522 Share on other sites More sharing options...
Rother2005 Posted December 31, 2006 Author Share Posted December 31, 2006 fert ive changed the code and this is the resultParse error: parse error, unexpected T_VARIABLE in C:\Program Files\xampp\htdocs\Loginpage.php on line 32the line that begins with 'values' Link to comment https://forums.phpfreaks.com/topic/32408-solved-help-with-login-form/#findComment-150533 Share on other sites More sharing options...
dcro2 Posted December 31, 2006 Share Posted December 31, 2006 I see something there... the quotes are kind of messed up.Replace[quote]VALUES ('"$_POST['username']."',$_POST['password']."',$_POST['firstname']."',$_POST['surname']."',$_POST['address1']."',$_POST['address2']."',=$_POST['town']."',$_POST['county']."',$_POST['postcode']."',$_POST['telno']."',$_POST['mobile']."',$_POST['email']."')";[/quote]With:[quote]VALUES ('".$_POST['username']."','".$_POST['password']."','".$_POST['firstname']."','".$_POST['surname']."','".$_POST['address1']."','".$_POST['address2']."','".$_POST['town']."','".$_POST['county']."','".$_POST['postcode']."','".$_POST['telno']."','".$_POST['mobile']."','".$_POST['email']."')";[/quote]Basically, you missed some dots and some single and double quotes. One tip though, you assigned each of these POST values to variables earlier, you could use those to avoid confusion:[quote]VALUES ('$username','$password','$firstname','$surname','$address1','$address2','$town','$county','$postcode','$telno','$mobile','$email')";[/quote]And, again, please don't use .inc as a include extension. It's dangerous :D Link to comment https://forums.phpfreaks.com/topic/32408-solved-help-with-login-form/#findComment-150554 Share on other sites More sharing options...
Rother2005 Posted December 31, 2006 Author Share Posted December 31, 2006 ok ur a star for helpingthis new error is coming upYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1,Address 2,Town,County,Postcode,Tel No,Mobile,Email) VALUES ('a','b','c','d',' at line 1ive check my spelling in the database and it matches the one on the insert into line (line 31) is the space a problem 'address 1'?HAPPY NEW YEAR!!ps i used the VALUES ('$username','$password','$firstname','$surname','$address1','$address2','$town','$county','$postcode','$telno','$mobile','$email')"; line Link to comment https://forums.phpfreaks.com/topic/32408-solved-help-with-login-form/#findComment-150561 Share on other sites More sharing options...
dcro2 Posted January 1, 2007 Share Posted January 1, 2007 Try renaming the field names without spaces in the database and in the script. (Address 1 -> Address1), etc. Link to comment https://forums.phpfreaks.com/topic/32408-solved-help-with-login-form/#findComment-150573 Share on other sites More sharing options...
Rother2005 Posted January 1, 2007 Author Share Posted January 1, 2007 u sir are a GOD!!! thank you very much for ur help and taking the time to help meall the best for the new year ;D Link to comment https://forums.phpfreaks.com/topic/32408-solved-help-with-login-form/#findComment-150585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.