mcclellanfsu
Solid State Member
- Messages
- 6
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!
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!