delete a row of data base PHP SQL

Wednesday, November 4, 2015

im trying to delete a row of my database table from a drop down list. but do not act, also there is no errors.




this is how i create new jobs, and that works property.




<p>
<label for="textfield">شغل جدید</label>
<input type="text" name="textfield" id="textfield" />
<label for="Submit"></label>
<input type="submit" name="Submit" value="Submit" id="Submit" />
</p>
</form>



end of creating new jobs with sending contents to admin_send_ job.php.



here i fetch jobs list from table job_list. my problem starts here:



this is how i need to delete a job




  <form name="form2" method="post" action="delete.php" > 
<?php

$db_host = 'localhost';
$db_name= 'site';
$db_table= 'job_list';
$db_user = 'root';
$db_pass = '';




$con = mysql_connect($db_host,$db_user,$db_pass) or die("خطا در اتصال به پايگاه داده");

mysql_query("SET NAMES 'utf8'", $con);
mysql_query("SET CHARACTER SET 'utf8'", $con);
mysql_query("SET character_set_connection = 'utf8'", $con);

$selected=mysql_select_db($db_name, $con) or die("خطا در انتخاب پايگاه داده");
mysql_query("SET CHARACTER SET utf8");
$dbresult=mysql_query("SELECT * FROM $db_table",$con);
echo "شغلی که می خواهید حذف کنید انتخاب نمایید: ";
echo '<br/>';

echo '<select name="delete">';

while($amch=mysql_fetch_assoc($dbresult))
{
echo '<option value="'.$amch['job_id'].'">'.$amch['job_name'].'</option>';
}
echo '</select>'; ?> <br/>
<input name="submit2" type="submit" value="submit2" />

</form>



and this is delete.php. that must delete selected value of drop down list, but no think appear. with no errors!




<?php
$db_host = 'localhost';
$db_name= 'site';
$db_table= 'job_list';
$db_user = 'root';
$db_pass = '';


$con = mysql_connect($db_host,$db_user,$db_pass) or die("خطا در اتصال به پايگاه داده");

mysql_query("SET NAMES 'utf8'", $con);
mysql_query("SET CHARACTER SET 'utf8'", $con);
mysql_query("SET character_set_connection = 'utf8'", $con);

$selected=mysql_select_db($db_name, $con) or die("خطا در انتخاب پايگاه داده");
$ins = "DELETE FROM job_list
where job_id='" . mysql_escape_string($_POST['delete']) . "'";
echo "('" . mysql_escape_string($_POST['delete']) . "')";


?>

0 comments:

Post a Comment