1

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']) . "')";


?>
sammy
  • 717
  • 4
  • 13

1 Answers1

3

You did not execute the SQL query for delete.

Corrected code:

 $ins = "DELETE FROM job_list 
     where job_id='" . mysql_escape_string($_POST['delete']) . "'";
$dbresult=mysql_query($ins,$con);

Note: Don't use mysql_* functions, they are deprecated and will be removed in future PHP versions. Use mysqli_ or PDO.

Pupil
  • 23,834
  • 6
  • 44
  • 66
  • how can i translate mysql to mysqli? – sammy Nov 04 '15 at 10:24
  • 1
    @sajad I have already done that example with mysqli to you man, if you read my previous answer it says exactly the same – Maytham Fahmi Nov 04 '15 at 11:12
  • @maytham-ɯɐɥıλɐɯ: sorry man, u r right, but i need to work further for using of sqli and forget sql for ever :p – sammy Nov 04 '15 at 14:22
  • 1
    @sajad all of us trying to help you man doing the right thing, good luck dude – Maytham Fahmi Nov 04 '15 at 14:24
  • @maytham-ɯɐɥıλɐɯ realy thanks :) i have another question. when i send information to a table, returns null. im crating a post about this problem, wish u help me... – sammy Nov 04 '15 at 14:44
  • can you take a look here: http://stackoverflow.com/questions/33550554/insert-to-all-cells-when-records-are-more-than-one-php – sammy Nov 06 '15 at 07:48