Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP with mySQL Insert statement using session variables

Status
Not open for further replies.

adgesap

Technical User
Mar 11, 2005
10
GB
I have been trying to use and insert statement with the following PHP code:
Code:
<?php
session_start();
  $_SESSION['SentenceText'] = $_POST['SentenceText'];
  $_SESSION['SentenceManner'] = $_POST['SentenceManner'];
  
echo' <p>('.stripslashes($_SESSION['SentenceText']).')<br/>('.$_SESSION['SentenceManner'].')</p>';
  
$title='SecondPage';
include ('functions.inc');
db_logon();
html_head($title);

$query="INSERT INTO Sentence (SentenceManner) VALUES ('".$_SESSION['SentenceManner']."') where SentenceID=".$_SESSION['SentenceID']."";
echo $query;
mysql_query($query) or die($mysql_error());
There's more to the page, but it's up to this point that it goes wrong. This is what appears in the browser when I run the script (and the mysql_query($query) is line 15):

(Do you love me)
(Question)
INSERT INTO Sentence (SentenceManner) VALUES ('Question') where SentenceID=2
Fatal error: Function name must be a string in G:\ on line 15

Any suggestions, please. This is for an academic project and it's coming up due!
 
You're calling a MySQL function:

Sentence(SentenceManner)

But Sentence isn't a valid mysql function.

I know this isn't the MySQL forum, so correct me if I'm wrong, but it makes no sense to use a WHERE clause in an INSERT statement. It doesn't look like you actually want to insert a row in your table, it looks like you want to update an existing row. If Sentence is the table and SentenceManner is the column you're updating, then you really want something like:

Code:
$query = "UPDATE Sentence set SentenceManner='" . $_SESSION['SentenceManner']. "' where SentenceID=" . $_SESSION['SentenceID']

If you really want to insert a row, then you'd better check the syntax of an INSERT statement in MySQL.
 
That's done it! Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top