kr3m3r Posted August 21, 2007 Share Posted August 21, 2007 Hi guys, I'm getting this result: Fatal error: Call to undefined function: array() in /home/.titch/rwkremer/kr3m3r.com/insert_book.php on line 9 From this code: <html> <head> <title>Book-O-Rama Book Entry Results</title> </head> <body> <h1>Book-O-Rama Entry Results</h1> <?php //create short variable names $isbn=$HTTP_POST_VARS('isbn'); $author=$HTTP_POST_VARS('author'); $title=$HTTP_POST_VARS('title'); $price=$HTTP_POST_VARS('price'); if(!$isbn || !$author || !$title || !$price) { echo 'You have not entered all the required details. <br />' .'Please go back and try again.'; exit; } $isbn=addslashes($isbn); $author=addslashes($author); $title=addslashes($title); $price=addslashes($price); @ $db = mysql_pconnect('learning', 'bookorama', 'bookorama123'); if(!$db) { echo 'Error: Could not connect to database. Please try later.'; exit; } mysql_select_db('books'); $query = "insert into books values ('".$isbn."','".$author."','".$title."','".$price."')"; $result = mysql_query($query); if($result) echo mysql_affected_rows().' book inserted into database.'; ?> </body> </html> My first question is obviously, do you know what the fatal error is? But the second question I have is Where do I start counting the lines to locate the error? From the begining of the php code? From the begining of all the code? Thanks for your help and your time! -Robb Quote Link to comment https://forums.phpfreaks.com/topic/65900-solved-fatal-error-egad/ Share on other sites More sharing options...
kr3m3r Posted August 21, 2007 Author Share Posted August 21, 2007 Need to pay more attention was the use of () rather than []. Sorry to bother you all. -Robb Quote Link to comment https://forums.phpfreaks.com/topic/65900-solved-fatal-error-egad/#findComment-329438 Share on other sites More sharing options...
trq Posted August 21, 2007 Share Posted August 21, 2007 The error usually results when you try and call a function which does not exist. The line the error reports may not be the exact line on which the error occures (counted from the top of the file), but is where php decides it can no longer continue. The problem is your calling $HTTP_POST_VARS('isbn') as though it was a function. Array indexes are displayed using [], so it should be $HTTP_POST_VARS['isbn']. On top of that... $HTTP_POST_VARS has long been depricated in favour of $_POST. Change... $isbn=$HTTP_POST_VARS('isbn'); $author=$HTTP_POST_VARS('author'); $title=$HTTP_POST_VARS('title'); $price=$HTTP_POST_VARS('price'); to $isbn = $_POST['isbn']; $author = $_POST['author']; $title = $_POST['title']; $price = $_POST['price']; PS: You really ought check these variables are set before trying to use them. You'll be generating other warnings otherwise. Quote Link to comment https://forums.phpfreaks.com/topic/65900-solved-fatal-error-egad/#findComment-329439 Share on other sites More sharing options...
AndyB Posted August 21, 2007 Share Posted August 21, 2007 Thorpe nailed it. FYI, $HTTP_POST_VARS['isbn'] - old style (the tutorial or your book is out of date). http://www.php.net/manual/en/reserved.variables.php#reserved.variables.post - deprecated since 4.1 And line 9 is/was the ninth line of your code. Quote Link to comment https://forums.phpfreaks.com/topic/65900-solved-fatal-error-egad/#findComment-329444 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.