![]() |
MySql Add to favorites - almost functional - help
Hello talkphp members,
I am very very new to php and mysql, and i have a problem. Problem: I am buiding a simple embedd youtube-link site (school project) and i cant get my "add to favorites"-php to throw any values into my database. In my opinion the php below should work, i cant find any errors and i am completely blinded by now - why wont this work? Additional things you need to know:
There was a point in time where this worked. please help me.:'-( ------------------------------------------------------------ print "<div class='video_post_bottom'>";//BOTTOM print "<div class='favorit'><form action='Main4.php' method='post' class='favorites'><input type='image' src='Images/Favorites.png' name='FAV' value=''/><input type='hidden' name='FAV_Id' value='$Id'></form></div>"; //"Favorites" - BUTTON //ADD TO FAVORITES if (isset($_POST['FAV'])) { print"<p>isset _POSTFAV</p>"; $Video_Id = $_POST['FAV_Id']; $query7 ="SELECT * FROM Favorites WHERE '$Video_Id' = Favorites.Video_Id AND '$Current_Id' = User_Id"; $result_C = mysql_query($query7); print"<p>SELECT * FROM FAVORITES</p>"; while ($row7 = mysql_fetch_array($result_C)) { $favorite = $row7['Video_Id']; print"<p>favorite = row7Video_Id</p>"; } If(!$favorite)//not favorite yet? { $query = "INSERT INTO Favorites (User_Id, Video_Id) VALUES ('$Current_Id', '$Video_Id ')"; print"<p>INSERT INTO Favorites</p>"; $result_C = mysql_query($query); print "<p> $Title has been added to your favorites</p>"; unset($_POST['FAV']); } else if($favorite && $Video_Id == $Id) //if voted has value { print "<p> THIS IS ALREADY IN YOUR FAVOURITES </p>"; } } print"<div class='comments'><a href='../Comment/Comment.php?V_Id=$Id'><img src='Images/Comments.png'></a></div>";//COMMENTS print "</div>"; |
Can't completely debug this for you as it appears to me to be incomplete code (there are some values that don't have any assignments associated with them), but here's how I would rewrite it leaving your variable naming conventions in place.
The queries look okay, except for the fact that none of the data can be trusted. You forgot to escape the user based input coming from POST, and there are no checks to ensure the integrity or type of data being put back into the database. All this could be used to easily attack and manipulate your database server were this script to be on a live site. There's a few other tips in the comments. Take a peek and see if it helps you get it back up and running; php Code:
|
| All times are GMT. The time now is 05:55 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0