devang23 Posted December 5, 2009 Share Posted December 5, 2009 this is the code, and i keep getting a t string syntax on line 24 <html><head><title>Adding a User </title></head> <body> <?php if( (!$firstname) or (!$lastname) or (!$username) or (!$password) ) { $form ="Please enter all new user details"; $form.="<form action=\"$PHP_SELF\""; $form.=" method=\"post\">First Name: "; $form.="<input type=\"text\" name=\firstname\""; $form.=" value=\"$firstname\"><br>Last Name: "; $form.="<input type=\"text\" name=\"lastname\""; $form.=" value=\"$lastname\"><br>UserName: "; $form.="<input type=\"text\" name=\"username\""; $form.=" value=\"$username\"><br>PassWord: "; $form.="<input type=\"text\" name=\"password\""; $form.=" value=\"$password\"><br>"; $form.="<input type=\"submit\" value=\"Submit\">"; $form.="</form>"; echo($form); } else { $conn = mysql_connect("mysql4.000webhost.com")or die("Try Again Punk"); $db = mysql_select_db("a3213677_snorre",$conn)or die("NOOPE"); $sql = insert into User Table(first_name,last_name,user_name,password) values(\"$firstname\",\"$lastname\",\"$username\",password(\$password\") )"; $result = mysql_query($sql,$conn)or die ("NOT EVEN"); if($result) { echo("New User $username ADDED DUH!"); } } ?> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/184108-annoying-syntax-can-anyone-help-fix-it/ Share on other sites More sharing options...
Alex Posted December 5, 2009 Share Posted December 5, 2009 You had some mistakes with your quotes when defining your $sql variable. Try: $sql = "insert into User Table(first_name,last_name,user_name,password) values('$firstname','$lastname','$username',password('$password'))"; I'd also suggest you don't use the MySQL PASSWORD() function to store your passwords. It has changed in the past and it's a possibility that it will change again, and if it does it would break your application. Quote Link to comment https://forums.phpfreaks.com/topic/184108-annoying-syntax-can-anyone-help-fix-it/#findComment-972000 Share on other sites More sharing options...
devang23 Posted December 5, 2009 Author Share Posted December 5, 2009 You had some mistakes with your quotes when defining your $sql variable. Try: $sql = "insert into User Table(first_name,last_name,user_name,password) values('$firstname','$lastname','$username',password('$password'))"; I'd also suggest you don't use the MySQL PASSWORD() function to store your passwords. It has changed in the past and it's a possibility that it will change again, and if it does it would break your application. WOW! your the first person that got it to show up without a syntax....but now, when i put the information in, it doesnt respond with something that says the data was created....how would this info pop up into mysql? Quote Link to comment https://forums.phpfreaks.com/topic/184108-annoying-syntax-can-anyone-help-fix-it/#findComment-972004 Share on other sites More sharing options...
Alex Posted December 5, 2009 Share Posted December 5, 2009 Are you getting your success message? If it's not updating the database try this: $result = mysql_query($sql,$conn) or trigger_error(mysql_error()); Is your table named 'User Table' (It is case-sensitive)? Quote Link to comment https://forums.phpfreaks.com/topic/184108-annoying-syntax-can-anyone-help-fix-it/#findComment-972010 Share on other sites More sharing options...
devang23 Posted December 5, 2009 Author Share Posted December 5, 2009 Are you getting your success message? If it's not updating the database try this: $result = mysql_query($sql,$conn) or trigger_error(mysql_error()); Is your table named 'User Table' (It is case-sensitive)? Yes, it is called "User Table" just like that, the capital U and capital T...im sure im a couple of steps away from making this work. Quote Link to comment https://forums.phpfreaks.com/topic/184108-annoying-syntax-can-anyone-help-fix-it/#findComment-972011 Share on other sites More sharing options...
devang23 Posted December 5, 2009 Author Share Posted December 5, 2009 Are you getting your success message? If it's not updating the database try this: $result = mysql_query($sql,$conn) or trigger_error(mysql_error()); Is your table named 'User Table' (It is case-sensitive)? Yes, it is called "User Table" just like that, the capital U and capital T...im sure im a couple of steps away from making this work. and yes i didnt try the new code you suggested, but same thing, it just reloads the page Quote Link to comment https://forums.phpfreaks.com/topic/184108-annoying-syntax-can-anyone-help-fix-it/#findComment-972013 Share on other sites More sharing options...
PFMaBiSmAd Posted December 5, 2009 Share Posted December 5, 2009 To show all php errors, add the following two lines of code immediately after your first opening <?php tag - ini_set("display_errors", "1"); error_reporting(E_ALL); The normal action of trigger_error() won't show anything on a majority of the php systems in use. Quote Link to comment https://forums.phpfreaks.com/topic/184108-annoying-syntax-can-anyone-help-fix-it/#findComment-972015 Share on other sites More sharing options...
Alex Posted December 5, 2009 Share Posted December 5, 2009 By just reloads the page do you mean that it's still displaying the form? That would mean that it's not even getting to the mysql insert, which could be why it's not working. $username, $password, won't even be set unless register_globals is enabled on your server (which is a bad idea..). Try this: <html><head><title>Adding a User </title></head> <body> <?php if( (!isset($_POST['username'], $_POST['password'], $_POST['lastname'], $_POST['firstname']) ) { $form ="Please enter all new user details"; $form.="<form action=\"$PHP_SELF\""; $form.=" method=\"post\">First Name: "; $form.="<input type=\"text\" name=\firstname\""; $form.=" value=\"$firstname\"><br>Last Name: "; $form.="<input type=\"text\" name=\"lastname\""; $form.=" value=\"$lastname\"><br>UserName: "; $form.="<input type=\"text\" name=\"username\""; $form.=" value=\"$username\"><br>PassWord: "; $form.="<input type=\"text\" name=\"password\""; $form.=" value=\"$password\"><br>"; $form.="<input type=\"submit\" value=\"Submit\">"; $form.="</form>"; echo($form); } else { $conn = mysql_connect("mysql4.000webhost.com")or die("Try Again Punk"); $db = mysql_select_db("a3213677_snorre",$conn)or die("NOOPE"); $sql = "insert into `User Table` (first_name,last_name,user_name,password) values('{$_POST['firstname']}','{$_POST['lastname']}','{$_POST['username']}',password('{$_POST['password']}'))"; $result = mysql_query($sql,$conn)or die ("NOT EVEN"); if($result) { echo("New User $username ADDED DUH!"); } } ?> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/184108-annoying-syntax-can-anyone-help-fix-it/#findComment-972019 Share on other sites More sharing options...
devang23 Posted December 5, 2009 Author Share Posted December 5, 2009 Correct, it just keeps refreshing the form....and when i put the code you just sent there was a syntax error on line 5, and i still didnt catch it. could it be because it cant find the mysql server? if so i dont understand why it wont, all the info i have is right Quote Link to comment https://forums.phpfreaks.com/topic/184108-annoying-syntax-can-anyone-help-fix-it/#findComment-972025 Share on other sites More sharing options...
mrMarcus Posted December 5, 2009 Share Posted December 5, 2009 all the info i have is rightthat's what everybody says, until they come back 5 minutes later saying, "OMGZ, my bad. my password wuz wrong. works now!" check, and triple check. Quote Link to comment https://forums.phpfreaks.com/topic/184108-annoying-syntax-can-anyone-help-fix-it/#findComment-972033 Share on other sites More sharing options...
mrMarcus Posted December 5, 2009 Share Posted December 5, 2009 and keep i mind that Table is a reserved SQL word. must use `User Table` delimiters like in AlexWD's post. MySQL Reserved Words Quote Link to comment https://forums.phpfreaks.com/topic/184108-annoying-syntax-can-anyone-help-fix-it/#findComment-972037 Share on other sites More sharing options...
Alex Posted December 5, 2009 Share Posted December 5, 2009 Sorry, I left an extra ( when I edited your code. <html><head><title>Adding a User </title></head> <body> <?php if( !isset($_POST['username'], $_POST['password'], $_POST['lastname'], $_POST['firstname']) ) { $form ="Please enter all new user details"; $form.="<form action=\"$PHP_SELF\""; $form.=" method=\"post\">First Name: "; $form.="<input type=\"text\" name=\firstname\""; $form.=" value=\"$firstname\"><br>Last Name: "; $form.="<input type=\"text\" name=\"lastname\""; $form.=" value=\"$lastname\"><br>UserName: "; $form.="<input type=\"text\" name=\"username\""; $form.=" value=\"$username\"><br>PassWord: "; $form.="<input type=\"text\" name=\"password\""; $form.=" value=\"$password\"><br>"; $form.="<input type=\"submit\" value=\"Submit\">"; $form.="</form>"; echo($form); } else { $conn = mysql_connect("mysql4.000webhost.com")or die("Try Again Punk"); $db = mysql_select_db("a3213677_snorre",$conn)or die("NOOPE"); $sql = "insert into `User Table` (first_name,last_name,user_name,password) values('{$_POST['firstname']}','{$_POST['lastname']}','{$_POST['username']}',password('{$_POST['password']}'))"; $result = mysql_query($sql,$conn)or die ("NOT EVEN"); if($result) { echo("New User $username ADDED DUH!"); } } ?> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/184108-annoying-syntax-can-anyone-help-fix-it/#findComment-972046 Share on other sites More sharing options...
Alex Posted December 5, 2009 Share Posted December 5, 2009 Taking another look over your code, I noticed some other errors. So I decided to rewrite it (somewhat) for you and explain it a little better. Hopefully this will teach you something for future use. <html><head><title>Adding a User </title></head> <body> <?php if(!isset($_POST['submit'])) { echo <<<FORM Please enter all new user details <form action="" method="post"> First Name: <input type="text" name="firstname"><br> Last Name: <input type="text" name="lastname"><br> UserName: <input type="text" name="username"><br> PassWord: <input type="text" name="password"><br> <input type="submit" name="submit" value="Submit"> </form> FORM; } else { $conn = mysql_connect("mysql4.000webhost.com")or die("Try Again Punk"); $db = mysql_select_db("a3213677_snorre",$conn)or die("NOOPE"); $sql = "insert into `User Table` (first_name,last_name,user_name,password) values('{$_POST['firstname']}','{$_POST['lastname']}','{$_POST['username']}',password('{$_POST['password']}'))"; $result = mysql_query($sql,$conn) or trigger_error(mysql_error()); if($result) { echo("New User $username ADDED DUH!"); } } ?> </body></html> It's much easier to write a block of html using the heredoc syntax. You had a problem with a missing " which is why it wasn't working before. You most likely missed this because it's hard to see when you're escaping tons of quotes. This way you can write the form like you normally would in any html document. I also removed all the value="..."s because assuming this works you'll never be submitting data in a way that it'll be redisplayed on the form (Unless you add validation, which you don't currently have, but I'd suggest). I also removed the $PHP_SELF, because using this leaves you open to XSS attacks. It's a better idea to just leave the action attribute empty, or just type in the name of the file (if you want it to validate) if you want to submit a form back to the same page. Finally I gave the submit button a name of 'submit', this way you can just use if(!isset($_POST['submit'])) { ... } to see if the form was submitted. ( isset ). Hopefully this helps. ( And for future reference it's a better idea to keep this inside of the help topic, and not over pms ). Quote Link to comment https://forums.phpfreaks.com/topic/184108-annoying-syntax-can-anyone-help-fix-it/#findComment-972109 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.