[Help with an error in PHP] - Computers



Search Tech-Forums - link takes you to our Forum's search page.

Note: The following is only a text archive!


To view the actual forum discussion, please visit our website at http://www.tech-forums.net

Pages:1



Help with an error in PHP

(Click here to view the original thread with full colors/images)



Posted by: mcclellanfsu

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. <br />'
.'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;
}


[COLOR=red]// The next line is line 46[/COLOR]

$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!



Posted by: StillwaterIT

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.



Posted by: office politics

strings must be enclosed in single or double quotes.

[php]
$query = "select * from tablename where col = '".$data."'"
[/php]



Posted by: Enterpriser

[QUOTE]strings must be enclosed in single or double quotes.[/QUOTE]

QFT





vBulletin Copyright ©2000 - 2003, Jelsoft Enterprises Limited.


PPC Management
vB Easy Archive Final - Created by Xenon