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();
		}
		}
		}
}
?>

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>

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);

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.