0

<?php
require_once '_includes/_coo.php';

$id =$_post['user_id'];  //error here -> line 4 


// sending query
mysql_query("DELETE FROM example WHERE BookID = '$id'")
or die(mysql_error());      

header("Location: index.php");

?>
error in line 4

4
Contributors
3
Replies
19
Views
2 Years
Discussion Span
Last Post by minitauros
0

Your problem does not seem like it is on line "4", more of the line above, below. You have not specified the error, what does the error say is the problem?

1

You're probably getting a notice that there is an undefined variable on line 4. That is because $_post does not exist. Variable names in PHP are case-sensitive. This means that you need to use $_POST (with capital letters) - this represents the values that are sent with the POST request.

You will also get a notice if an array key is undefined. That means that if $_POST['user_id'] is undefined, you will be notified of it. This is not a serious error, and you can turn the reporting of notices off with for example:

// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);

(from php.net)

Code that will probably work:

// Check if $_POST['user_id'] is not empty. If true is returned, assign $_POST['user_id'] to $id. Else, assign null to $id.
$id = !empty($_POST['user_id']) ? $_POST['user_id'] : null;

(In the example above, I use the "ternary operator", see also here and scroll to "Ternary operator").

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.