leequalls Posted December 26, 2009 Share Posted December 26, 2009 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 More sharing options...
trq Posted December 26, 2009 Share Posted December 26, 2009 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 More sharing options...
leequalls Posted December 26, 2009 Author Share Posted December 26, 2009 ok I found the problem in the sql the del_name I am trying to delete is "Eating Your Feelings" with Party Mixologist Josephine the quotes are throwing off the script how would I fix this Link to comment https://forums.phpfreaks.com/topic/186362-php-or-sql/#findComment-984154 Share on other sites More sharing options...
trq Posted December 26, 2009 Share Posted December 26, 2009 You need to escape your data. Take a look at mysql_real_escape_string. Link to comment https://forums.phpfreaks.com/topic/186362-php-or-sql/#findComment-984159 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.