Jump to content

Problem with inserting data


Go to solution Solved by babymac,

Recommended Posts

I'm just learning and am trying to insert data into a table via myphpadmin.  I have MAMP running and servers are on.  

 

Simple Input Form, then php script follows. I'm getting an error: Column count doesn't match value count at row 1.  I've counted my variables over and over and they seem to match to me but this is my first time every doing this so perhaps I'm missing it.  Also, I put x's through the sensitive login info and am interested what others do here.  Again, this is just a simple assignment that I'm doing on localhost but am looking to the future also.  Any thoughts?

Thanks!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://wwww.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

	<title> Database Input Form
	</title>
</head>

<body>
	<p><h3>Please enter the following information:</h3></p>	
		
	<form action="pa4.php" method="post">
		
		<p>First Name: <input type="text" name="fname" size="20" />
		</p>
		<p>Last Name: <input type="text" name="lname" size="20" />
		</p>
		<p>Address: <input type="text" name="address" size="60" />
		</p>
		<p>Phone: <input type="text" name="phone" size="13" />
		</p>
		<p>Email: <input type="text" name="email" size="50" />
		</p>
		<p>Birthdate: <input type="text" name="bday" size="10" />
		</p>
		
		<input type="submit" name="submit" value="Submit" />
		
	</form>
</body>

</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML  1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;  charset=utf-8"/>
<title>Creating Directory</title>
</head>
<body>

<?php

//Label variables
$dbhost = "localhost";
$dbuser = "xxxxxx";
$dbpword = "xxxxxx";
$dbname = "xxxxxx";
$dbtable = "Address_Book";
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$bday = $_POST['bday'];



//Initiate connection
$con=mysqli_connect($dbhost, $dbuser, $dbpword, $dbname);

// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql = "INSERT INTO $dbtable (First_Name, Last_Name, Adress, Phone, Email, Birthdate)
VALUES
('$fname', '$lname', '$address' '$phone', '$email', '$bday')";

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
echo "1 record added";

mysqli_close($con);
?>
Link to comment
https://forums.phpfreaks.com/topic/278357-problem-with-inserting-data/
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.