help! not sure how to resolve this error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mattman098
Forum Newbie
Posts: 16
Joined: Wed Feb 10, 2010 1:45 pm

help! not sure how to resolve this error

Post by mattman098 »

Basically I'm doing an add function for a small project, and I'm trying to add values from text fields into a database using _POST...

and I think I'm soooooo close to having it work but I'm getting this one error when i try and run it

Code: Select all

Fatal error: Function name must be a string in /home/a2778613/public_html/add.php on line 3
I'm thinking i might have something to do with how that particular value is an integer in the database, and I'm trying to force it into a string or something? that's just a guess though...

anyway here's my code:

Code: Select all

<?php
 
$stid = $_POST('stid');
$fname = $_POST('fname');
$sname = $_POST('sname');
$crs = $_POST('crs');
$sch = $_POST('sch');
$yos = $_POST('yos');
 
$con = mysql_connect("[i]dbhost[/i]", "[i]username[/i]", "[i]password[/i]"); 
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("[i]dbname[/i]", $con);
 
mysql_query("INSERT INTO students VALUES($stid, $fname, $sname, $crs, $sch, $yos)");
 
mysql_close($con);
 
?>
Thanks in advance for any help here, and if you think you need to see any more of my code to sort this just let me know and I'll post it
User avatar
a.heresey
Forum Commoner
Posts: 59
Joined: Wed Dec 13, 2006 7:31 pm
Location: Chesapeake, VA, US

Re: help! not sure how to resolve this error

Post by a.heresey »

Wrong brackets, yo.

Code: Select all

 
$stid = $_POST['stid'];
$fname = $_POST['fname'];
$sname = $_POST['sname'];
$crs = $_POST['crs'];
$sch = $_POST['sch'];
$yos = $_POST['yos'];
 
Your query is going to need quotes as well.

Code: Select all

 
mysql_query("INSERT INTO students VALUES('$stid', '$fname', '$sname', '$crs', '$sch', '$yos')");
 
Post Reply