Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/65900-solved-fatal-error-egad/
Share on other sites

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.