Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

What's wrong with this code?

Codes here !

Moderators: macek, egami, gesf

What's wrong with this code?

Postby friend_al_23 » Thu Jul 10, 2003 5:56 am

Code: Select all
<?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
friend_al_23
New php-forum User
New php-forum User
 
Posts: 12
Joined: Sat Dec 28, 2002 6:30 pm
Location: Philippines

Re: What's wrong with this code?

Postby swirlee » Fri Jul 11, 2003 7:43 am

What error are is it generating? Unless there's some wonky syntax that I'm not aware of (if there is, please, somebody tell me), my guess is the problem is your multitudinous backticks that have no place in this code. What the hell are those all about? Try this:

Code: Select all
<?
$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()" .
")";

$result = mysql_query($query,$link) or die("Query Error: ".mysql_error());
?>


Also, you might be interested to known that when performing a MySQL INSERT, if you're providing a value for every column in VALUES(), you don't need to specify the column names after sc_nom.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby friend_al_23 » Fri Jul 11, 2003 8:13 am

Never mind. The first code was generating error at first. Then several people helped, and now I got it working already. Thanks for your input anyway. :)
friend_al_23
New php-forum User
New php-forum User
 
Posts: 12
Joined: Sat Dec 28, 2002 6:30 pm
Location: Philippines


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.