PDA

View Full Version : PHP: What's wrong with this code?



QReyes
July 10th, 2003, 10:18
<?php

$link = mysql_connect("localhost","root","") or die("Connection Error: ".mysql_error());

mysql_select_db("thecofc_ama",$link) or die ("Database Error: ".mysql_error());

$result = mysql_query('INSERT INTO `sc_nom` (`stud`, `studnum`, `email`, `pres`, `vice`, `sec`, `treas`, `proe`, `proi`, `sgt`, `strep`, `ndrep`, `rdrep`, `datetime`) VALUES (`$stud`, `$studnum`, `$email`, `$pres`, `$vice`, `$sec`, `$treas`, `$proe`, `$proi`, `$sgt`, `$strep`, `$ndrep`, `$rdrep`, NOW())',$link) or die("Query Error: ".mysql_error());

mysql_free_result($result);

mysql_close($link);

?>
You can try it out at http://thecofclub.distanthost.com/AMA/sc_nom.php

Loon
July 10th, 2003, 10:24
Query Error: Unknown column '$stud' in 'field list'

Do you have a column named "stud" in your table?

QReyes
July 10th, 2003, 10:48
Originally posted by Loon
Do you have a column named "stud" in your table?
Yes.

dawizman
July 10th, 2003, 11:01
<?php

mysql_connect("localhost","root","") or die("Connection Error: " . mysql_error());

mysql_select_db("thecofc_ama") or die ("Database Error: " . mysql_error());

$result = mysql_query('INSERT INTO `sc_nom` (`stud`, `studnum`, `email`, `pres`, `vice`, `sec`, `treas`, `proe`, `proi`, `sgt`, `strep`, `ndrep`, `rdrep`, `datetime`) VALUES (`$stud`, `$studnum`, `$email`, `$pres`, `$vice`, `$sec`, `$treas`, `$proe`, `$proi`, `$sgt`, `$strep`, `$ndrep`, `$rdrep`, NOW())',$link) or die("Query Error: ".mysql_error());

mysql_free_result($result);

mysql_close($link);

?>


Try that

QReyes
July 10th, 2003, 11:13
Same error as before:

Query Error: Unknown column '$stud' in 'field list'

dawizman
July 10th, 2003, 11:45
Try this then:


<?php

mysql_connect("localhost","root","") or die("Connection Error: " . mysql_error());

mysql_select_db("thecofc_ama") or die ("Database Error: " . mysql_error());

$result = mysql_query("INSERT INTO sc_nom (stud, studnum, email, pres, vice, sec, treas, proe, pro1, sgt, strep, ndrep, rdrep, datetime) VALUES (`$stud`, `$studnum`, `$email`, `$pres`, `$vice`, `$sec`, `$treas`, `$proe`, `$proi`, `$sgt`, `$strep`, `$ndrep`, `$rdrep`, NOW())") or die("Query Error: ".mysql_error());

mysql_free_result($result);

mysql_close($link);

?>

QReyes
July 11th, 2003, 12:27
Thanks for your inputs, guys. BTW, dawizman, that code worked.