MySQL insert
| From: | Scott Webb | Date: | Wed, 06 Sep 2000 04:23:57 +0000 |
| Subject: | MySQL insert | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-15427@lists.php.net to get a copy of this message | ||
I am a newbie to PHP and MySQL. I am trying to do what I perceive to be a
simple insert statement but am having trouble. I want to take the values
from a form insert the values and use a calculation to add an additional
value to the table. Here is the info:
I have a table named players with the following fields:
lname
fname
points
rebounds
assists
total
I want to take a html form input for lname, fname, points, rebounds and
assists. I want to insert these values into the table. I want the total
field to be a calculation of points, rebounds and assists and insert it into
the total field in the players table. Here is my code that is not working:
$sql = "INSERT INTO players (fname, lname, points, rebounds, total)
VALUES ('$fname', '$lname', '$points',
'($points+($rebounds*2)+($assists*2)')";
$connection = mysql_connect("localhost","user","password")
or die ("Couldn't connect to server.");
$db = mysql_select_db("db_name", $connection)
or die("Couldn't select database.");
$sql_result = mysql_query($sql,$connection)
or die("Couldn't add record.");
What am I doing wrong?
Thanks,
Scott