The code that you have posted is not enough enough to get the job done. Have you posted all of the code ? You are missing some basic elements such as getting the posted data from your form and putting it into the query, and also code for displaying the gifts in the last query that you have posted. I would suggest you read more tutorials on how to do this, or place a request for someone to write this for you in the services forum. Brew
Still cant get this to work..Im must be missing something...I can insert data fine, but when i send a 'gift' it does not show in the members area, I dont get a error - its just a blank page.
Hi this is the code im using to try and find the gifts for the specific member- <?php $result = mysql_query("SELECT 'giftlog'.'name' AS name, 'giftlog'.'image' AS image FROM 'giftlog' LEFT JOIN 'gifts' ON 'giftlog'.'giftid' = 'gifts'.'giftid' WHERE 'giftlog'.'recipientid' = " . $userid); echo $row['$name']; echo $row['$image']; ?> PHP:
Try this: $result = mysql_query("SELECT 'giftlog'.'name' AS name, 'giftlog'.'image' AS image FROM 'giftlog' LEFT JOIN 'gifts' ON 'giftlog'.'giftid' = 'gifts'.'giftid' WHERE 'giftlog'.'recipientid' = " . $userid); while ($row = mysql_fetch_assoc($result)) { echo $row['name']; echo $row['image']; } PHP: Brew
I get this - Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in mygifts.php on line 8
Ok removed all quotes. - Get same error. I dont have a column called $userid I have just made the tables like you said - One called gitfs, with 3 fields. - Giftid - Name - Image And another one called giftlog or something like that, with 4 fields. - Logid - Giftid - Recipientid - Fromid
Are you using mysql_connect to connect to the database ? You havent got this in the code you posted, but I just want to rule out the obvious. Brew
Im slightly confused about the- $userid I do not have this in the table. (I dont think im supposed to.) Does this help: // Insert a row of information into the table "giftlog" mysql_query("INSERT INTO giftlog (Giftid, Recipientid,Fromid) VALUES('$giftid', '$recipientid', '$userid' ) ") or die(mysql_error()); PHP:
On the page where you are displaying the gifts, the variable $userid needs to contain the id of the user that the gifts belong to. Are you populating this variable ? If not, that is where the problem lies. Brew
Brew: your a big help. Thanks in advance. <form action="gift.php" method="post"> <input type="text" name="giftid" value="$name"> <input type="text" name="recipientid" value="$recipientid"> <input type="text" name="userid" value="$userid"> <input type="submit" name="Submit" value="Submit" class="mybutton"> </form> <?php $query = mysql_query("SELECT * FROM gifts") OR die(mysql_error()); while ($gift = mysql_fetch_array($query)) { echo $gift['Name']; echo $gift['Image']; } ?>
Hi again I meant the page that had your code that looks something like this: $result = mysql_query("SELECT giftlog.name AS name, giftlog.image AS image FROM giftlog LEFT JOIN gifts ON giftlog.giftid = gifts.giftid WHERE giftlog.recipientid=" . $userid); while ($row = mysql_fetch_assoc($result)) { echo $row['name']; echo $row['image']; } PHP: The variable $userid needs to have a value, otherwise nothing will get displayed. Try this: $userid = (int)GET['userid']; $result = mysql_query("SELECT giftlog.name AS name, giftlog.image AS image FROM giftlog LEFT JOIN gifts ON giftlog.giftid = gifts.giftid WHERE giftlog.recipientid=" . $userid); while ($row = mysql_fetch_assoc($result)) { echo $row['name']; echo $row['image']; } PHP: Then call the page like this {name of page}.php?userid=13 - use a value that is in your database here. Understand ? Brew
This is the code that you wanted btw $result = mysql_query("SELECT 'giftlog'.'name' AS name, 'giftlog'.'image' AS image FROM 'giftlog' LEFT JOIN 'gifts' ON 'giftlog'.'giftid' = 'gifts'.'giftid' WHERE 'giftlog'.'recipientid' = " . $userid); while ($row = mysql_fetch_assoc($result)) { echo $row['Name']; echo $row['Image']; }