Jump to content

[SOLVED] help passing correct "id" from two tables to a delete function


RyanSF07

Recommended Posts

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>";
}

}

}

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!

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());

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.