Jump to content

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

i get no errors and when i echo the query everything is as it should be. I even copied the echoed query and used it in phpmyadmin and it added the data. Could it be because i dont have any inputs in the form because they are all just hidden?

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

how do i activate error reporting?

 

the query echos the right values and when i insert the echoed query into phpmyadmin it inserts the values correctly, however the query in the script doesnt work. No values get added to the database.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.