Skip to content

Commit

Permalink
Fixed database insertion to use (col_name list) VALUES (value list).
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/trunk/unstable@7 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
John Richards committed Mar 10, 2003
1 parent 1b9130a commit 39217a0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,22 +261,25 @@
echo "\t\t\t\t\t\t<br /><b>Results are being submitted...<br /><br />\n";
echo "\t\t\t\t\t</td>\n";
echo "\t\t\t\t</tr>\n";
$subquery = "INSERT INTO $surveytable VALUES ('',";
foreach ($insertarray as $in)
$subquery = "INSERT INTO $surveytable ";
foreach ($insertarray as $value)
{
$col_name .= "," . substr($value, 1); //Strip off leadinf 'F'
if (get_magic_quotes_gpc()=="0")
{
$subquery .= "'". addcslashes($$in, "'") . "',";
$values .= ",'" . addcslashes($$value, "'") . "'";
}
else
{
$subquery .= "'".$$in."',";
$values .= ",'" . $$value . "'";
}
//echo "$in<br />\n";
//echo "$value<br />\n"; //Debugging info
}
$subquery = substr($subquery, 0, strlen($subquery)-1);
$subquery .= ")";
//echo $subquery;
$col_name = substr($col_name, 1); //Strip off inital comma
$values = substr($values, 1); //Strip off leading comma
$subquery .= "($col_name) VALUES ($values)";
echo "<pre style='text-align: left'>$subquery</pre>\n"; //Debugging info

if ($surveyactive == "Y")
{
$subresult=mysql_query($subquery) or die ("Couldn't update $surveytable<br />\n".mysql_error()."<br />\n<br />\n$subquery");
Expand Down

0 comments on commit 39217a0

Please sign in to comment.