<?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

Recommended Answers

All 3 Replies

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?

$id =$_POST['user_id'];
commented: Posting answers is good. Posting with explanations is better. +12

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").

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.