Jump to content

I need help badly!! Help me fis the PHP and MySQL bug!


Ex-Bull

Recommended Posts

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

Link to comment
Share on other sites

$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')";

Link to comment
Share on other sites

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);
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.