jvo Posted April 12, 2006 Share Posted April 12, 2006 I am trying to implement a website using PHP and so far it's going rather well. Today I ran upon a bit of a hiccup. I've written some code folloing a tutorial that allows people to enter information to a database and it worked fine for a little while. But now it's broken. On the user end, it looks like it works, but when I actually browse the contents of the database, the information has not been added. I'm relatively new to the PHP/MySQL platform but as I'm not so familiar with the syntax yet, I could very well be over looking something quite simple. Below is the code from the two pages I have.SIGNUP.HTML<html><head> <title>.:: New User ::. </title></head><body><font face="arial" pt size=1><form action="insert.php" method="post">Username: <input type="text" name="user"><br>Password: <input type="password" name="password"><br>Confirm Password: <input type="password" name="password"><br>Email: <input type="text" name="email"><br>First Name: <input type="text" name="first"><br>Last Name: <input type="text" name="last"><br>Primary Contact: <input type="text" name="phone"><br>Age: <input type="text" name="age"><br>Gender: <input type="radio" name="gender" value="M">Male <input type="radio" name="gender" value="F">Female<br><input type="Submit"></form></body></html>INSERT.PHP<?phpinclude("library/dblogin.php");$user=$_POST['user'];$password=$_POST['password'];$email=$_POST['email'];$first=$_POST['first'];$last=$_POST['last'];$phone=$_POST['phone'];$age=$_POST['age'];$gender=$_POST['gender'];$query = "INSERT INTO users VALUES('','$user','$password','$email','$first','$last','$phone','$age','$gender','0')";mysql_query($query);mysql_close();?><html><head><title> .:: New User ::. </title></head><body><font face="arial" pt size="1"><p align="center">Your account has been successfully created.<br>Thank you for registering. <br></p></body></html>So there it is. Is there any reason why this code shouldn't work? Any insight would be helpful. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 12, 2006 Share Posted April 12, 2006 If nothing is being added to your Database then there is a likely chance you have an error with your Query. To find out change this:[code]mysql_query($query);[/code]to:[code]mysql_query($query) or die("Error: " . mysql_error());[/code]Run you code again this time if there is a problem with your query it'll stop the script and show an error message. if it does return an error, post the full error message here and we'll try to help. Quote Link to comment Share on other sites More sharing options...
jvo Posted April 12, 2006 Author Share Posted April 12, 2006 [!--quoteo(post=364165:date=Apr 12 2006, 03:26 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 12 2006, 03:26 PM) [snapback]364165[/snapback][/div][div class=\'quotemain\'][!--quotec--]If nothing is being added to your Database then there is a likely chance you have an error with your Query. To find out change this:[code]mysql_query($query);[/code]to:[code]mysql_query($query) or die("Error: " . mysql_error());[/code]Run you code again this time if there is a problem with your query it'll stop the script and show an error message. if it does return an error, post the full error message here and we'll try to help.[/quote]Hey, thanks so much for the fast reply. I did exactly what you said and here's what I get[i]Error: 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 ''users' VALUES ('','johndoe','0000','john@doe.com','John','D[/i]I'm rechecking my code now, but it still looks fine. Any advise? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 12, 2006 Share Posted April 12, 2006 Add echoing the $query in the "or die" clause:[code]<?phpmysql_query($query) or die("Error in query: $query<br>" . mysql_error());?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.