Forum Moderators: coopster

Message Too Old, No Replies

MySql Insert Form Values Interatively

         

lbombardier

10:22 pm on Oct 20, 2007 (gmt 0)

10+ Year Member



Having a heck of a time with this one. I'm trying to store a series of scores. Each record has 2 fields which are unique and 1 that isn't. There are 2 records that should be inserted each time. 'MyID' is the same for both records.

Form:

<input name="MyID" type="hidden" id="MyID" value="<? echo $sessionVar?>" />
<input name="MyCheckbox[]" type="checkbox" id="MyCheckbox[]" value="1" />
<input name="MyScore[]" type="text" id="MyScore[]"/>
<input name="MyCheckbox[]" type="checkbox" id="MyCheckbox[]" value="1" />
<input name="MyScore[]" type="text" id="MyScore[]"/>

Query:

for ($i=0; $i < 3; $i++) {

$querySQL = sprintf("INSERT into tblMytable (MyID=%s, MyScore=%s,MyCheckbox=%s",
stripString($_POST['MyID'], "int"),
stripString($_POST['MyScore'][$i], "int"),
stripString($_POST['MyCheckbox'][$i], "int"));

run query etc.. }

When i run this i get a non-descript sql error. I;m just wondering if there is a better way to do this? And also, the checkbox values never seem to appear. (I've checked the data with a print_r($_POST).)

Help?

Habtom

4:55 am on Oct 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is MyID the primary key in your table, or it is just a normal id?

Can you check what you get by printing $querySQL and $querySQL2?

$MyID = stripString($_POST['MyID']
$MyScore = stripString($_POST['MyScore']);
$MyCheckbox = stripString($_POST['MyCheckbox'];

$querySQL = "INSERT into tblMytable (MyID, MyScore,MyCheckbox)
". $MyID) .",
". $MyScore[0]) .",
". $MyCheckbox[0]) ."";

echo $querySQL;

$querySQL2 = "INSERT into tblMytable (MyID, MyScore,MyCheckbox)
". $MyID) .",
". $MyScore[1]) .",
". $MyCheckbox[1]) ."";

echo $querySQL2;

Habtom