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


?>

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

how can i translate mysql to mysqli?
@sajad I have already done that example with mysqli to you man, if you read my previous answer it says exactly the same
@maytham-ɯɐɥıλɐɯ: sorry man, u r right, but i need to work further for using of sqli and forget sql for ever :p
@sajad all of us trying to help you man doing the right thing, good luck dude
@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...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.