Hi, I need to make a script so members of my can post 'gifts' to other people's profiles. Like facebook does. I am kind of stuck on how to do this. I was going to use php and sql. Maybe have the images in the database and when one type og image is selected in will be posted ito the members profile. Has any1 got a clue on how to do this. ?
Make two tables. 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 Then to give someone a gift. INSERT INTO giftlog (giftid, recipientid, fromid) VALUES (" . $giftid . ", " . $recipientid . ", " . $userid . ") Code (sql): Get gifts for a specific user. SELECT giftlog.name, girtlog.image FROM giftlog LEFT JOIN gifs USING (giftid) WHERE giftlog.recipientid = " . $userid Code (sql): Untested but you get the idea.
Have a folder in images [gifts] Have a database for gifts [db_gifts] , with a unique id, gift name, and image loacation (refer to > [gifts]) When a user sends a gift it picks from a list (each with an id corresponding to [db_gifts] id's). This will bring up the correct image. EDIT: Bah, i was too late! lol
eeek. OK im not sure about how to implement this. So in short im making the table in SQL - what code do i put on the page to let the user select and send ? Big thanks so far.
nico_swd : I have made those table now i need to put the code onto the page. Do i just copy the sql code on ? Im really not sure of this one ? Any help good ta.
As you are a beginner with MySQL and PHP I recommend you try starting on a smaller project. http://www.tizag.com/ have some great PHP tutorials
I don't want to sound cocky, but I can't code the entire script for you. But I'll point you in the right direction. First, you have to add gifts to the table. Then you have to make a page which loops though this table and displays the photos along with a link which passes the current ID of the gift to another page (or to itself) Info regarding this here: www.php.net/mysql_fetch_array Users have to be logged in at this point. Once the user clicks a link, the gift ID is passed to this page, and adds a row to the database (query in first post). The gift ID, the recipients user ID and the current user ID will be inserted. Running queries: www.php.net/mysql_query You might not need this if you do it with links alone, however, if you're interedted: Dealing with forms: http://www.php.net/tutorial.forms
Hmm kinda understand...I will have a play and see what happens. I really dont know mucho about MySQL.....Should be interesting.
So far..... I get how to post to the database...But i cant display what's in the first 'gifts' table ...Any1 got any help. ?
Raw example $query = mysql_query("SELECT * FROM gifts") OR die(mysql_error()); while ($gift = mysql_fetch_array($query)) { echo $gift['name']; echo $gift['image']; } PHP:
Ok so i have inserted that, but it shows nothing...is this ok....I think im going to have to pay someone to do this... <?php $query = mysql_query("SELECT * FROM gifts") OR die(mysql_error());while ($gift = mysql_fetch_array($query)){ echo $gift['name']; echo $gift['image'];} ?> PHP:
Why did you put the whole code into a single line? And the field names are case-sensitive. In $gift['name'], the "name" has to be exactly the same as in your database field.
Fixed it....OK thanks, that is displaying the image. NOW....Do i make a form that will post this into the second table --Gift log.
nico_swd : I can now add to my database thanks. First part is done. Next part: This is the code im using to view the 'gifts' the members have been sent. However it displays an error. Any suggestions. <?php $query = "SELECT giftlog.name, giftlog.image". "FROM giftlog". "LEFT JOIN gifts" "USING (giftid)" "WHERE giftlog.recipientid = " . $userid"; ?> PHP:
There are no spaces where you split the string (why are you doing that anyway?) $query = " SELECT giftlog.name, giftlog.image FROM giftlog LEFT JOIN gifts USING (giftid) WHERE giftlog.recipientid = " . intval($userid); PHP: And also, for future reference, please always include the error messages to be able to give you more precise help.
Hi, Ok no error message now, just a blank screen -which is what is supposed to happen if there is not gift. No there is a problem i have added a gift to the tables but it does not show in the area where the code is ? Do i need to get it to display a result ?
FORM <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> HTML: (action=)gift.php <? require ("config.php"); include("functions.php"); // 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()); echo "Data Inserted!"; ?> PHP: View posted gifts <?php $query = " SELECT giftlog.name, giftlog.image FROM giftlog LEFT JOIN gifts USING (giftid) WHERE giftlog.recipientid = " . intval($userid); ?> PHP: [/PHP]