Computers |
|
| | #1 (permalink) |
| Newb Techie Join Date: Jan 2007
Posts: 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! |
| | |
| | #2 (permalink) |
| True Techie Join Date: Aug 2006
Posts: 176
| 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. |
| | |
| | #3 (permalink) |
| Dope Tech | strings must be enclosed in single or double quotes. PHP Code:
__________________ 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 |
| | |