Hi,
As part of my cleaning up I have started to put data from one table into many. The problem I have now is trying to create a 'relationship' between them. In the example below I am trying to upload an image and store the data in a table - supplierimages. The table shares username with the suppliers table which contains all the other user data.
From this code you will see that what I am trying to do is create a relationship by getting the username and image1 from the suppliers table (although image1 will be taken out and exist in only the supplierimages table) process the form and then update the supplierimages table with the username and image1:
$id = $_SESSION['username'];
echo $id;
$query = "select username, image1 from suppliers where username='$id'";
$result=mysql_query($query, $link) or die("MySQL query $query failed. Error if any: ".mysql_error());
echo $query;
//get the first (and only) row from the result
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$username=$row['username'];
$image1 = $row['image1'];
In this middle part I do some processing which works fine, now I need to update the supplierimages table with the details:
$query = "UPDATE `supplierimages`
SET `image1` = '$image1', `username` = '$username' WHERE `username` = '". mysql_real_escape_string($_SESSION['username']). "'
LIMIT 1";
$result = mysql_query($query, $link) or die('Update failed: ' . mysql_error());
echo $query;
//print_r($query);
mysql_info($link) ;
if(mysql_affected_rows($link) == 0);
}
}
else {
I hope that this gives you an idea of what I am trying to do, at the moment the second query isnt working, perhaps I need to create some kinf of join on the first one?