Page 1 of 1
will this work
Posted: Wed Jan 20, 2010 10:42 am
by gotornot
I am trying to insert all extra questions asked on data cpture into a db will this work
if (isset($_REQUEST))
{
foreach($_REQUEST as $key=>$value)
{
// only get the data for extra questions
$schq = "SELECT * FROM extraq WHERE programid='$programid'";
$schr = mysql_query($schq);
while($schrow=mysql_fetch_array($schr))
{
$thisqid = $schrow["id"];
if ($thisqid=='$key')
{
$addq3 = "INSERT INTO $extraqopt (extraqid, value, subid) VALUES ('$thisqid', '$value', '$subid')";
$addr3 = mysql_query($addq3);
}
}
}
}
Re: will this work
Posted: Wed Jan 20, 2010 11:03 am
by AbraCadaver
Yes and no. Your single quotes around $key will keep it from ever matching, however if you change it it should work. Plus I don't see where $programid and $subid are being defined. That being said, it is not optimal. Why not just send the field names as keys like this (example only):
Code: Select all
<input type="hidden" name="data[extraqid]" value="<?php echo $extraqid; ?>">
<input type="hidden" name="data[subid]" value="<?php echo $subid; ?>">
<input type="text" name="data[value]">
To process:
Code: Select all
$fields = implode(',', array_keys($_POST['data']));
$values = "'" . implode("','", array_map('mysql_real_escape_string', $_POST['data'])) . "'";
mysql_query("INSERT INTO table_name ($fields) VALUES ($values)";
Re: will this work
Posted: Wed Jan 20, 2010 12:42 pm
by gotornot
this does not seem to put the data in the table and is driving me up the wall
//grab the sub id for extra q submission
$chkq4 = "SELECT * FROM submission WHERE email='$email' AND programid='$programid'";
$chkr4 = mysql_query($chkq4);
$chkrow4 = mysql_fetch_array($chkr4);
$subid = $chkrow4["id"];
// insert extraq data
// grab the extra data in from the string i may have to blow it appart and check it has a value
if (isset($_REQUEST))
{
foreach($_REQUEST as $key=>$value)
{
// only get the data for extra questions
$schq = "SELECT * FROM extraq WHERE programid='$programid'";
$schr = mysql_query($schq);
while($schrow=mysql_fetch_array($schr))
{
$thisqid = $schrow["id"];
if ($thisqid==$key)
{
$addq3 = "INSERT INTO $extraqopt (extraqid, value, subid) VALUES ('$thisqid', '$value', '$subid')";
$addr3 = mysql_query($addq3);
}
}
}
}
if basically their is an extra q why can it not bung it in.