$php_mysql$ Posted July 5, 2012 Share Posted July 5, 2012 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(); } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/265229-form-submit-value-not-being-sent-please-check/ Share on other sites More sharing options...
oraya Posted July 5, 2012 Share Posted July 5, 2012 where are you getting the id from I don't see it in the form? Quote Link to comment https://forums.phpfreaks.com/topic/265229-form-submit-value-not-being-sent-please-check/#findComment-1359243 Share on other sites More sharing options...
jcbones Posted July 5, 2012 Share Posted July 5, 2012 method="post" ... $id = $_GET['del']; There lies your problem. Quote Link to comment https://forums.phpfreaks.com/topic/265229-form-submit-value-not-being-sent-please-check/#findComment-1359244 Share on other sites More sharing options...
$php_mysql$ Posted July 5, 2012 Author Share Posted July 5, 2012 method="post" ... $id = $_GET['del']; There lies your problem. still no value is being sent to act=delete i tried that too before Quote Link to comment https://forums.phpfreaks.com/topic/265229-form-submit-value-not-being-sent-please-check/#findComment-1359246 Share on other sites More sharing options...
oraya Posted July 5, 2012 Share Posted July 5, 2012 I noticed that also, but just assumed he was passing the variable from another page. Quote Link to comment https://forums.phpfreaks.com/topic/265229-form-submit-value-not-being-sent-please-check/#findComment-1359247 Share on other sites More sharing options...
$php_mysql$ Posted July 5, 2012 Author Share Posted July 5, 2012 something is still not right tho i made method to GET but nothing is happening in act=delete the values are not being executed there Quote Link to comment https://forums.phpfreaks.com/topic/265229-form-submit-value-not-being-sent-please-check/#findComment-1359250 Share on other sites More sharing options...
jcbones Posted July 5, 2012 Share Posted July 5, 2012 Put this code at the top of the page, and copy/paste the results: echo '<pre>' . print_r($_GET,true) . print_r($_POST,true) . '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/265229-form-submit-value-not-being-sent-please-check/#findComment-1359251 Share on other sites More sharing options...
$php_mysql$ Posted July 5, 2012 Author Share Posted July 5, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/265229-form-submit-value-not-being-sent-please-check/#findComment-1359255 Share on other sites More sharing options...
jcbones Posted July 5, 2012 Share Posted July 5, 2012 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); Quote Link to comment https://forums.phpfreaks.com/topic/265229-form-submit-value-not-being-sent-please-check/#findComment-1359307 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.