Page 2 of 2
Re: Need help
Posted: Tue Sep 16, 2008 9:47 am
by wolfwood16
yeah, the $DB exist...
now the error is
Code: Select all
Unknown column '$_POST[id]' in 'field list'

really strange..........
Re: Need help
Posted: Tue Sep 16, 2008 9:50 am
by bungkusan
wolfwood16 wrote:yeah, the $DB exist...
now the error is
Code: Select all
Unknown column '$_POST[id]' in 'field list'

really strange..........
please include all your code here, maybe I can help you ^^
Re: Need help
Posted: Tue Sep 16, 2008 9:51 am
by Ziq
Are you sure?
PHP code:
Code: Select all
$nameid = $_POST['name'];
$middlenameid = $_POST['middlename'];
$surnameid = $_POST['surname'];
// Read documentation about foreach!
foreach($nameid as $key => $value)
{
$insertNow = 'INSERT INTO '.$DB.' (id, namefields, middlenamefields, surnamefields) VALUES ('.$_POST['id'].', '.$nameid[$key].', '.$middlenameid[$key].', '.$surnameid[$key].')';
mysql_query($insertNow, $connString) or die($insertNow.' <br> '.mysql_error());
// $nameid is an array. And you cannot print variable due print() echo() or some else
}
Re: Need help
Posted: Tue Sep 16, 2008 9:54 am
by wolfwood16
this is my actual code, all the fields are correct, but still
Code: Select all
INSERT INTO theActualCode(id,subj_code,subj_desc,lec_hrs,lab_hrs,subj_units) VALUES( `$_POST[id]`,`$subjCode[$v]`,`$subjDesc[$v]`,`$subjLecHrs[$v]`,`$subjLabHrs[$v]`,`$subjUnits[$v]` )
Unknown column '$_POST[id]' in 'field list'
even i put it this way,
Code: Select all
$subjID = $_POST[id];
//and put on the value to be stored is
....subj_units) VALUES( `$subjID[$v]`,`$subjCode[$v]`.....
error became
Code: Select all
Unknown column '$subjID[$v]' in 'field list'
Re: Need help
Posted: Tue Sep 16, 2008 9:57 am
by bungkusan
Ziq wrote:Are you sure?
PHP code:
Code: Select all
$nameid = $_POST['name'];
$middlenameid = $_POST['middlename'];
$surnameid = $_POST['surname'];
// Read documentation about foreach!
foreach($nameid as $key => $value)
{
$insertNow = 'INSERT INTO '.$DB.' (id, namefields, middlenamefields, surnamefields) VALUES ('.$_POST['id'].', '.$nameid[$key].', '.$middlenameid[$key].', '.$surnameid[$key].')';
mysql_query($insertNow, $connString) or die($insertNow.' <br> '.mysql_error());
// $nameid is an array. And you cannot print variable due print() echo() or some else
}
Code: Select all
$nameid = $_POST['name'];
$middlenameid = $_POST['middlename'];
$surnameid = $_POST['surname'];
$id = $_POST['id'];
// Read documentation about foreach!
foreach($nameid as $key => $value)
{
$insertNow = 'INSERT INTO '.$DB.' (id, namefields, middlenamefields, surnamefields) VALUES ('$id', '.$nameid[$key].', '.$middlenameid[$key].', '.$surnameid[$key].')';
mysql_query($insertNow, $connString) or die($insertNow.' <br> '.mysql_error());
// $nameid is an array. And you cannot print variable due print() echo() or some else
}
Any error / warning from that code above?
please print_r($nameid);
Re: Need help
Posted: Tue Sep 16, 2008 9:59 am
by wolfwood16
Ziq wrote:Are you sure?
PHP code:
Code: Select all
$nameid = $_POST['name'];
$middlenameid = $_POST['middlename'];
$surnameid = $_POST['surname'];
// Read documentation about foreach!
foreach($nameid as $key => $value)
{
$insertNow = 'INSERT INTO '.$DB.' (id, namefields, middlenamefields, surnamefields) VALUES ('.$_POST['id'].', '.$nameid[$key].', '.$middlenameid[$key].', '.$surnameid[$key].')';
mysql_query($insertNow, $connString) or die($insertNow.' <br> '.mysql_error());
// $nameid is an array. And you cannot print variable due print() echo() or some else
}
i guess i didn't need to put the concatenation "." due to this error:
Code: Select all
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
'`.$subjLecHrs[$v].`,`.$subjLabHrs[$v].`,`.$subjUnits[$v].` )' at line 3
Re: Need help
Posted: Tue Sep 16, 2008 10:08 am
by wolfwood16
these are the entire codes
on the form page
Code: Select all
<td> <input name="subjcode[]" type="text" size="8"> </td>
<td> <input name="subjdesc[]" type="text" size="50"> </td>
<td> <input name="subjlechrs[]" type="text" size="8" maxlength="1"> </td>
<td> <input name="subjlabhrs[]" type="text" size="8" maxlength="1"> </td>
<td> <input name="subjunits[]" type="text" size="8" maxlength="1"> </td>
</tr>
<tr>
<td> <input name="subjcode[]" type="text" size="8"> </td>
<td> <input name="subjdesc[]" type="text" size="50"> </td>
<td> <input name="subjlechrs[]" type="text" size="8" maxlength="1"> </td>
<td> <input name="subjlabhrs[]" type="text" size="8" maxlength="1"> </td>
<td> <input name="subjunits[]" type="text" size="8" maxlength="1"> </td>
</tr>
<tr>
<td> <input name="subjcode[]" type="text" size="8"> </td>
<td> <input name="subjdesc[]" type="text" size="50"> </td>
<td> <input name="subjlechrs[]" type="text" size="8" maxlength="1"> </td>
<td> <input name="subjlabhrs[]" type="text" size="8" maxlength="1"> </td>
<td> <input name="subjunits[]" type="text" size="8" maxlength="1"> </td>
</tr>
on the process page
Code: Select all
$subjCode = $_POST[subjcode];
$subjID = $_POST[id];
$subjDesc = $_POST[subjdesc];
$subjLecHrs = $_POST[subjlechrs];
$subjLabHrs = $_POST[subjlabhrs];
$subjUnits = $_POST[subjunits];
foreach ($subjCode as $v => $a){
print_r($subjCode);
$addSubjCode = 'INSERT INTO '.$sessionNewCurrName.'(id,subj_code,subj_desc,lec_hrs,lab_hrs,subj_units)
VALUES(
`$subjID`,`$subjCode[$v]`,`$subjDesc[$v]`,`$subjLecHrs[$v]`,`$subjLabHrs[$v]`,`$subjUnits[$v]`
)';
mysql_query($addSubjCode, $conn) or die($addSubjCode." <br> ".mysql_error());
}
revisions made, but still.....
print_r($subjCode);
Code: Select all
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => g [7] => h [8] => i [9] => j ) INSERT INTO newtableCurriculum(id,subj_code,subj_desc,lec_hrs,lab_hrs,subj_units) VALUES( `$subjID`,`$subjCode[$v]`,`$subjDesc[$v]`,`$subjLecHrs[$v]`,`$subjLabHrs[$v]`,`$subjUnits[$v]` )
Unknown column '$subjID' in 'field list'
that would be 10 textboxes
Re: Need help
Posted: Tue Sep 16, 2008 10:10 am
by Ziq
You cannot use ` (this type qoutes) in the VALUES statement. You can use ' or ".
Re: Need help
Posted: Tue Sep 16, 2008 10:14 am
by bungkusan
# Unknown column '$subjID' in 'field list'
on the form page did you send your id via POST method?
Re: Need help
Posted: Tue Sep 16, 2008 10:23 am
by wolfwood16
bungkusan wrote:# Unknown column '$subjID' in 'field list'
on the form page did you send your id via POST method?
yes sir bungkusan, i did a post method
sir Ziq error now is...
Code: Select all
Array ( [0] => first [1] => second [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => ) INSERT INTO newtableCurriculum(id, subj_code, subj_desc, lec_hrs, lab_hrs, subj_units) VALUES( , first, desc1, 3, 2, 3 )
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' first, desc1, 3, 2, 3 )' at line 3
changing the ` to ' .....
filling in two textboxes, the rest are empty....but i guess it doesn't matter...
Re: Need help
Posted: Tue Sep 16, 2008 10:26 am
by bungkusan
Please use this code :
Code: Select all
$addSubjCode = "INSERT INTO '.$sessionNewCurrName.'(id,subj_code,subj_desc,lec_hrs,lab_hrs,subj_units) VALUES( '$subjID', '$subjCode[$v]', '$subjDesc[$v]', '$subjLecHrs[$v]', '$subjLabHrs[$v]', '$subjUnits[$v]')";
replace the existing your sql command
Re: Need help
Posted: Tue Sep 16, 2008 10:34 am
by wolfwood16
bungkusan wrote:Please use this code :
Code: Select all
$addSubjCode = "INSERT INTO '.$sessionNewCurrName.'(id,subj_code,subj_desc,lec_hrs,lab_hrs,subj_units) VALUES( '$subjID', '$subjCode[$v]', '$subjDesc[$v]', '$subjLecHrs[$v]', '$subjLabHrs[$v]', '$subjUnits[$v]')";
replace the existing your sql command
well, God for letting us figure the errors
this is the exact code...and
working
Code: Select all
foreach ($subjCode as $v => $a){
print_r($subjCode);
$addSubjCode = "INSERT INTO $sessionNewCurrName(id, subj_code, subj_desc, lec_hrs, lab_hrs, subj_units)
VALUES(
'$subjID', '$subjCode[$v]', '$subjDesc[$v]', '$subjLecHrs[$v]', '$subjLabHrs[$v]', '$subjUnits[$v]'
)";
mysql_query($addSubjCode, $conn) or die($addSubjCode." <br> ".mysql_error());
}
hope this will also help other newbies like me

thanks Sir Ziq and Sir Bungkusan.....hmmm how can we change the thread title?
