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','[email protected]','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
https://forums.phpfreaks.com/topic/102943-solved-insert-into-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.