mysql - simple delete query using php -
i trying create delete query html using php:
html:
<form method="post" action="" > id<input type="text" name="x" /> <input type="submit" value="delete" name="del"/> </form>
php:
<?php $connection = mysql_connect("localhost","root","") or die ("couldn't connect server"); $db = mysql_select_db("smap", $connection) or die ("couldn't select database"); if(isset($_post['del'])) { $a = $_post['x']; $sql = mysql_query("delete syracuseone id ='$a'";) if(mysql_query($sql)) { echo "deleted"; } else { echo "fail"; } } ?>
i error:
notice: undefined index: x
any assistance stack?
it means post value not passed next page, can $a = isset($_post['x']) ? $_post["a"] : 0;
take look, here it's usage:
<form method="post" action="" > id<input type="text" name="x" /> <input type="submit" value="delete" name="del"/> </form> <?php $connection = mysql_connect("localhost", "root", "") or die("couldn't connect server"); $db = mysql_select_db("smap", $connection) or die("couldn't select database"); if(isset($_post['del'])){ $a = isset($_post['x']) ? $_post["a"] : 0; $sql = mysql_query("delete syracuseone id ='$a'"); if(mysql_query($sql)){ echo "deleted"; }else{ echo "fail"; } } ?>
Comments
Post a Comment