Jump to content

php or sql?


leequalls

Recommended Posts

Sorry not sure if this is a sql problem or php the following code is supposed to delete data from the sql. However when I click delete nothing happens.

 

<center>


<b><u>Delete A Profile</u></b><p>
<form method='POST' action='deleteprofile.php'>

<?php
session_start();
if ($_POST['del_name']) {
$del_name=$_POST['del_name'];
$query = mysql_query("SELECT * FROM rp_staff WHERE name = '$del_name'");
$image = mysql_result($query, 0, "image");
if($image != "") {
$file = "/home/party/public_html/en/images/$image";
if (file_exists($file)) { unlink($file); $imagegone = "The profile image $image has been removed";  }
}
$result = mysql_query("DELETE FROM rp_staff WHERE name = '$del_name'");
echo "<center><h1><b>The profile of $del_name has been successfully deleted.</h1><p>";
if($imagegone != "") { echo "<h1><b>$imagegone</h1><p>";}
session_unregister ('del_name');
}
?>

<?php
    $result = mysql_query("SELECT name FROM rp_staff ORDER BY name ASC");
    echo '<select name="del_name">';
    while($row = mysql_fetch_assoc($result))
    {
        echo '<option value="' . $row['name'] . '">' . $row['name'] . '</option>';
    }
    echo '</select>';
?>
<p><input type="submit" name="submit" value="Delete">
</form>


</center>

Link to comment
https://forums.phpfreaks.com/topic/186362-php-or-sql/
Share on other sites

Firstly, have you heard of indenting code so it is readable?

 

Next, you need to actually debug what the problem is. At the very least something like....

 

$sql = "DELETE FROM rp_staff WHERE name = '$del_name'";
if ($result = mysql_query($sql)) {
  // rest of code
} else {
  echo mysql_error() . "<br />$sql";
}

 

Notice also that I moved your query into a variable? This is so that if there is an error you will be able to see the actual query that your database is receiving.

Link to comment
https://forums.phpfreaks.com/topic/186362-php-or-sql/#findComment-984151
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.