Ex-Bull Posted March 5, 2008 Share Posted March 5, 2008 I am trying to make a registering page in my site from a form, the form is perfect but the problem is i am getting an error with processing the form with PHP. Here's my PHP code for inserting the record in the database: /*Data base connection*/ $User="SomeName"; $MyPassword="passwords213"; $connection= mysql_connect("localhost",$User,$MyPassword); /* insering a new record */ $DBName="TheDBName"; mysql_select_db($DBName, $connection); /*Information from registration form*/ $email= $_POST["Email"]; $DesUsername = $_POST["UserName"]; $Password= $_POST["Password"]; $CPassword= $_POST["CPassword"]; $FName= $_POST["FName"]; $SName= $_POST["SName"]; $Country= $_POST["Country"]; $Gender= $_POST["sex"]; /*getting the date*/ $Year= $_POST["Year"]; $Month= $_POST["Month"]; $Day= $_POST["Day"]; $sql = 'INSERT INTO `DBName`.`TheTable` (`UserName`, `Password`, `Email`, `FirstName`, `LastName`, `Year`, `Month`, `Day`, `Country`, `ID`, `Gender`) VALUES( $DesUsername , $Password , $email , $FName , $SName , $Year , $Month , $Day , $Country , NULL , $Gender);'; if (!mysql_query($sql,$connection)) { die('<h1>Some Error has occured:</h1><br /> ' . mysql_error()); } echo "Congratulations! You have been sucessfully registered to webtutorial! <br /> <h1>Enjoy your stay!</h1>"; mysql_close($connection); ?> after this i get the following error: Unknown column '$DesUsername' in 'field list' you can test the script yourself byclicking this link: http://www.wc.890m.com/ScriptTest Quote Link to comment Share on other sites More sharing options...
deansatch Posted March 5, 2008 Share Posted March 5, 2008 $sql = "INSERT INTO `DBName`.`TheTable` (`UserName`, `Password`, `Email`, `FirstName`, `LastName`, `Year`, `Month`, `Day`, `Country`, `ID`, `Gender`) VALUES( '$DesUsername' , '$Password' , '$email' , '$FName' , '$SName' , '$Year' , '$Month' , '$Day' , '$Country' , , '$Gender')"; Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 5, 2008 Share Posted March 5, 2008 valadate your code please use mysql_real_escape_string($_POST['my_varable']) function on all posting varables.. also set the form name="submit" buttion name as submit... also in php the ' singel quote means show as written,.... example $varable echo's $varable and " " double quotes makes php echo what in the $varable...... your insert was wrong you used ' single quote not " double quote use a database connection that makes sence to all please.... read up on databse connection for php example this connection so much easer to read then yours..... there plenty off wrongs to php do wrights mate.. <?php $db=mysql_connect("localhost","username","password"); mysql_select_db("databse_name",$db); ?> <?php /*Data base connection*/ $User="SomeName"; $MyPassword="passwords213"; $connection= mysql_connect("localhost",$User,$MyPassword); /* insering a new record */ $DBName="TheDBName"; mysql_select_db($DBName, $connection); if (isset($_POST['submit'])){ /*Information from registration form*/ $email= $_POST["Email"]; $DesUsername = $_POST["UserName"]; $Password= $_POST["Password"]; $CPassword= $_POST["CPassword"]; $FName= $_POST["FName"]; $SName= $_POST["SName"]; $Country= $_POST["Country"]; $Gender= $_POST["sex"]; /*getting the date*/ $Year= $_POST["Year"]; $Month= $_POST["Month"]; $Day= $_POST["Day"]; $sql = "INSERT INTO DBName TheTable (UserName, Password, Email, FirstName, LastName, Year, Month, Day, Country, ID, Gender) VALUES( $DesUsername , $Password , $email , $FName , $SName , $Year , $Month , $Day , $Country , NULL , $Gender)"; if (!mysql_query($sql,$connection)) { die('<h1>Some Error has occured:</h1> ' . mysql_error()); } echo "Congratulations! You have been sucessfully registered to webtutorial! <h1>Enjoy your stay!</h1>"; mysql_close($connection); } ?> 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.