Derleek Posted May 7, 2008 Share Posted May 7, 2008 i'm completely stumped... granted i'm not all that experienced with php/mySQL but i can't figure out what exactly is wrong with my code here. i'm sure there is a bunch though. the object of this program is to take user input/varify it. then if it is valid store it into a database (moto) under the table fans... the table doesn't seem to be created correctly (obviously an issue with my code) so here it is... sorry if its sloppy... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>Sign Up!</title> </head> <body> <p> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <label for="name">Name: </label> <input id="name" type="text" name="realName" maxlength="25" /><br /> <label for="name">Screen Name: </label> <input id="name" type="text" name="screenName" maxlength="25" /><br /> <label for="name">Password: </label> <input id="name" type="password" name="password" maxlength="25" /><br /> <label for="name">Confirm Password: </label> <input id="name" type="password" name="cPassword" maxlength="25" /><br /> <input id="submit" type="submit" value="Sign UP!" /><br /> </p> <?php function sanityCheck($string, $type, $length){ // assign the type $type = 'is_'.$type; if(!$type($string)) { return FALSE; } // to check if there is anything in the string elseif(empty($string)) { return FALSE; } // to check how long the string is elseif(strlen($string) > $length) { return FALSE; } else { // if all is well, we return TRUE return TRUE; } } function checkSet(){ return isset($_POST['realName'], $_POST['screenName'], $_POST['password'], $_POST['cPassword']); } if(checkSet() != FALSE) { if(empty($_POST['realName'])==FALSE && sanityCheck($_POST['realName'], 'string', 25)!=FALSE && empty($_POST['screenName'])==FALSE && sanityCheck($_POST['screenName'], 'string', 25)!=FALSE && empty($_POST['password'])==FALSE && sanityCheck($_POST['password'], 'string', 25)!=FALSE) { //If all is well the value of the POST is assigned to a variable... $realName = $_POST['realName']; $screenName = $_POST['screenName']; $password = $_POST['password']; $cPassword = $_POST['cPassword']; if($password !=$cPassword) { echo 'your passwords don not match'; exit(); } $link = @mysql_connect('localhost', 'root', 'zOinks12'); if (!$link) { die('Not connected : ' . mysql_error()); } $db_selected = mysql_select_db('moto', $link); if (!$db_selected) { die ("Database not selected : " . mysql_error()); } $input = "CREATE TABLE fans ( realName VARCHAR( 25 ) NOT NULL , screenName VARCHAR( 100 ) NOT NULL , password VARCHAR( 25 ) NOT NULL , )"; mysql_query($input,$link); // Query $uInput = sprintf("INSERT INTO fans (realName,screenName,password) VALUES( '%s', '%s','%s')", mysql_real_escape_string($realName), mysql_real_escape_string($screenName), mysql_real_escape_string($password)); // run the query if(!mysql_query($uInput)) { echo 'Query failed '.mysql_error(); exit(); } else { echo "welcome to Pro Moto Fan bench racing!!!"; } } else { echo 'You did not fill out all of the fields!!'; exit(); } } else { echo "Please fill out all of the above!"; } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
fenway Posted May 7, 2008 Share Posted May 7, 2008 That's not helpful. What sql statement doesn't work? Quote Link to comment Share on other sites More sharing options...
Derleek Posted May 7, 2008 Author Share Posted May 7, 2008 the error that is spat out is... "Query failed Table 'moto.fans' doesn't exist" Quote Link to comment Share on other sites More sharing options...
fenway Posted May 8, 2008 Share Posted May 8, 2008 the error that is spat out is... "Query failed Table 'moto.fans' doesn't exist" That's a good start... which query? And please echo the plaintext sql statement, NOT php code. Quote Link to comment Share on other sites More sharing options...
Derleek Posted May 15, 2008 Author Share Posted May 15, 2008 sorry, new to this php/mySQL stuff... here is the query $uInput = sprintf("INSERT INTO fans (realName,screenName,password) VALUES( '%s', '%s','%s')", mysql_real_escape_string($realName), mysql_real_escape_string($screenName), mysql_real_escape_string($password)); // run the query if(!mysql_query($uInput)) { echo 'Query failed '.mysql_error(); exit(); } else { echo "welcome to Pro Moto Fan bench racing!!!"; } } i believe this is what you're looking for? Quote Link to comment Share on other sites More sharing options...
Derleek Posted May 15, 2008 Author Share Posted May 15, 2008 well, i checked out phpMyAdmin and the it appears that the table isn't even being created... here is that code that is right before the previously posted query code. $input = "CREATE TABLE fans ( realName VARCHAR( 25 ) NOT NULL , uID bigint(20) NOT NULL AUTO_INCREMENT, screenName VARCHAR( 25 ) NOT NULL , password VARCHAR( 25 ) NOT NULL , PRIMARY KEY (`uID`), )"; mysql_query($input,$link); this code does not appear to be working... Quote Link to comment Share on other sites More sharing options...
Derleek Posted May 15, 2008 Author Share Posted May 15, 2008 solved... syntax error i hate myself... hahah how come i can't modify my old posts to say this issue was solved? Quote Link to comment Share on other sites More sharing options...
fenway Posted May 15, 2008 Share Posted May 15, 2008 Just clicked the "TOPIC SOLVED" button on the bottom-right of the button set on the bottom of the page (near the quick reply area). We specifically don't want old posts changed. 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.