Jump to content

Form submit value not being sent please check


$php_mysql$

Recommended Posts

Hey all whats wrong when i hit submit the numeric value which i enter is not being sent to act=delete

 

<?php
include 'db.php';
$act = $_GET["act"];
$id=$_GET["id"];

echo '<form action="delete.php?act=delete" method="post">';
echo '<input type="text" name="del">';
echo '<input type="submit" value="Delete">';
echo '</form>';

if($act=='delete'){
            $id = $_GET['del']; 
	    $sql="SELECT `id`, `image` FROM `tbl` WHERE id='".$id."'";
		$result = mysql_query($sql);
		if(!$result){
		echo 'SELECT failed: '.mysql_error();
		}else{
		while($row = mysql_fetch_array($result)){
		if (mysql_num_rows($result)) {
		$id = $row['id'];
		if(!unlink($row['image'])){
		echo "unlink ".$row['image']." failed";
			}
		}
		$sql="DELETE FROM tbl WHERE id = '".$id."'";
		$result= mysql_query($sql);
		if(!$result){
		echo 'DELETE from tbl with id '.$id.' failed: '.mysql_error();
		}
		}
		}
}
?>

Link to comment
Share on other sites

i got that but why is it not executing my sql query? no matter what ever numeric value i input i get it printed by using print_r(); func but when i use $id = $_POST['id']; nothing prints

 

<?php
include 'db.php';

print_r($_POST['id']);

if(isset($_POST['submit'])){

            $id = $_POST['id']; // The $id is not effecting the sql query WHERE id='".$id."'

    	    $sql="SELECT `id`, `image` FROM `tbl` WHERE id='".$id."'";
		$result = mysql_query($sql);
		if(!$result){

		}else{
		while($row = mysql_fetch_array($result)){
		if (mysql_num_rows($result)) {
		$id = $row['id'];
		if(!unlink($row['image'])){

			}
		}
		$sql="DELETE FROM tbl WHERE id = '".$id."'";
		$result= mysql_query($sql);
		if(!$result){

		}
		}
		}
}
?>

<form action="delete.php" method="POST">
<input type="text" name="id">
<input type="submit" value="Delete">
</form>

Link to comment
Share on other sites

This is marked as solved?  Not sure that it is.

 

Have you echo'd the $sql variable to see if it contains the data you want?

echo $sql;

Have you made sure there is not a problem on the database's end, by catching any database errors?

$result = mysql_query($sql) or exit($sql . ' has an error <br />' . mysql_error());

 

Are you getting any notices about undefined indexes? if so, paste them.

if not,

Do you have error reporting on, and display errors?

//runtime setting
error_reporting(-1);
ini_set('display_errors',1);

 

Link to comment
Share on other sites

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.