Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 02-21-2007, 10:42 AM   #1 (permalink)
 
Newb Techie

Join Date: Jan 2007

Posts: 6

mcclellanfsu

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  
Old 02-21-2007, 07:45 PM   #2 (permalink)
 
True Techie

Join Date: Aug 2006

Posts: 176

StillwaterIT

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  
Old 02-21-2007, 08:15 PM   #3 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,389

office politics will become famous soon enough

Default

strings must be enclosed in single or double quotes.

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

office politics is offline  
Old 02-21-2007, 09:16 PM   #4 (permalink)
 
Banned

Join Date: Jun 2006

Location: United States of America

Posts: 109

Enterpriser is an unknown quantity at this point

Default

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

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