Alith7
08-03-2009, 05:31 PM
I have this insert statement:
if ($totalRows_getInk1==0) {
$iic1 = 0;
foreach ($_POST['Ink1Data'] as $key => $value) {
extract($value);
$insertInk1 = sprintf("INSERT INTO InkSide1 (JobID, InkID, Ink1Desc) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['JobID'], "int"),
GetSQLValueString($InkID, "int"),
GetSQLValueString($InkDesc, "text"));
mysql_query($insertInk1, $geQuote) or die(mysql_error());
}
}
else {
foreach ($_POST['Ink1Data'] as $key => $value) {
extract($value);
if ($InkID1!=NULL) {
$insertInk1 = sprintf("UPDATE InkSide1 SET JobID=%s, InkID=%s, Ink1Desc=%s WHERE Ink1ID=%s",
GetSQLValueString($_POST['JobID'], "int"),
GetSQLValueString($InkID, "int"),
GetSQLValueString($InkDesc, "text"),
GetSQLValueString($InkID1, "int"));
mysql_query($insertInk1, $geQuote) or die(mysql_error());
}
else {
$insertInk1 = sprintf("INSERT INTO InkSide1 (JobID, InkID, Ink1Desc) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['JobID'], "int"),
GetSQLValueString($InkID, "int"),
GetSQLValueString($InkDesc, "text"));
mysql_query($insertInk1, $geQuote) or die(mysql_error());
}
}
}
and this is the form script that feeds it:
if ($totalRows_getInk1==0) {
echo "<div id='ink11'>
<p>Ink:
<select name='Ink1Data[1][InkID]' class='dropMenu' onchange='addInkOpt(1,2)'>
<option value='NULL'></option>";
do {
echo "<option value='".$row_inkList['InkID']."'>".$row_inkList['InkDesc']."</option>";
}
while ($row_inkList = mysql_fetch_assoc($inkList));
$rows = mysql_num_rows($inkList);
if($rows > 0) {
mysql_data_seek($inkList, 0);
$row_inkList = mysql_fetch_assoc($inkList);
}
echo "</select> Desc:
<input name='Ink1Data[1][InkDesc]' type='text' class='inkdesc' maxlength='25' />
</p>
</div>"; }
else {
$cink1=0;
do {
$cink1++;
$jsVar1=$cink1+1;
echo "<div id='ink1".$cink1."'>
<p>Ink:
<select name='Ink1Data[".$cink1."][InkID]' class='dropMenu' onchange='addInkOpt(1,".$jsVar1.")'>
<option value='NULL'></option>";
do {
echo "<option value='".$row_inkList['InkID']."'";
if (!(strcmp($row_inkList['InkID'], $row_getInk1['InkID']))) {echo "selected=\"selected\"";}
echo ">".$row_inkList['InkDesc']."</option>";
}
while ($row_inkList = mysql_fetch_assoc($inkList));
$rows = mysql_num_rows($inkList);
if($rows > 0) {
mysql_data_seek($inkList, 0);
$row_inkList = mysql_fetch_assoc($inkList);
}
echo "</select>Desc:
<input name='Ink1Data[".$cink1."][InkDesc]' type='text' class='inkdesc' maxlength='25' value='".$row_getInk1['Ink1Desc']."' />
<input type=hidden name='Ink1Data[".$cink1."][InkID1]' value=".$row_getInk1['Ink1ID']." /></p></div>"; }
while ($row_getInk1 = mysql_fetch_assoc($getInk1));
$rows = mysql_num_rows($getInk1);
if($rows > 0) {
mysql_data_seek($getInk1, 0);
$row_getInk1 = mysql_fetch_assoc($getInk1);
} }
It inserts and updates the first row just fine, but it doesn't insert the 2nd or 3rd row.
I've been fighting with this for a while and I can't seem to figure out what I'm doing wrong.
This was my test script, and it echoed the whole array no problem.
if (!isset($_POST['submit']))
{
echo '<form action="" method="post">
<p>Ink Type: <select name="data[1][InkID]">
<option value="Spot">Spot</option>
<option value="Process">Process</option>
<option value="Varnish">Varnish</option>
</select><br />
Ink Desc: <input name="data[1][Ink1Desc]" /></p>
<p>Ink Type: <select name="data[2][InkID]">
<option value="Spot">Spot</option>
<option value="Process">Process</option>
<option value="Varnish">Varnish</option>
</select><br />
Ink Desc: <input name="data[2][Ink1Desc]" /></p>
<p>Ink Type: <select name="data[3][InkID]">
<option value="Spot">Spot</option>
<option value="Process">Process</option>
<option value="Varnish">Varnish</option>
</select><br />
Ink Desc: <input name="data[3][Ink1Desc]" /></p>
<input type="submit" name="submit" value="submit">
</form>
';
}
else
{
$JobID='2010';
$x= 0;
foreach ($_POST['data'] as $key => $value) {
extract($value);
$x++;
echo "<p>For Job ID #$JobID Ink $x has InkID $InkID, and Ink Description $Ink1Desc </p>";
}
}
If someone could please help me with this I would appreciate it.
I wish I had another coder here to look over my code when it's being difficult, but I don't, so I appreciate all the help I've been getting here on the forums!:thumbsup:
if ($totalRows_getInk1==0) {
$iic1 = 0;
foreach ($_POST['Ink1Data'] as $key => $value) {
extract($value);
$insertInk1 = sprintf("INSERT INTO InkSide1 (JobID, InkID, Ink1Desc) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['JobID'], "int"),
GetSQLValueString($InkID, "int"),
GetSQLValueString($InkDesc, "text"));
mysql_query($insertInk1, $geQuote) or die(mysql_error());
}
}
else {
foreach ($_POST['Ink1Data'] as $key => $value) {
extract($value);
if ($InkID1!=NULL) {
$insertInk1 = sprintf("UPDATE InkSide1 SET JobID=%s, InkID=%s, Ink1Desc=%s WHERE Ink1ID=%s",
GetSQLValueString($_POST['JobID'], "int"),
GetSQLValueString($InkID, "int"),
GetSQLValueString($InkDesc, "text"),
GetSQLValueString($InkID1, "int"));
mysql_query($insertInk1, $geQuote) or die(mysql_error());
}
else {
$insertInk1 = sprintf("INSERT INTO InkSide1 (JobID, InkID, Ink1Desc) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['JobID'], "int"),
GetSQLValueString($InkID, "int"),
GetSQLValueString($InkDesc, "text"));
mysql_query($insertInk1, $geQuote) or die(mysql_error());
}
}
}
and this is the form script that feeds it:
if ($totalRows_getInk1==0) {
echo "<div id='ink11'>
<p>Ink:
<select name='Ink1Data[1][InkID]' class='dropMenu' onchange='addInkOpt(1,2)'>
<option value='NULL'></option>";
do {
echo "<option value='".$row_inkList['InkID']."'>".$row_inkList['InkDesc']."</option>";
}
while ($row_inkList = mysql_fetch_assoc($inkList));
$rows = mysql_num_rows($inkList);
if($rows > 0) {
mysql_data_seek($inkList, 0);
$row_inkList = mysql_fetch_assoc($inkList);
}
echo "</select> Desc:
<input name='Ink1Data[1][InkDesc]' type='text' class='inkdesc' maxlength='25' />
</p>
</div>"; }
else {
$cink1=0;
do {
$cink1++;
$jsVar1=$cink1+1;
echo "<div id='ink1".$cink1."'>
<p>Ink:
<select name='Ink1Data[".$cink1."][InkID]' class='dropMenu' onchange='addInkOpt(1,".$jsVar1.")'>
<option value='NULL'></option>";
do {
echo "<option value='".$row_inkList['InkID']."'";
if (!(strcmp($row_inkList['InkID'], $row_getInk1['InkID']))) {echo "selected=\"selected\"";}
echo ">".$row_inkList['InkDesc']."</option>";
}
while ($row_inkList = mysql_fetch_assoc($inkList));
$rows = mysql_num_rows($inkList);
if($rows > 0) {
mysql_data_seek($inkList, 0);
$row_inkList = mysql_fetch_assoc($inkList);
}
echo "</select>Desc:
<input name='Ink1Data[".$cink1."][InkDesc]' type='text' class='inkdesc' maxlength='25' value='".$row_getInk1['Ink1Desc']."' />
<input type=hidden name='Ink1Data[".$cink1."][InkID1]' value=".$row_getInk1['Ink1ID']." /></p></div>"; }
while ($row_getInk1 = mysql_fetch_assoc($getInk1));
$rows = mysql_num_rows($getInk1);
if($rows > 0) {
mysql_data_seek($getInk1, 0);
$row_getInk1 = mysql_fetch_assoc($getInk1);
} }
It inserts and updates the first row just fine, but it doesn't insert the 2nd or 3rd row.
I've been fighting with this for a while and I can't seem to figure out what I'm doing wrong.
This was my test script, and it echoed the whole array no problem.
if (!isset($_POST['submit']))
{
echo '<form action="" method="post">
<p>Ink Type: <select name="data[1][InkID]">
<option value="Spot">Spot</option>
<option value="Process">Process</option>
<option value="Varnish">Varnish</option>
</select><br />
Ink Desc: <input name="data[1][Ink1Desc]" /></p>
<p>Ink Type: <select name="data[2][InkID]">
<option value="Spot">Spot</option>
<option value="Process">Process</option>
<option value="Varnish">Varnish</option>
</select><br />
Ink Desc: <input name="data[2][Ink1Desc]" /></p>
<p>Ink Type: <select name="data[3][InkID]">
<option value="Spot">Spot</option>
<option value="Process">Process</option>
<option value="Varnish">Varnish</option>
</select><br />
Ink Desc: <input name="data[3][Ink1Desc]" /></p>
<input type="submit" name="submit" value="submit">
</form>
';
}
else
{
$JobID='2010';
$x= 0;
foreach ($_POST['data'] as $key => $value) {
extract($value);
$x++;
echo "<p>For Job ID #$JobID Ink $x has InkID $InkID, and Ink Description $Ink1Desc </p>";
}
}
If someone could please help me with this I would appreciate it.
I wish I had another coder here to look over my code when it's being difficult, but I don't, so I appreciate all the help I've been getting here on the forums!:thumbsup: