We help IT Professionals succeed at work.
Get Started

PHP / MySQL insert

patrickm12981
on
368 Views
Last Modified: 2012-05-11
I'm getting this error when I hit submit and can't find the error.

"Column count doesn't match value count at row 1"

Thank you for the help
ResultsAdmin.php
--------------------------------------------------------------------------------------------------
<?php

// Inialize session
session_start();

// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username'])) {
header('Location: index.php');
}

?>

<?php

error_reporting(E_ALL);
include("../includes/Header.html");
include("../includes/conn.php"); 
?>
<center><p><a href="Admin.php">Back To Admin Index</a></p></center>
<center><p><a href="logout.php">Logout</a></p></center>
<table width="930" align="center">
<tr>
<td valign="top">

<center><h2><u>Submit Race Results</u></h2></center>

<form action="insertresults.php" method="post">
<?php
if($updated===TRUE)
	{echo '<div>Results Updated</div>';
	}
?>
<table border="1" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<th>
			Race Date:
		</th>
		
		<td colspan="2">
			<?php
			$query2="SELECT Race_Number, Date FROM Schedule ORDER BY Date";
			$result3 = mysql_query($query2) or die("Error executing:<br>$query2<br>" . mysql_error() );

			echo "<select name=\"Race_Number\">";
			echo "<option></option>";
			while ($row=mysql_fetch_assoc($result3)) {
			echo "<option value=\"{$row['Race_Number']}\">{$row['Date']}</option>";
			}
			echo "</select>";
			?>
		</td>	
	</tr>
	
	<tr>
		<th>
			Event:
		</th>
		
		<td colspan="2">
			<?php
			$query3="SELECT Event FROM Events";
			$result4 = mysql_query($query3) or die("Error executing:<br>$query3<br>" . mysql_error() );

			echo "<select name=\"Event\">";
			echo "<option></option>";
			while ($row=mysql_fetch_assoc($result4)) {
			echo "<option>".$row['Event']."</option>";
			}
			echo "</select>";
			?>
		</td>
	</tr>
        
            <tr><td>1</td><td><input type="text" name="1" /></td></tr>
            <tr><td>2</td><td><input type="text" name="2" /></td></tr>
            <tr><td>3</td><td><input type="text" name="3" /></td></tr>
            <tr><td>4</td><td><input type="text" name="4" /></td></tr>
            <tr><td>5</td><td><input type="text" name="5" /></td></tr>
            <tr><td>6</td><td><input type="text" name="6" /></td></tr>
            <tr><td>7</td><td><input type="text" name="7" /></td></tr>
            <tr><td>8</td><td><input type="text" name="8" /></td></tr>
            <tr><td>9</td><td><input type="text" name="9" /></td></tr>
            <tr><td>10</td><td><input type="text" name="10" /></td></tr>
            <tr><td>11</td><td><input type="text" name="11" /></td></tr>
            <tr><td>12</td><td><input type="text" name="12" /></td></tr>
            <tr><td>13</td><td><input type="text" name="13" /></td></tr>
            <tr><td>14</td><td><input type="text" name="14" /></td></tr>
            <tr><td>15</td><td><input type="text" name="15" /></td></tr>
            <tr><td>16</td><td><input type="text" name="16" /></td></tr>
            <tr><td>17</td><td><input type="text" name="17" /></td></tr>
            <tr><td>18</td><td><input type="text" name="18" /></td></tr>
            <tr><td>19</td><td><input type="text" name="19" /></td></tr>
            <tr><td>20</td><td><input type="text" name="20" /></td></tr>
            <tr><td>21</td><td><input type="text" name="21" /></td></tr>
            <tr><td>22</td><td><input type="text" name="22" /></td></tr>
            <tr><td>23</td><td><input type="text" name="23" /></td></tr>
            <tr><td>24</td><td><input type="text" name="24" /></td></tr>
            <tr><td>25</td><td><input type="text" name="25" /></td></tr>
            <tr><td>26</td><td><input type="text" name="26" /></td></tr>
            <tr><td>27</td><td><input type="text" name="27" /></td></tr>
            <tr><td>28</td><td><input type="text" name="28" /></td></tr>
            <tr><td>29</td><td><input type="text" name="29" /></td></tr>
            <tr> <td>30</td><td><input type="text" name="30" /></td></tr>
            <tr><td>DNF1</td><td><input type="text" name="DNF1" /></td></tr>
            <tr><td>DNF2</td><td><input type="text" name="DNF2" /></td></tr>
            <tr><td>DNF3</td><td><input type="text" name="DNF3" /></td></tr>
            <tr><td>DNF4</td><td><input type="text" name="DNF4" /></td></tr>
            <tr><td>DNF5</td><td><input type="text" name="DNF5" /></td></tr>
            <tr><td>DNF6</td><td><input type="text" name="DNF6" /></td></tr>
            <tr><td>DNF7</td><td><input type="text" name="DNF7" /></td></tr>
            <tr><td>DNF8</td><td><input type="text" name="DNF8" /></td></tr>
            <tr><td>DNF9</td><td><input type="text" name="DNF9" /></td></tr>
            <tr><td>DNF10</td><td><input type="text" name="DNF10" /></td></tr>
            <tr><td>DNS1</td><td><input type="text" name="DNS1" /></td></tr>
            <tr><td>DNS2</td><td><input type="text" name="DNS2" /></td></tr>
            <tr><td>DNS3</td><td><input type="text" name="DNS3" /></td></tr>
            <tr><td>DNS4</td><td><input type="text" name="DNS4" /></td></tr>
            <tr><td>DNS5</td><td><input type="text" name="DNS5" /></td></tr>
            <tr><td>NT1</td><td><input type="text" name="NT1" /></td></tr>
            <tr><td>NT2</td><td><input type="text" name="NT2" /></td></tr>
            <tr><td>NT3</td><td><input type="text" name="NT3" /></td></tr>
            <tr><td>NT4</td><td><input type="text" name="NT4" /></td></tr>
            <tr><td>NT5</td><td><input type="text" name="NT5" /></td></tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="submit" value="Submit Results" /></td>
</tr>
</table>
</form>
</td>
<td valign="top">
<center><h2><u>Edit Race Results</u></h2></center>

<form action="updateresults.php" method="post">

<table border="1" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<th>
			Race Date:
		</th>

		<td colspan="2">
			<?php
			$query2="SELECT Race_Number, Date FROM Schedule ORDER BY Date";
			$result3 = mysql_query($query2) or die("Error executing:<br>$query2<br>" . mysql_error() );

			echo "<select name=\"Race_Number\">";
			echo "<option></option>";
			while ($row=mysql_fetch_assoc($result3)) {
			echo "<option value=\"{$row['Race_Number']}\">{$row['Date']}</option>";
			}
			echo "</select>";
			?>
		</td>
	</tr>

	<tr>
		<th>
			Event:
		</th>

		<td colspan="2">
			<?php
			$query3="SELECT Event FROM Events";
			$result4 = mysql_query($query3) or die("Error executing:<br>$query3<br>" . mysql_error() );

			echo "<select name=\"Event\">";
			echo "<option></option>";
			while ($row=mysql_fetch_assoc($result4)) {
			echo "<option>".$row['Event']."</option>";
			}
			echo "</select>";
			?>
		</td>
	</tr>

            <tr><td>1</td><td><input type="text" name="1" /></td></tr>
            <tr><td>2</td><td><input type="text" name="2" /></td></tr>
            <tr><td>3</td><td><input type="text" name="3" /></td></tr>
            <tr><td>4</td><td><input type="text" name="4" /></td></tr>
            <tr><td>5</td><td><input type="text" name="5" /></td></tr>
            <tr><td>6</td><td><input type="text" name="6" /></td></tr>
            <tr><td>7</td><td><input type="text" name="7" /></td></tr>
            <tr><td>8</td><td><input type="text" name="8" /></td></tr>
            <tr><td>9</td><td><input type="text" name="9" /></td></tr>
            <tr><td>10</td><td><input type="text" name="10" /></td></tr>
            <tr><td>11</td><td><input type="text" name="11" /></td></tr>
            <tr><td>12</td><td><input type="text" name="12" /></td></tr>
            <tr><td>13</td><td><input type="text" name="13" /></td></tr>
            <tr><td>14</td><td><input type="text" name="14" /></td></tr>
            <tr><td>15</td><td><input type="text" name="15" /></td></tr>
            <tr><td>16</td><td><input type="text" name="16" /></td></tr>
            <tr><td>17</td><td><input type="text" name="17" /></td></tr>
            <tr><td>18</td><td><input type="text" name="18" /></td></tr>
            <tr><td>19</td><td><input type="text" name="19" /></td></tr>
            <tr><td>20</td><td><input type="text" name="20" /></td></tr>
            <tr><td>21</td><td><input type="text" name="21" /></td></tr>
            <tr><td>22</td><td><input type="text" name="22" /></td></tr>
            <tr><td>23</td><td><input type="text" name="23" /></td></tr>
            <tr><td>24</td><td><input type="text" name="24" /></td></tr>
            <tr><td>25</td><td><input type="text" name="25" /></td></tr>
            <tr><td>26</td><td><input type="text" name="26" /></td></tr>
            <tr><td>27</td><td><input type="text" name="27" /></td></tr>
            <tr><td>28</td><td><input type="text" name="28" /></td></tr>
            <tr><td>29</td><td><input type="text" name="29" /></td></tr>
            <tr> <td>30</td><td><input type="text" name="30" /></td></tr>
            <tr><td>DNF1</td><td><input type="text" name="DNF1" /></td></tr>
            <tr><td>DNF2</td><td><input type="text" name="DNF2" /></td></tr>
            <tr><td>DNF3</td><td><input type="text" name="DNF3" /></td></tr>
            <tr><td>DNF4</td><td><input type="text" name="DNF4" /></td></tr>
            <tr><td>DNF5</td><td><input type="text" name="DNF5" /></td></tr>
            <tr><td>DNF6</td><td><input type="text" name="DNF6" /></td></tr>
            <tr><td>DNF7</td><td><input type="text" name="DNF7" /></td></tr>
            <tr><td>DNF8</td><td><input type="text" name="DNF8" /></td></tr>
            <tr><td>DNF9</td><td><input type="text" name="DNF9" /></td></tr>
            <tr><td>DNF10</td><td><input type="text" name="DNF10" /></td></tr>
            <tr><td>DNS1</td><td><input type="text" name="DNS1" /></td></tr>
            <tr><td>DNS2</td><td><input type="text" name="DNS2" /></td></tr>
            <tr><td>DNS3</td><td><input type="text" name="DNS3" /></td></tr>
            <tr><td>DNS4</td><td><input type="text" name="DNS4" /></td></tr>
            <tr><td>DNS5</td><td><input type="text" name="DNS5" /></td></tr>
            <tr><td>NT1</td><td><input type="text" name="NT1" /></td></tr>
            <tr><td>NT2</td><td><input type="text" name="NT2" /></td></tr>
            <tr><td>NT3</td><td><input type="text" name="NT3" /></td></tr>
            <tr><td>NT4</td><td><input type="text" name="NT4" /></td></tr>
            <tr><td>NT5</td><td><input type="text" name="NT5" /></td></tr>

<tr>
<td colspan="3" align="center"><input type="submit" name="submit" value="Edit Results" /></td>
</tr>
</table>
</form>
</td>
</tr>

---------------------------------------------------------------------------------------------------
InsertResults.php
---------------------------------------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>InsertResults.php</title>
</head>
<body>

<?php
mysql_connect("mysql", "********", "********") or die ('Could not connect: ' . mysql_error());
mysql_select_db("RMDCRA");
    
$Race_Number = $_POST['Race_Number'];
$Event = $_POST['Event'];
$one=$_POST['1'];
$two=$_POST['2'];
$three=$_POST['3'];
$four=$_POST['4'];
$five=$_POST['5'];
$six=$_POST['6'];
$seven=$_POST['7'];
$eight=$_POST['8'];
$nine=$_POST['9'];
$ten=$_POST['10'];
$eleven=$_POST['11'];
$twelve=$_POST['12'];
$thirteen=$_POST['13'];
$fourteen=$_POST['14'];
$fifteen=$_POST['15'];
$sixteen=$_POST['16'];
$seventeen=$_POST['17'];
$eighteen=$_POST['18'];
$nineteen=$_POST['19'];
$twenty=$_POST['20'];
$twentyone=$_POST['21'];
$twentytwo=$_POST['22'];
$twentythree=$_POST['23'];
$twentyfour=$_POST['24'];
$twentyfive=$_POST['25'];
$twentysix=$_POST['26'];
$twentyseven=$_POST['27'];
$twentyeight=$_POST['28'];
$twentynine=$_POST['29'];
$thirty=$_POST['30'];
$DNF1=$_POST['DNF1'];
$DNF2=$_POST['DNF2'];
$DNF3=$_POST['DNF3'];
$DNF4=$_POST['DNF4'];
$DNF5=$_POST['DNF5'];
$DNF6=$_POST['DNF6'];
$DNF7=$_POST['DNF7'];
$DNF8=$_POST['DNF8'];
$DNF9=$_POST['DNF9'];
$DNF10=$_POST['DNF10'];
$DNS1=$_POST['DNS1'];
$DNS2=$_POST['DNS2'];
$DNS3=$_POST['DNS3'];
$DNS4=$_POST['DNS4'];
$DNS5=$_POST['DNS5'];
$NT1=$_POST['NT1'];
$NT2=$_POST['NT2'];
$NT3=$_POST['NT3'];
$NT4=$_POST['NT4'];
$NT5=$_POST['NT5'];


$sql = mysql_query("INSERT INTO Race_Results (`Race_Number`, `Event`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `13`, `14`, `15`, `16`, `17`, `18`, `19`, `20`, `21`, `22`, `23`, `24`, `25`, `26`, `27`, `28`, `29`, `30`, `DNF1`, `DNF2`, `DNF3`, `DNF4`, `DNF5`, `DNF6`, `DNF7`, `DNF8`, `DNF9`, `DNF10`, `DNS1`, `DNS2`, `DNS3`, `DNS4`, `DNS5`)
    VALUES ('$Race_Number', '$Event', '$one', '$two', '$three', '$four', '$five', '$six', '$seven','$eight','$nine','$ten','$eleven','$twelve','$thirteen','$fourteen','$fifteen','$sixteen', '$seventeen','$eighteen','$nineteen','$twenty','$twentyone','$twentytwo','$twentythree','$twentyfour','$twentyfive','$twentysix','$twentyseven','$twentyeight','$twentynine','$thirty','$DNF1','$DNF2','$DNF3','$DNF4','$DNF5','$DNF6','$DNF7','$DNF8','$DNF9','$DNF10','$DNS1','$DNS2','$DNS3','$DNS4','$DNS5','$NT1','$NT2','$NT3','$NT4','$NT5')") or die(mysql_error());
header('Location: http://rmdcra.org/admin/Admin.php');  
?>
</body>
</html>

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE