bytesize Posted November 29, 2010 Share Posted November 29, 2010 Can someone please help me figure out how to insert "image" from table users, that contains the .jpg data associated with "screen_name", into table friends "friendimg" Here are the tables: friends: id, member, friendwith, friendimg users: id, screen_name, image $_GET["id"] only contains "screen_name" and"image" is not included add.php <?php if(isset($_GET["id"])) { echo "<br/><a href=\"member?add=".$_GET["id"]."\">Add ".$_GET["id"]." to your list of friends</a>"; } ?> member.php <?php if(isset($_GET["add"])) { $username = $_SESSION["screen_name"]; $friend = $_GET["add"]; $query = "SELECT * FROM friends WHERE member='$username' AND friendwith='$friend'"; $result = mysql_query($query); $exist = mysql_num_rows($result); if($exist=='0') { $query = "INSERT INTO friends(member,friendwith) VALUES('$username','$friend')"; mysql_query($query); echo "<br/>You are now friends with $friend"; } else { echo "<br/>$friend is already in your list of friends!"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/220167-need-help-inserting-data/ Share on other sites More sharing options...
jdavidbakr Posted November 29, 2010 Share Posted November 29, 2010 Why do you want to do that? It would make more sense to do a join instead of storing the same data in two tables. Quote Link to comment https://forums.phpfreaks.com/topic/220167-need-help-inserting-data/#findComment-1141068 Share on other sites More sharing options...
QuickOldCar Posted November 29, 2010 Share Posted November 29, 2010 I was going to say the same, also the way this is doing it, you would have to also include an insert, or else update because the original user could change their image then the other friends image would be incorrect. Just call to the friends users table by their name and get the image to display, because going by id for for tables they are different, but the names should remain the same. Quote Link to comment https://forums.phpfreaks.com/topic/220167-need-help-inserting-data/#findComment-1141072 Share on other sites More sharing options...
bytesize Posted November 29, 2010 Author Share Posted November 29, 2010 I will try joining the tables and see what happens. Thank you for the input. Quote Link to comment https://forums.phpfreaks.com/topic/220167-need-help-inserting-data/#findComment-1141080 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.