Jump to content

Need help inserting data


bytesize

Recommended Posts

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!";
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/220167-need-help-inserting-data/
Share on other sites

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.

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.