Insert statement error

admin

Administrator
Staff member
Hi, this is not exactly a insert statement error but something related to it.

I am trying to insert different variables with the names SSN$i that is (SSN1, SSN2, .. etc). But am having a problem with it. The values are properly passed from the previous page but then in the insert statement there is a problem.

Here is the code:
<?php
$dbcnx = @mysql_connect("host", "user", "pwd");
mysql_select_db("db");
if(!$dbcnx)
{ echo("<p>Error while connecting to the database.</p>");
}
echo("$count\n");
//$count is equal to 16..passed from previous page

$j = 1;
echo("$SSN1\n $SSN2\n $SSN10\n $SSN11\n $SSN1\n $SSN12\n $SSN13\n $SSN16\n");
//values showed properly i.e values are getting passed properly

while ($j<=$count) {

$sql = "INSERT INTO tblStudHw (SSN, HwNo, SubDate, HwGrade) values ('$SSN$j', '$HwNo', '$SubDate$j', '$Marks$j')";
echo("<P>'SSN$j'\n'$SSN$j'\n'$HwNo'\n'$SubDate$j'\n'$Marks$j'\n</P>");
if (!mysql_query($sql)) {
echo("<P>Error adding Grades:". mysql_error(). "</P>");
}
$j++;
}
?>
 
Back
Top