babymac Posted May 24, 2013 Share Posted May 24, 2013 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/278357-problem-with-inserting-data/ Share on other sites More sharing options...
Solution babymac Posted May 24, 2013 Author Solution Share Posted May 24, 2013 Wow - it wasn't until I saw the code in the format here that I saw the missing comma plain as day. Fixed - nevermind! I don't know how to delete a post or I would. Quote Link to comment https://forums.phpfreaks.com/topic/278357-problem-with-inserting-data/#findComment-1432107 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.