RyanSF07 Posted May 7, 2009 Share Posted May 7, 2009 Hi All, I'm trying to pass the correct "id" to a delete function. The sql query taps into two tables. The while clause is followed by a resize-image function. I was thinking that I could use the while clause to find and pass the links-table id, however, the users-table id is passed instead here: delete_link.php?delete_link_id=$info[id] I've placed the code that I have below -- trimmed it down some. I left the resize-image function in there as I think my problem is happening after the while clause. Anyhow -- I'm looking for help passing the correct info[id] to the delete function. Thank you for your suggestions! $content2 .= " <br><h2>Link:</h2>"; $data = mysql_query("SELECT * FROM links, registered_users WHERE links.user_id = registered_users.id AND links.user_id = $_SESSION[user_id] ORDER BY link_website_title ASC") or die(mysql_error()); function imageResize($width, $height, $target) { if ($width > $height) { $percentage = ($target / $width); } else { $percentage = $height == 0? 0 : $target / $height; } $width = round($width * $percentage); $height = round($height * $percentage); return "width=\"$width\" height=\"$height\""; } while($info = mysql_fetch_array( $data )) { $resized= getimagesize("link_images/". $info['photo']); $content3 .= " <p><b>".$info['link_website_title'] . " </b> " . "<a href = \"edit_link.php?link_id=$info[id]\">[Edit]</a> <a href = \"delete_link.php?delete_link_id=$info[id]\" onClick=\"return confirm('Are you sure you want to delete this link completely? This action cannot be undone.');\">[Delete]</a><br>" . "<img src='http://www.website.com/link_images/". $info['photo'] ."' " . imageResize($resized[0], $resized[1], 100) ."></a><br>" . "<b>".$info['link_website_description'] . " </b>" . "<b><a href = ".$info['link_website_url'] . " target='_blank'>".$info['link_website_url'] . "</b></a></p>"; $_SESSION[get] = $_GET[link_id]; } if ($_GET[delete_link_id]) { $sql = "DELETE FROM links WHERE links.id = '$_GET[delete_link_id]'"; if (mysql_query($sql)) { $content .= "<h2>The link has been deleted</h2>"; } else { $content .= "<p>The quiz could not be deleted.</p>"; } } } Link to comment https://forums.phpfreaks.com/topic/157251-solved-help-passing-correct-id-from-two-tables-to-a-delete-function/ Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Use string concatenation instead. So your SQL should along the lines of: $data = "SELECT ... AND links.user_id = '" . $_SESSION['user_id'] . "' ..."; I am going to stop teaching people to use those tacky braces because more problems will just arise. People, learn string concatenation in SQLs! Link to comment https://forums.phpfreaks.com/topic/157251-solved-help-passing-correct-id-from-two-tables-to-a-delete-function/#findComment-828632 Share on other sites More sharing options...
RyanSF07 Posted May 7, 2009 Author Share Posted May 7, 2009 Thanks, Ken. The primary key id from the User's table is still passed rather than the primary key id from the Link's table. Still working at it... Ryan Link to comment https://forums.phpfreaks.com/topic/157251-solved-help-passing-correct-id-from-two-tables-to-a-delete-function/#findComment-828646 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 SELECT links.id ... FROM ... Link to comment https://forums.phpfreaks.com/topic/157251-solved-help-passing-correct-id-from-two-tables-to-a-delete-function/#findComment-828651 Share on other sites More sharing options...
RyanSF07 Posted May 7, 2009 Author Share Posted May 7, 2009 Thank you, Ken. The correct id is now being passed. The trouble i'm having now is that the record is not actually being deleted. I changed the $sql variable in the delete function to $data (didn't know if that would make a difference, apparently it didn't : ) Please let me know if you have any ideas as to why the record isn't being deleted. Thank you again for the help with the sql query! this worked: $data = mysql_query("SELECT links.id, links.link_website_title, links.link_website_url, links.link_website_description, links.photo, first_name, last_name, DATE_FORMAT(date, '%M %D, %Y') as date FROM links, registered_users WHERE links.user_id = registered_users.id AND links.user_id = '" . $_SESSION['user_id'] . "' ORDER BY link_website_title ASC") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/157251-solved-help-passing-correct-id-from-two-tables-to-a-delete-function/#findComment-828662 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.