Jump to content

Add as favorite


doddsey_65

Recommended Posts

Im trying to set up an add as favorite link on my tutorials. When the link is clicked it sends the name of the tutorial and the users username to a database table called favorites. The only problem is that its not sending anything to the database. Here is the insert query:

 

 if (isset($_POST['fav'])) {

$qry = "INSERT INTO favorites (username, tutorialid, tutorialname, tutorialauthor)
				VALUES ('".$loiginusername."', '".$row->id."', '".$row->name."', '".$row->fullname."')";

$add_fav = mysql_query($qry);
}

 

And here is the form:

 

echo '<form name="addfavorite" action="' . $_SERVER['PHP_SELF'] . '?id=' . $id . '" method="POST">';
		echo '<input type="image" src ="images/icons/fav.png" name="fav" />';
		echo '</form>';

 

How can i get this to work?

Link to comment
https://forums.phpfreaks.com/topic/201001-add-as-favorite/
Share on other sites

Okay i have changed it a little but its still not working. Heres the form:

 

echo '<table><tr><td style="padding: 5px;">';
		echo '<form name="fav" action="' . $_SERVER['PHP_SELF'] . '?id=' . $id . '" method="post">';
		echo '<input type="hidden" name="id" value="'.$id.'">';
		echo '<input type="hidden" name="name" value="'.$row->name.'">';
		echo '<input type="hidden" name="fullname" value="'.$row->fullname.'">';
		echo '<input type="image" src ="images/icons/fav.png" name="fav" />';
		echo '</form>';

And heres the php:

 

 if (isset($_POST['fav'])) {

$qry = "INSERT INTO favorites (username, tutorialid, tutorialname, tutorialauthor)					
VALUES ('$loginusername', '".$_POST['id']."', '".$_POST['name']."', '".$_POST['fullname']."')";

$add_fav = mysql_query($qry);

}

Link to comment
https://forums.phpfreaks.com/topic/201001-add-as-favorite/#findComment-1054614
Share on other sites

Okay i figured out the problem but i dont know why its a problem. Its this bit:

 

<input type="image" src ="images/icons/fav.png" name="fav" />

 

If i just use the standard submit button it works fine.

 

<input type="submit" value=Favorite" name="fav" />

 

So how is this not working with an image?

Link to comment
https://forums.phpfreaks.com/topic/201001-add-as-favorite/#findComment-1054653
Share on other sites

from what i have seen the name attribute is not used when using an image as the submit button. The codes i have seen divert you to a different page via form action. But i want to stay on the same page. I just dont know how to work around this. Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/201001-add-as-favorite/#findComment-1054702
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.