doddsey_65 Posted May 7, 2010 Share Posted May 7, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/201001-add-as-favorite/ Share on other sites More sharing options...
siric Posted May 7, 2010 Share Posted May 7, 2010 try this $qry = "INSERT INTO favorites (username, tutorialid, tutorialname, tutorialauthor) VALUES ('$loiginusername', '$row->id', '$row->name', '$row->fullname')"; Might I also assume that you have spelt $loiginusername incorrectly? Quote Link to comment https://forums.phpfreaks.com/topic/201001-add-as-favorite/#findComment-1054576 Share on other sites More sharing options...
doddsey_65 Posted May 7, 2010 Author Share Posted May 7, 2010 i have done what you said, and yes it was spelled incorectly so i have changed it but still nothing is giong into the database. Quote Link to comment https://forums.phpfreaks.com/topic/201001-add-as-favorite/#findComment-1054583 Share on other sites More sharing options...
doddsey_65 Posted May 7, 2010 Author Share Posted May 7, 2010 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); } Quote Link to comment https://forums.phpfreaks.com/topic/201001-add-as-favorite/#findComment-1054614 Share on other sites More sharing options...
cs.punk Posted May 7, 2010 Share Posted May 7, 2010 Check for errors on mysql. Or echo your query. $add_fav = mysql_query($qry) or die("$qry" . mysql($con)) ; Quote Link to comment https://forums.phpfreaks.com/topic/201001-add-as-favorite/#findComment-1054623 Share on other sites More sharing options...
doddsey_65 Posted May 7, 2010 Author Share Posted May 7, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/201001-add-as-favorite/#findComment-1054625 Share on other sites More sharing options...
cs.punk Posted May 7, 2010 Share Posted May 7, 2010 What does your query echo? And do you have error reporting on? Your saying the query works in phpmyadmin but not in your script? Quote Link to comment https://forums.phpfreaks.com/topic/201001-add-as-favorite/#findComment-1054631 Share on other sites More sharing options...
doddsey_65 Posted May 7, 2010 Author Share Posted May 7, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201001-add-as-favorite/#findComment-1054634 Share on other sites More sharing options...
doddsey_65 Posted May 7, 2010 Author Share Posted May 7, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/201001-add-as-favorite/#findComment-1054653 Share on other sites More sharing options...
doddsey_65 Posted May 7, 2010 Author Share Posted May 7, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/201001-add-as-favorite/#findComment-1054702 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.