Greenbox Posted May 24, 2010 Share Posted May 24, 2010 Hi, im trying to make a code where you can send a friend invite to other members and be stored in a page called friends.php, i'm not the best coder but i think im getting alittle hang on it of anyone could help me out alittle then it would been great just ask if you need any information about the db, Thanks in advance <?php session_start(); include "includes/db_connect.php"; include "includes/functions.php"; $username=$_SESSION['username']; $query=mysql_query("SELECT * FROM users WHERE username='$username'"); $fetch=mysql_fetch_object($query); $inviter = mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$username'")); if (strip_tags($_POST['invite_button']) && strip_tags($_POST['invite_person'])){ $invite_person=strip_tags($_POST['invite_person']); if (strtolower($invite_person) == strtolower($username)){ echo "You cannot invite yourself"; }elseif (strtolower($invite_person) != strtolower($username)){ $invite_text="<form name=invite_friend method=post action=?accept=friends&id=$inviter->id> <div align=center>You have been invited to be $username s friend!<br> <input name=Decline type=submit id=Decline value=Decline> | <input name=Accept type=submit id=Accept value=Accept> </div> </form>"; mysql_query("INSERT INTO `inbox` ( `id` , `to` , `from` , `message` , `date` , `read` ) VALUES ( '', '$invite_person', '$invite_person', '$invite_text', '$date', '0' )"); mysql_query("UPDATE friend SET person ='$invite_person' WHERE id='$inviter->id'"); echo "Invite has been sent to <a href='profile.php?viewuser=$invite_person'><b>$invite_person</b></a>"; }} ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <div align="center"> <input name="invite_person" type="text" id="invite_person" /> <input name="invite_button" type="submit" id="invite_button" value="Invite" /> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/202745-invite-friend-code/ Share on other sites More sharing options...
Bladescope Posted May 24, 2010 Share Posted May 24, 2010 Can you clarify what problem you are getting? Quote Link to comment https://forums.phpfreaks.com/topic/202745-invite-friend-code/#findComment-1062736 Share on other sites More sharing options...
Greenbox Posted May 24, 2010 Author Share Posted May 24, 2010 Can you clarify what problem you are getting? when i push the invite button, nothing happends Quote Link to comment https://forums.phpfreaks.com/topic/202745-invite-friend-code/#findComment-1062760 Share on other sites More sharing options...
premiso Posted May 24, 2010 Share Posted May 24, 2010 <?php session_start(); include "includes/db_connect.php"; include "includes/functions.php"; $username=$_SESSION['username']; $query=mysql_query("SELECT * FROM users WHERE username='$username'"); $fetch=mysql_fetch_object($query); $inviter = mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$username'")); // if (strip_tags($_POST['invite_button']) && strip_tags($_POST['invite_person'])){ if (isset($_POST['invite_button']) && isset($_POST['invite_person)) { $invite_person=strip_tags($_POST['invite_person']); if (strtolower($invite_person) == strtolower($username)){ echo "You cannot invite yourself"; }elseif (strtolower($invite_person) != strtolower($username)){ $invite_text="<form name=invite_friend method=post action=?accept=friends&id=$inviter->id> <div align=center>You have been invited to be $username s friend!<br> <input name=Decline type=submit id=Decline value=Decline> | <input name=Accept type=submit id=Accept value=Accept> </div> </form>"; mysql_query("INSERT INTO `inbox` ( `id` , `to` , `from` , `message` , `date` , `read` ) VALUES ('', '$invite_person', '$invite_person', '$invite_text', '$date', '0')") or trigger_error("Mysql Update Inbox Failed: " . mysql_error()); mysql_query("UPDATE friend SET person ='$invite_person' WHERE id='$inviter->id'") or trigger_error("Mysql Update Failed Friend: " . mysql_error()); echo "Invite has been sent to <a href='profile.php?viewuser=$invite_person'><b>$invite_person</b></a>"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <div align="center"> <input name="invite_person" type="text" id="invite_person" /> <input name="invite_button" type="submit" id="invite_button" value="Invite" /> </div> </body> </html> A. Use proper indentiation. Makes code easier to read. B. checking for "strip_tags" of a field is not correct, as all that has to do is strip the tags, which will normaly always return true. Better to check isset to see if the variable has been set. C. Added error checking so you can see if the queries are failing for some reason. The above "should work" or at least return a helpful error. Quote Link to comment https://forums.phpfreaks.com/topic/202745-invite-friend-code/#findComment-1062788 Share on other sites More sharing options...
Greenbox Posted May 25, 2010 Author Share Posted May 25, 2010 Parse error: syntax error, unexpected T_STRING, expecting ']' in /home7/greenbox/public_html/MafiaLegacy/addfriend.php on line 14 Thanks for your reply it was very helpfull but i got this error when i tried it out Quote Link to comment https://forums.phpfreaks.com/topic/202745-invite-friend-code/#findComment-1062816 Share on other sites More sharing options...
premiso Posted May 25, 2010 Share Posted May 25, 2010 And you could not work out what the problem was? if (isset($_POST['invite_button']) && isset($_POST['invite_person'])) { It was a typo missing the '] after the invite_person. Quote Link to comment https://forums.phpfreaks.com/topic/202745-invite-friend-code/#findComment-1062829 Share on other sites More sharing options...
Greenbox Posted May 25, 2010 Author Share Posted May 25, 2010 Ok, the addfriend page is finished i think.. but how i can make it so when the user that have been invited goes into his inbox and click the accept button it updates the db field and add id, username, person? anyone who could tech me how i can do it? thanks <?php session_start(); include "includes/db_connect.php"; include "includes/functions.php"; $username=$_SESSION['username']; $query=mysql_query("SELECT * FROM users WHERE username='$username'"); $fetch=mysql_fetch_object($query); $inviter = mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$username'")); // if (strip_tags($_POST['invite_button']) && strip_tags($_POST['invite_person'])){ if (isset($_POST['invite_button']) && isset($_POST['invite_person'])) { $invite_person=strip_tags($_POST['invite_person']); if (strtolower($invite_person) == strtolower($username)){ echo "You cannot invite yourself"; }elseif (strtolower($invite_person) != strtolower($username)){ $invite_title="You have a friend invitation"; $invite_text="<form name=invite_friend method=post action=?accept=friends&friends_id=$inviter->id> <div align=center>You have been invited to be $username s friend!<br> <input name='Decline' type='submit' id='Decline' value='Decline'> | <input name='Accept_friend' type='submit' id='Accept' value='Accept'> </div> </form>"; mysql_query("INSERT INTO `inbox` ( `id` , `to` , `title` , `from` , `message` , `date` , `read` ) VALUES ('', '$invite_person', '$invite_title', '$invite_person', '$invite_text', '$date', '0')") or trigger_error("Mysql Update Inbox Failed: " . mysql_error()); mysql_query("UPDATE friends SET person ='$invite_person' WHERE id='$inviter->id'") or trigger_error("Mysql Update Failed Friend: " . mysql_error()); echo "Invite has been sent to <a href='profile.php?viewuser=$invite_person'><b>$invite_person</b></a>"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>add friend</title> </head> <body> <div align="center"> <form name="form1" method="post" action=""> <input name="invite_person" type="text" id="invite_person" /> <input name="invite_button" type="submit" id="invite_button" value="Invite" /> </form> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/202745-invite-friend-code/#findComment-1063000 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.