Computer ForumsComputers  

Go Back   Computer Forums > Programmers Lounge > Programming Discussions

Reply
 
LinkBack Thread Tools Display Modes
Old 02-21-2007, 09:42 AM   #1 (permalink)
Newb Techie
 
Join Date: Jan 2007
Posts: 6
Default Help with an error in PHP

First off I want to say that I am just beginning with PHP...OK, now I am trying to write just a simple little program to try to learn PHP and MYSQL. It basically just will insert information about a book into a database.

My problem is that I keep getting an error when I try to add the information to the database and I can't figure out what I am doing wrong.

THe error is:
Parse error: syntax error, unexpected T_STRING in /insert_book.php on line 46

My code for the file insert_book.php is as follows:

<?php
//create short variable names
$isbm=$_POST['isbn'];
$author=$_POST['author'];
$title=$_POST['title'];
$price=$_POST['price'];

if (!$isbn || !$author || !$title || !$price)
{
echo 'You have not entered all the required details.
'
.'Please go back and try again.';
exit;
}
if (!get_magic_quotes_gpc())
{
$isbn = addslashes($isbn);
$author = addslashes($author);
$title = addslashes($title);
$price = doubleval($price);
}

$dbhost = 'XXXXXX';
$dbuser = 'XXXXXXXX';
$dbpass = 'XXXXXXX';

@ $db = new mysqli($dbhost, $dbuser, $dbpass);

$dbname = 'XXXXXXXXXX';
mysql_select_db($dbname);

if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}


// The next line is line 46

$query = insert into books values
('".$isbn."', '".$author."', '".$title."', '".$price."')";
$result = $db->query($query);
if ($result)
echo $db->affected_rows.' book inserted into database.';

$db->close();
?>

Any help on this would be greatly appreciated.

Thanks in advance!
mcclellanfsu is offline   Reply With Quote
Old 02-21-2007, 06:45 PM   #2 (permalink)
True Techie
 
Join Date: Aug 2006
Posts: 176
Default

which mysql version are you using?

Try this:
------------------
$query = insert into books (cat1, cat2, cat3, cat4) values ('".$isbn."', '".$author."', '".$title."', '".$price."')";
------------------

where cat1 cat2, etc are the categories in the table you want to put your values.
StillwaterIT is offline   Reply With Quote
Old 02-21-2007, 07:15 PM   #3 (permalink)
Dope Tech
 
Join Date: Jan 2004
Posts: 3,589
Send a message via ICQ to office politics Send a message via AIM to office politics Send a message via Yahoo to office politics
Default

strings must be enclosed in single or double quotes.

PHP Code:
$query "select * from tablename where col = '".$data."'" 

__________________
Tech IMO.com | ExtremeTech.com | ASP Free.com | SysOpt.com | Tech Support Guy.org
DB Forums.com | Cyber Tech Help.com | Lazy Forums.com | Warrior Nation.net

'If you don't stand for somethin you'll fall for anything' - Dr. Dre Been there, done that
office politics is offline   Reply With Quote
Old 02-21-2007, 08:16 PM   #4 (permalink)
Banned
 
Join Date: Jun 2006
Location: United States of America
Posts: 110
Default

Quote:
strings must be enclosed in single or double quotes.
QFT
Enterpriser is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 02:40 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0