Modernvox Posted January 25, 2010 Share Posted January 25, 2010 Hello Guyz, I am almost through O'reilly's book on php and mysql. VALUES will not enter DB? First my form: <form action="reg_success.php" method="POST"> <table> <tr> <td><font face= "tahoma" size= "2">Name</font></td> <td><input type= "text" name= "regname" size= "35" /></td> <td><br><br></td> </tr> <tr> <td><font face= "tahoma" size= "2">State</font></td> <td><input type= "text" name= "regstate" size= "35" /></td> <td><br><br></td> </tr> </tr> <td><font face= "tahoma" size= "2">City</font></td> <td><input type="text" name= "regcity" size= "35" /></td> <td><br><br></td> </tr> <tr> <td><font face= "tahoma" size= "2">Email</font></td> <td><input type="text" name= "regemail" size= "35" /></td> </tr> <tr> <td><br></td> </tr> <tr> <td><br></td> </tr> <tr> <td><br></td> </tr> <tr> <td><br></td> </tr> <tr> <td><font face= "tahoma" size= "2">Choose a username</font></td> <td><input type= "text" name= "username" size "35"/></td> </tr> <tr> <td><br></td> </tr> <tr> <td><font face= "tahoma" size= "2">Choose a password</font></td> <td><input type= "pass" name= "password" size "35"/></td> </tr> <tr> <td><font face= "tahoma" size= "2">Confirm password</font></td> <td><input type= "pass" name= "confirmpass" size "35"/></td> </tr> <tr> <td><br></td> </tr> <tr> <td><br></td> </tr> </table> <center><input type="submit" name="submit" value= "register" /></center> </form></font> and now my process registration page script... <php if ((isset($_POST['submit'])) && (!empty($_POST['regname'])) && (!empty($_POST['regstate'])) && (!empty($_POST['regcity'])) && (!empty($_POST['regemail'])) && (!empty($_POST['username'])) && (!empty($_POST['password'])) && (!empty($_POST['confirmpass']))) { $reg_name= $_POST['regname']; $reg_state= $_POST['regstate']; $reg_city= $_POST['regcity']; $reg_email= $_POST['regemail']; $reg_username= $_POST['username']; $reg_password= $_POST['password']; $reg_confirmpass= $_POST['confirmpass']; $database= register; $dbx =mysql_connect('localhost', 'root', ""); if (!$dbx) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database); if (!mysql_select_db) { die ("Could not select the database: <br />" . mysql_error()); } $insert_query = "INSERT INTO users ('regname', 'regstate', 'regcity', 'regemail', 'username', 'password', ) VALUES ('$reg_name','$reg_state''$reg_city','$reg_email','$reg_username', '$reg_password')"; ); $result= mysql_query($insert_query); if (!$result){ die ("Could not query the database: <br />". mysql_error()); mysql_close)$connection) ?> No matter what I do I keep getting this error: " . mysql_error()); } $insert_query = "INSERT INTO users ('regname', 'regstate', 'regcity', 'regemail', 'username', 'password', ) VALUES ('$reg_name','$reg_state''$reg_city','$reg_email','$reg_username', '$reg_password')"; ); $result= mysql_query($insert_query); if (!$result){ die ("Could not query the database: ". mysql_error()); mysql_close)$connection) YOUR HELP IS GREATLY APPRECIATED ON THIS MATTER.. Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/ Share on other sites More sharing options...
Mchl Posted January 25, 2010 Share Posted January 25, 2010 'This error' means what? You pasted a piece of code, not an actual helpful error message. One thing I can tell you, this is wrong mysql_close)$connection) Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/#findComment-1001491 Share on other sites More sharing options...
PFMaBiSmAd Posted January 25, 2010 Share Posted January 25, 2010 That's no error. It is raw php code. Your opening php tag is not one. Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/#findComment-1001492 Share on other sites More sharing options...
wildteen88 Posted January 25, 2010 Share Posted January 25, 2010 Just looking at your code I can see multiple syntax errors First is line 1 <php That is an invalid tag, It should be <?php Line 21 - 22 is incorrect mysql_select_db($database); if (!mysql_select_db) It should be $db_selected = mysql_select_db($database); if (!$db_selected) Line 41 ); I don't know what that is? Delete it You have a missing closing brace } after line 45 44. if (!$result){ 45. die ("Could not query the database: <br />". mysql_error()); 46. } Line 46 is incorrect mysql_close)$connection) It should be mysql_close($dbx); Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/#findComment-1001495 Share on other sites More sharing options...
Mchl Posted January 25, 2010 Share Posted January 25, 2010 Maybe you should get some sleep? Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/#findComment-1001496 Share on other sites More sharing options...
Modernvox Posted January 25, 2010 Author Share Posted January 25, 2010 Maybe you should get some sleep? lol... No what i did was mismatch the code from the book with mine and messed it up..Anyhow, I made all requested changes and now I get an unexpected unexpected $end. updated code <?php if ((isset($_POST['submit'])) && (!empty($_POST['regname'])) && (!empty($_POST['regstate'])) && (!empty($_POST['regcity'])) && (!empty($_POST['regemail'])) && (!empty($_POST['username'])) && (!empty($_POST['password'])) && (!empty($_POST['confirmpass']))) { $reg_name= $_POST['regname']; $reg_state= $_POST['regstate']; $reg_city= $_POST['regcity']; $reg_email= $_POST['regemail']; $reg_username= $_POST['username']; $reg_password= $_POST['password']; $reg_confirmpass= $_POST['confirmpass']; $database= register; $dbx =mysql_connect('localhost', 'root', ""); if (!$dbx) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db($database); if (!$db_selected) { die ("Could not select the database: <br />" . mysql_error()); } $insert_query = "INSERT INTO users ('regname', 'regstate', 'regcity', 'regemail', 'username', 'password', ) VALUES ('$reg_name','$reg_state''$reg_city','$reg_email','$reg_username', '$reg_password')"; $result= mysql_query($insert_query); if (!$result){ die ("Could not query the database: <br />". mysql_error()); } mysql_close($dbx); ?> Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/#findComment-1001497 Share on other sites More sharing options...
Modernvox Posted January 25, 2010 Author Share Posted January 25, 2010 Ok i left out the if's closing tab at the bottom noe I have: Could not query the database: 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 ''regname', 'regstate', ' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/#findComment-1001500 Share on other sites More sharing options...
Mchl Posted January 25, 2010 Share Posted January 25, 2010 Remove the , after password in column list. Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/#findComment-1001503 Share on other sites More sharing options...
Modernvox Posted January 25, 2010 Author Share Posted January 25, 2010 The ID field doesn't count as a VALUE position , right? In other words that field doesn't screw up the position the VALUES are inserted? I'm positive I am using the wrong syntax to input this data because I'm using variables. Maybe quotes, double quotes, semicolons, etc.. Is there a good tutorial on these syntax characters? Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/#findComment-1001507 Share on other sites More sharing options...
Modernvox Posted January 25, 2010 Author Share Posted January 25, 2010 Remove the , after password in column list. That did nothing... Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/#findComment-1001510 Share on other sites More sharing options...
PFMaBiSmAd Posted January 25, 2010 Share Posted January 25, 2010 Column names, table names, and keywords (function names, data types...) are not enclosed in single-quotes as that would make them string data. Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/#findComment-1001511 Share on other sites More sharing options...
Modernvox Posted January 25, 2010 Author Share Posted January 25, 2010 When I change the INSERT INTO users from 'regname' etc.. to "regname" (double quotes) I get this error now: Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\IWannaJam\cool.php on line 27 What am I suppose to be using here for syntax? Here's my DB order Fields: id regname regstate regcity regemail username password Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/#findComment-1001514 Share on other sites More sharing options...
Mchl Posted January 25, 2010 Share Posted January 25, 2010 They shouldn't be enclosed in ANY quotes. If anything you can use backticks ``, but they're optional. Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/#findComment-1001516 Share on other sites More sharing options...
Modernvox Posted January 25, 2010 Author Share Posted January 25, 2010 They shouldn't be enclosed in ANY quotes. If anything you can use backticks ``, but they're optional. Yeah..Took them all out a few minutes ago and it worked. Could U or someone direct me to a great tutorial on syntax, because I came across quite a few pages online showing DB queries with quotes around COLUMN keywords and this book I have been reading I (finally just found the proper example, because all the previous examples were just showing how to input values and not match COLUMNS with VALUES) Where is a good place to learn all of PHP' syntax? Thanks to everyone who posted on this topic. Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/#findComment-1001521 Share on other sites More sharing options...
Mchl Posted January 25, 2010 Share Posted January 25, 2010 Head here for PHP syntax, and this way for MySQL's. These sites never failed me. Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/#findComment-1001525 Share on other sites More sharing options...
Modernvox Posted January 25, 2010 Author Share Posted January 25, 2010 Head here for PHP syntax, and this way for MySQL's. These sites never failed me. Great, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/189773-day-2-1-book-read-and-still-showing-error-please-help/#findComment-1001572 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.