Forum Moderators: coopster
The alumInfo table is set up like this:
Create Table alumInfo (
userId int (11) NOT NULL,
pic_url varchar (50) default NULL,
living text,
spouse text,
kids text,
etc...
PRIMARY KEY (userId));
The error I get is: "Column count doesn't match value count at row 1"
I'm not sure if the problem is in using the $_SESSION['userId'] or in the query.
Here's what the code the form POST's to looks like:
session_start();
include 'db.php';
// Define post fields into simple variables
$_SESSION['userId'] = $userId;
$pic_url = $_POST['pic_url'];
$living = $_POST['living'];
$spouse = $_POST['spouse'];
$kids = $_POST['kids'];
$job = $_POST['job'];
$life = $_POST['life'];
$bestMHS = $_POST['bestMHS'];
$worstMHS = $_POST['worstMHS'];
$embarrassMHS = $_POST['embarrassMHS'];
$message = $_POST['message'];
$sql = mysql_query("INSERT INTO alumInfo (userId, pic_url, living, spouse,
kids, job, life, bestMHS, worstMHS, embarrassMHS, message)
VALUES('$userId, $pic_url', '$living', '$spouse', '$kids', '$job', '$life','$bestMHS', '$worstMHS', '$embarrassMHS', '$message')")
or die (mysql_error());
Any ideas?
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' '', 'Somewhere nice', 'Yes, Renee, 12', 'Lillian 5, Finn 2', '', 'I am cool','y' at line 3
Not sure why the blank '', and what line 3 they mean...
I've changed a bit so here's a reprint of the stuff above only changed:
session_start();
include 'db.php';
// Define post fields into simple variables
$userId = $_SESSION['userId'];
$pic_url = $_POST['pic_url'];
$living = $_POST['living'];
$spouse = $_POST['spouse'];
$kids = $_POST['kids'];
$job = $_POST['job'];
$life = $_POST['life'];
$bestMHS = $_POST['bestMHS'];
$worstMHS = $_POST['worstMHS'];
$embarrassMHS = $_POST['embarrassMHS'];
$message = $_POST['message'];
$sql = mysql_query("INSERT INTO alumInfo (userId, pic_url, living, spouse,
kids, job, life, bestMHS, worstMHS, embarrassMHS, message)
VALUES($userId, '$pic_url', '$living', '$spouse', '$kids', '$job', '$life','$bestMHS', '$worstMHS', '$embarrassMHS', '$message')")
or die (mysql_error());
if(!$sql){
echo 'There has been an error entering your Alumni Information. Please try again.';
} else {
$sql = mysql_query
("UPDATE users SET alumInfo='1' WHERE username='".$_SESSION['username']."' AND password='".$_SESSION['password']."'");
}
Now I am getting this error:
Duplicate entry '1' for key 1
Is that the MySQL key? Is that wrong that I used 'userId' as the PRIMARY KEY for both tables?