Jump to content

[SOLVED] INSERT INTO not working ?


d239113g

Recommended Posts

 

Hi, i am building up my site, and i am testing getting data from a form and inserting it into the database, but i am keep getting an error

Could not insert new record for INSERT INTO Customers (Surname, Firstname, Add, City, PostCode, email, Tel_No, Username, Password) VALUES ('bloggs','Joe','22 Somewhere Street','Anywhere','ZZZ 666Z','joebloggs@aol.com','01910000000','joebloggs08','blogger') . Please try again

 

can anybody see anything in my sql that is wrong? I have checked and double checked that column names in the database match my sql, and the form names match the $_POST['surname'] ect.

 

<?php 
$hostname = "localhost";
$user = "xxxxxxxx";
$pass = "xxxxxxxx";
$database = "xxxxxxxx";
   
   if (!($link = mysql_connect("$hostname", "$user", "$pass"))) 
   						  die ("Could not connect MySQL");
   
   if (!mysql_select_db($database)) die ("could not open database");
   
   $surname=$_POST['surname'];
   $firstname=$_POST['firstname'];
   $address=$_POST['add'];
   $city=$_POST['city'];
   $postcode=$_POST['postcode'];
   $Email=$_POST['Email'];
   $tele=$_POST['tel'];
   $username=$_POST['username'];
   $password=$_POST['password'];
   $submit=$_POST['submit'];
   
  
   if($submit)
   {
   	$msg="";		

   	$sqlString="SELECT * FROM Customers where username ='$username'";
   	$result=mysql_query($sqlString)or die("Could not retrieve $sqlString ");

   	if($myrow=mysql_fetch_row($result)) 
   	{
  			 $msg="Sorry, this user name is already in use. Please try again";
   	}
   		else
   		{
$sqlString = "INSERT INTO Customers (Surname, Firstname, Add, City, PostCode, email, Tel_No, Username, Password) 
VALUES ('$surname','$firstname','$address','$city','$postcode','$Email','$tele','$username','$password')";

$result=mysql_query($sqlString)or die("Could not insert new record for 
 											$sqlString . Please try again ");
   		$msg="  $user;     Your registration was successful";
   		} 
  } 
  
   
   
   $msgbody = "Dear $firstname, \n\n";
   $msgbody .= "Thank you for registering with FamilyHols.co.uk."; 
   $msgbody	.= "You have been successful in your application.";
   $msgbody .= " \n";
   $msgbody .= "The username you requested was: $username\n";
   $msgbody .= "Your password is: $password \n"; 
   $msgbody .= " \n";
   $msgbody .= "Please use the details above to login into FamilyHols.co.uk in order for you to purchase holidays. \n\n";
   mail("$Email", "Your login details!", "$msgbody") 
   
?>

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.