galvin Posted January 9, 2009 Share Posted January 9, 2009 I don't know if anyone can answer this without seeing the entire code, but I'll take a chance. This code below keeps producing the message "The picks were NOT submitted. Column count doesn't match value count at row 1" But I clearly am inserting FOUR values ('1', '{$_POST['pick1']}', '{$_SESSION['userid']}', '{$_POST['week']}' ) into the FOUR specified fields (pick#, teamid, userid, week). I did the echos as testing and each time, all three ARE showing a value. So that makes me think something must be wrong with my "pick#" value, but that is simply the number 1 (the first entry in the $insertsArr[]). Is something wrong my syntax? or maybe am I using quotes wrong? Any help would be appreciated... if (isset($_POST['submit']) && $_POST['submit'] == "Submit Pick #1" ) { //print_r($HTTP_POST_VARS); $atLeastOnePick = ''; $insertsArr = array(); if($_POST['pick1'] && $_POST['week']){ $atLeastOnePick = 1; $insertsArr[] = "('1', '{$_POST['pick1']}', '{$_SESSION['userid']}', '{$_POST['week']}' )"; } if($atLeastOnePick){ $query = "INSERT INTO picks2009 ( pick#, teamid, userid, week ) VALUES " . implode(', ', $insertsArr) ; $result = mysql_query($query, $connection); if ($result) { $message = "<p class=\"success\" >The picks were successfully submitted. </p>"; $pick1editmode="yes"; } else { $message = "The picks were NOT submitted."; $message .= "<br />" . mysql_error(); echo "teamid=" . $_POST['pick1']; echo "userid=" . $_SESSION['userid']; echo "week" . $_POST['week']; } } else { $badsubmit = '<p class="error">Error: Please be sure the WEEK NUMBER is selected (and at least one pick is made)!'; } Link to comment https://forums.phpfreaks.com/topic/140101-solved-shot-in-the-dark/ Share on other sites More sharing options...
kenrbnsn Posted January 9, 2009 Share Posted January 9, 2009 Try surrounding "pick#" with backticks: <?php $query = "INSERT INTO picks2009 (`pick#`, teamid, userid, week) VALUES " . implode(', ', $insertsArr) ; ?> Ken Link to comment https://forums.phpfreaks.com/topic/140101-solved-shot-in-the-dark/#findComment-733016 Share on other sites More sharing options...
galvin Posted January 9, 2009 Author Share Posted January 9, 2009 That did it, you're the man Ken! Just curious, do you know why those backticks are needed for that one but not the other three? Link to comment https://forums.phpfreaks.com/topic/140101-solved-shot-in-the-dark/#findComment-733021 Share on other sites More sharing options...
kenrbnsn Posted January 9, 2009 Share Posted January 9, 2009 The "#" character is not a normal character for a field name. The backtick tells MySQL to treat it as a regular character. Ken Link to comment https://forums.phpfreaks.com/topic/140101-solved-shot-in-the-dark/#findComment-733026 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.