I am using the same script to input data into my MySQL database with php. For some reason on one of the tables the code repeats the last entry but I cannot figure out why. It works fine for a different table with no repeats. Any help would be greatly appreciated
HTML
Code: Select all
<form action="db-collections-script.php" method="post">
<div id="header">
<img src="admin_img/header.png" />
</div><!-- end header -->
<div id="container">
<legend>Collections - Designers and the categories found on retailers sites</legend>
<ul id="list">
<li>Company Name: <input type="text" name="co_name[]" /></li>
<li>Link: <input type="text" name="link[]" /></li>
<li>Collection Name: <input type="text" name="text[]" /></li><br /><br />
<li>Company Name: <input type="text" name="co_name[]" /></li>
<li>Link: <input type="text" name="link[]" /></li>
<li>Collection Name: <input type="text" name="text[]" /></li><br /><br />
<li>Company Name: <input type="text" name="co_name[]" /></li>
<li>Link: <input type="text" name="link[]" /></li>
<li>Collection Name: <input type="text" name="text[]" /></li><br /><br />
<li>Company Name: <input type="text" name="co_name[]" /></li>
<li>Link: <input type="text" name="link[]" /></li>
<li>Collection Name: <input type="text" name="text[]" /></li><br /><br />
<li>Company Name: <input type="text" name="co_name[]" /></li>
<li>Link: <input type="text" name="link[]" /></li>
<li>Collection Name: <input type="text" name="text[]" /></li><br /><br />
<li>Company Name: <input type="text" name="co_name[]" /></li>
<li>Link: <input type="text" name="link[]" /></li>
<li>Collection Name: <input type="text" name="text[]" /></li><br /><br />
<li>Company Name: <input type="text" name="co_name[]" /></li>
<li>Link: <input type="text" name="link[]" /></li>
<li>Collection Name: <input type="text" name="text[]" /></li><br /><br />
<li>Company Name: <input type="text" name="co_name[]" /></li>
<li>Link: <input type="text" name="link[]" /></li>
<li>Collection Name: <input type="text" name="text[]" /></li><br /><br />
<li>Company Name: <input type="text" name="co_name[]" /></li>
<li>Link: <input type="text" name="link[]" /></li>
<li>Collection Name: <input type="text" name="text[]" /></li><br /><br />
<li>Company Name: <input type="text" name="co_name[]" /></li>
<li>Link: <input type="text" name="link[]" /></li>
<li>Collection Name: <input type="text" name="text[]" /></li><br /><br />
</ul><br />
<input type="submit" value="Submit To Database?" />
</form>
Code: Select all
$size_array = count($_POST['co_name']);//count the nr of times this field occurs in the array, so we can use this to process with a loop
//now INSERT
for ($i=0; $i<$size_array; $i++){
$query = 'INSERT into collections'.
" values ( '".mysql_real_escape_string($_POST['co_name'][$i])."', '".mysql_real_escape_string($_POST['link'][$i])."', '".mysql_real_escape_string($_POST['text'][$i])."')";
$result = mysql_query($query) or die ("Error in query: $query");
}
if (!mysql_query($query,$con))
{
die('Error: ' . mysql_error());
}
Thanx!