Jump to content

[SOLVED] POST & GET help


jamesxg1

Recommended Posts

hiya,

 

i have a php script called profile.php basically when your viewing a users profile it will look like this profile.php?username=PERSONS USERNAME but what i need to do is post the username that is at the end of the url what ever it may be and display it on another page in a text box how do i do this ?

Link to comment
https://forums.phpfreaks.com/topic/143790-solved-post-get-help/
Share on other sites

$_GET['username'];

 

or you can set it as a variable.

 

$username = $_GET['username'];

 

Iv tryed it doesnt work :(,

 

all i need it to do is post what ever is at the end of the url eg. profile.php?username=JAMES

 

so it will post JAMES

 

to what ever page i use the GET on and then i can display it in a text box

 

Any ideas  ?

Link to comment
https://forums.phpfreaks.com/topic/143790-solved-post-get-help/#findComment-754467
Share on other sites

Ok heres the code

 

Profile.php

<?php session_start(); 

require("../db/db.php"); //include database file
require("../db/config.php"); //include configuration file
require("../db/util.php");
require("../db/settings.php");

isloggedin();
accessneeded("C");

?>
<?php
$username = $_POST['username'];
?>
<?php
$id = mysql_real_escape_string($_GET['id']);
$username = mysql_real_escape_string($_GET['username']);
$sql = "SELECT * FROM `users` WHERE `id`='$id' OR `username`='$username' LIMIT 1";
$query = mysql_query($sql);
if(mysql_num_rows($query) > 0){

//display content
while ($row = mysql_fetch_assoc($query)) {
$id = $row['id'];
$photo = $row['photo'];
$gender = $row['gender'];
$email = $row['email'];
$firstn = $row['firstname'];
$lastn = $row['lastname'];
$dobd = $row['dobDay'];
$dobm = $row['dobMonth'];
$doby = $row['dobYear'];
$username = $row['username'];
$music = $row['music'];
$movies = $row ['movies'];
$scaredof = $row['scaredof'];
$field1 = $row['field1'];
$field2 = $row['field2'];
$field3 = $row['field3'];
$field4 = $row['field4'];
$field5 = $row['field5'];
$fieldb1 = $row['fieldb1'];
$fieldb2 = $row['fieldb2'];
$tagline = $row['tagline'];

}
}else{
header('Location: ../main/profileerror.php');
}
?>
<html>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><?php print $title ?> - <?php print $firstn ?> <?php print $lastn ?>'s Profile</title>
<!-- Insert your commenting javascript code here -->

</head>
<script type="text/javascript" src="ajax_framework.js"></script>

<link rel="stylesheet" type="text/css" href="../main/jqueryslidemenu.css" />
<!--[if lte IE 7]>
<style type="text/css">
html .jqueryslidemenu{height: 1%;} /*Holly Hack for IE7 and below*/
</style>
<![endif]-->

<script type="text/javascript" src="../main/jquery.min.js"></script>
<script type="text/javascript" src="../main/jqueryslidemenu.js"></script>
<style type="text/css" media="all">
	body 			{ margin: 0px; font-family: tahoma, sans-serif; padding-bottom: 20px; background: #FFFFFF; font-size: 12px; color: #333333;}
	#Granny 		{ width: 900px; font-size: 0.88em; }
	a 			{ text-decoration: none; color: #0000FF; }
	a img 			{ border-width: 0px; }
	#HeaderCont 		{ clear: both; width: 100%; margin-top: 30px; background: #CCC; border: 1px solid #333; }
	#HeaderInn 		{ margin-bottom: 4px; padding: 5px 0px; text-align: left; font-family: Tahoma, sans-serif, sans-serif; }
	#HeaderTitle 		{ font-size: 3em; color: #000000; padding: 0px 40px; direction: ltr; text-align: left; }
	.TitleItemLink 		{ color: #000000; }
	#MainAndSides 		{ clear: both; width: 100%; margin-top: 15px; }
	#MainCol 		{ width: 73%; background: #F6F6F6; float: right; }
	#MainColInner 		{ padding: 10px 20px; border: 1px solid #000000; }
	.OnePost		{ border: 1px solid #000000; font-family: Tahoma, sans-serif, sans-serif; direction: ltr; background: #EEE; }
	.OnePost .TopPost	{ border-bottom: 1px solid #666; padding:  0px 20px 3px 20px; background: #CCC; }
	.OnePost .MidPost	{ padding: 15px 25px; }
	.OnePost .BotPost	{ border-top: 1px solid #666; padding: 3px 20px; background: #CCC; }
	.OnePost .FullWidth	{ width: 100%; }
	.DateHeaderPost		{ font-size: 1em; color: #000000; padding-top: 3px; text-align: right; width: 48%; float: right; }
	.TitleHeaderPost	{ font-size: 1em; font-weight: bold; color: #000000; padding-top: 3px; text-align: left; direction: ltr; width: 48%; float: left; }
	.TitleHeaderPost a	{ color: #000000; }
	.PostTextBody		{ font-size: 1em; color: #000000; text-align: left; line-height: 150%; }
	.CmntFooterPost		{ visibility: visible; font-size: 1em; color: #333; width: 48%; float: right; text-align: right; }
	.CmntFooterPost a	{ color: #333; }
	.PermFooterPost		{ font-size: 1em; font-style: italic; color: #333; width: 48%; float: left; text-align: left; }
	.PermFooterPost a	{ color: #333; }
	.Clearer		{ clear: both; width: 100%; font-size: 0px; height: 0px; }
	.PostSep		{ height: 20px; font-size: 1px }
	.PostSepS		{ height: 10px; margin-bottom: 10px; border-bottom: 1px solid #000000; font-size: 1px }
	.SideBar		{ background: #999; }
	.SideBarInner		{ padding: 15px 15px; border: 1px solid #000000; }
	.SideBarInner img	{ margin-top: 2px; }
	#SideLCol 		{ width: 25%; float: left; margin-right: 1.5%; }
	#SideLCol .Box 		{ background: #CCC; border: 1px solid #666; font-family: Tahoma, sans-serif, sans-serif; }
	#SideLCol .Sep 		{ height: 30px; }
	#SideLCol .SepS		{ height: 14.5px; margin-bottom: 14.5px; border-bottom: 1px solid #000000; font-size: 1px }
	#SideLCol .Title	{ font-size: 1em; color: #000000; font-weight: bold; border-bottom: 1px solid #333; margin-bottom: 3px; }
	#SideLCol .Inner	{ text-align: center; font-size: 1em; color: #333; padding: 5px 15px 8px 15px; line-height: 150%; }
	#commentInline		{ margin: 10px 20px; text-align: left; }
	.commentHead		{ margin: 0px 10px 20px 10px; padding-top: 5px; color: #333; }
	.comments-block		{ line-height: 150%; padding: 0px 30px; }
	.comment-poster		{ padding-bottom: 10px; }
	.comment-body		{ margin: 0px; padding-bottom: 10px; padding-left: 20px; }
	.innerCmntBody		{ margin: 5px 0px; }
	.comment-timestamp	{ margin: 5px 0px; padding: 0px 0px 8px 20px; color: #999; }
	.comment-timestamp a 	{ color: #666; }
	.deleted-comment	{ font-style: italic; color: gray; }
	#ColClose 		{ clear: both; width: 100%; font-size: 1px; height: 1px; margin-bottom: 20px; }
	#CopyRight 		{ width: 60%; border-top: 1px solid gray; padding-top: 10px; line-height: 150%; }
	/* This template generated by PsycHo [http://psyc.horm.org] on 1/26/2009. */
</style>
<div id="myslidemenu" class="jqueryslidemenu">

<!-- CSS -->
<link rel="stylesheet" href="../template/lightbox.css" media="screen,projection" type="text/css" />

<!-- JavaScript -->
<script type="text/javascript" src="../inc/gen/prototype.js"></script>
<script type="text/javascript" src="../inc/gen/lightbox.js"></script>


</head>
<ul>
<li><a href="../main/index.php">Home</a></li>
<li><a href="../messages/inbox.php">Mail <?php
	$sql = mysql_query ("SELECT pm_count FROM users WHERE username = '{$_SESSION['username']}'");
$row = mysql_fetch_array ($sql);
$pm_count = $row['pm_count'];
  ?>(<?php print "$pm_count" ?>)</a></li>
<li><a href="#">Profile</a>
  <ul>
  <li><a href="">View Profile</a></li>
  <li><a href="../main/editprofile.php">Edit Profile</a></li>
  <li><a href="../main/profilephotoupload.php">Profile Photo</a></li>
  <li><a href="#">Privacy Settings</a></li>
  </ul>
</li>
<li><a href="#">Items</a></li>
<li><a href="../friends/friends.php">Friends</a>
  <ul>
  <li><a href="#">Friend Requests</a></li>
  <li><a href="#">Invitation</a>
    </li>
    <li><a href="#">Invite Friends</a></li>
    </ul>
</li>
<li><a href="../login/logout.php">Sign Out</a></li>
<li><?php print ("<img src='../main/images/$photo' width='28' height='30'>"); ?></li>
</ul>
<br style="clear: left" />
</div>
<body><center>
<div id="Granny">
	<div id="HeaderCont"><div id="HeaderInn">
		<div class="Clearer"></div>

		<div id="HeaderTitle">
		<center><?php print $tagline ?><center>
		</div>
		<div class="Clearer"></div>
	</div></div>
	<div id="MainAndSides">
	<!-- ==================== Main Column ==================== -->
	<div id="MainCol">
		<div id="MainColInner">
			<Blogger>

			<div class="OnePost">
				<a name=""></a>
				<div class="TopPost"><div class="FullWidth">
					<div class="DateHeaderPost">

					</div>
					<div class="TitleHeaderPost">
Information:
					</div>
					<div class="Clearer"></div>
				</div></div>
				<div class="MidPost"><div class="FullWidth">
					<div class="PostTextBody">

<?php
print("<P ALIGN=CENTER><strong>$field1</strong><br>$music<br><strong>$field2</strong><br>$movies<br><strong>$field3</strong><br>$scaredof<br><strong>$field4</strong><br>$fieldb1<br><strong>$field5</strong><br>$fieldb2</p>"); ?>


					</div>
				</div></div>
				<div class="BotPost"><div class="FullWidth">

					<div class="PermFooterPost">

<strong>Profile Comments:</strong>
					</div>

					<div class="CmntFooterPost">
					<!-- Insert your external commenting service scripts here and remove the line below -->

					</div>
					<div class="Clearer"></div>
				</div></div>
			</div>
			<ItemPage>
				<div id="commentInline">
						<div class="commentHead"></div>									
</span>
<div id="insert_response" align=center></div>
<P ALIGN=CENTER>
<form action="javascript:insert()" method="post">
<input type="hidden" name="comto" value="<? echo $username ?>" id="comto">
<input type="hidden" name="comfrom" value="<? echo($_SESSION['username']); ?>" id="$comfrom">
Comment:
<br><textarea name="commen" cols="45" rows="5" wrap="VIRTUAL" id="$commen"></textarea>
<br>   
         <input type="submit" name="submit" value="Send">
</form></P>
<?php
$sql = "SELECT * FROM `comments` WHERE comto = '$username'";
$query = mysql_query($sql);
while ($row = mysql_fetch_assoc($query)) {
$from = $row['comfrom'];
$message = $row['commen'];
$too = $row['comto'];
$comid = $row['id'];
echo "<br/>\n";
print("<P ALIGN=CENTER><strong>$from</strong><br>$message</P>");
if($_SESSION['username'] == $too) {
print("<br><P ALIGN=RIGHT><a href='../main/DeleteComment.php?id=$comid'>Delete Comment</a></P>");
}
}
?>
<br>

				</div>
			</ItemPage>

			<div class="PostSep"><div class="PostSepS"></div></div>


		</div>
	</div>

	<!-- =================== Side L Column =================== -->
	<div id="SideLCol" class="SideBar">
		<div class="SideBarInner">
			<div class="Box">

				<div class="Inner">
				<div class="Title">Profile Image</div>
<?php print ("<img src='../main/images/$photo' width='150'>"); ?>



<br /> 
				</div>
<a href='../main/editprofile.php'>Edit Profile</a> | <a href='../main/profilephotoupload.php'>Profile Photo</a>


			</div>
			<div class="Clearer"></div>
		</div>


	<div class="Clearer"></div>
<div class="Clearer"></div>



		<div class="SideBarInner">
			<div class="Box">

				<div class="Inner">
				<div class="Title">Contact <?php print $firstn ?></div>
<a href="../messages/compose.php" class="lbOn">Send Message</a> || <a href="../friends/add.php">Add As Firend</a><br>
                              <a href="../main/blockfriend.php">Block User</a> || <a href="../main/reportusr.php">Report User</a>



<br /> 
				</div>
			</div>

		</div>
	</div>



	</div>

	<div id="ColClose"></div>
	<div id="CopyRight">


<br />

	<br />
	</div>
</div>
</center></body>
</html>

 

And this is the script i need to get the $username

 

Compose.php

<?php session_start(); 

require("../db/db.php"); //include database file
require("../db/config.php"); //include configuration file
require("../db/util.php");
require("../db/settings.php");

isloggedin();
accessneeded("C");

?>
<?php
$user = $_SESSION['username'];
$reciever = $_GET['username'];

    
    //This checks to see if a user is logged in or not by seeing if the sessioned username varialble exists.
//You could change this check to however you want to validate your members, this is just how I did it.
    if(!$user)
        {
        echo "<br><p>Blah blah you arent logged in and stuff, you should do that or something</p><br>";
        }
        
    else
        {
        //Query the database to see how many messages the logged in user has, then do a little math
	//Find the percentage that your inbox is full (message count divided by 50)
	//50 messages maximum, you can change that
	$sql = mysql_query ("SELECT pm_count FROM users WHERE username='$user'");
	$row = mysql_fetch_array ($sql);
	$pm_count = $row['pm_count'];

	//This is the math to figure out the percentage.
	//The message could divided by 50 then multiplied by 100 so we dont have a number less than 1
	$percent = $pm_count/'50';
	$percent = $percent * '100';
        ?>
        <br>
        <center>
        <b><p><a href="inbox.php">Inbox</a> | <a href="compose.php">Compose</a> | <a href="sent.php">Sentbox</a></b>
        <b><p><?php echo "$pm_count"." of 50 Total  |  "."$percent"."% full"; ?></p></b>
        </center>
        <br>
        <?php
        //So here we get the variable submitted through the form to this page
        $reciever = $_POST['username'];
        $subject = $_POST['subject'];
        $message = $_POST['message'];
        $error = '0';
        
        //If they are all blank we jsut say to compose a message
        if(!$reciever AND !$subject AND !$message)
            {
            ?>
            <p><b>Please compose a message.</b></p>
            <br>
            <?php
            }
        
        //Since this form was partially filled out we need to return an error message
        else
            {
            if (!$reciever)
                {
                $error = 'You must enter a reciever to your message';
                }
            
            if (!$subject)
                {
                $error = 'You must enter a subject';
                }
            
            if (!$message)
                {
                $error = 'You must enter a message';
                }
            
            //If the variable error is not set to zero, we have a problem and should show the error message
            if($error != '0')
                {
                echo "<p>$error</p><br>";
                }
            
            //There are no errors so far which means the form is completely filled out    
            else
                {
                //Are the trying to send a message to a real user or to something they just made up?
                $user_check = mysql_query("SELECT username FROM users WHERE username='$reciever'");
                $user_check = mysql_num_rows($user_check);
                
                //The user is real and not made up if this is true
                if($user_check > '0')
                    {
                    //There might already be a sessioned time variable, if so we need to get it for the flood check
                    $time = $_SESSION['time'];
                    
                    //If there is a time variable already, set it to the varialbe $old_time
                    if($time > '0')
                        {
                        $old_time = $time;
                        }
                    
                    //Here we get the minutes and seconds on the server time using the date function, and set that to the $time variable
                    //Now we find the difference between this time ($time) and the time that the page was submitted ($old_time)
                    $time = date('is');
                    $difference = $time - $old_time;
                    
                    $_SESSION['time'] = $time;
                    
                    //If the two times have a difference greater or equal to 15, which is 15 seconds, they can submit the message, this is for flood protection
                    if($difference >= '15')
                        {
                        //Get their private message count
                        $sql = mysql_query ("SELECT pm_count FROM users WHERE username='$reciever'");
                        $row = mysql_fetch_array ($sql);
                        $pm_count = $row['pm_count'];
                        
                        //You cant have more than 50 private messages, if they try sending a message to a user with a full inbox return an error message
                        if(pm_count == '50')
                            {
                            $error = 'The user you are trying to send a message to has 50 private messages, sorry but we cant send your message untill that user deletes some of their messages.';
                            }
                            
                        else
                            {    
                            //And now we stick the message in the database with all the correct information
                            mysql_query("INSERT INTO messages (reciever, sender, subject, message) VALUES('$reciever', '$user', '$subject', '$message')") or die (mysql_error());
						//Add 1 to the pm count, update the reciever with the new pm count
						$pm_count++;
						mysql_query("UPDATE users SET pm_count='$pm_count' WHERE username='$reciever'");
                            }
                            
                        //Let the user know everything went ok.
                        echo "<p><b>You have successfully sent a private message!</b></p><br>";
                        }
                    
                    //Since they are trying to send messages faster than every 15 seconds, give them an error message    
                    else
                        {
                        $error = 'You must wait 15 seconds before sending another private message';
                        }
                    }
                
                //If they mis spelled or, made up a username, then give an error message telling them its wrong.
                else
                    {
                    $error = 'That username does not exist, please try again. Remember to check your spelling, and don\'t make stuff up at random.';
                    }
                }
            }
            
        //Since we may have set the error variable to something while trying to send the messae, we need another error check
        if($error != '0')
            {
            echo "<p>$error</p><br>";
            }
            
        else
            {
            //Here's the form for the input
            ?>
            <form name="send" method="post" action="../messages/compose.php">
            <table width="80%">
              <tr>
                <td width="150px" align="left" valign="top"><p>Username</p></td>
                 <td width="" align="left" valign="top"><input name="username" type="text" id="username" value="THIS IS WHERE I NEED THE $USERNAME VAR TO BE PRINTED SO THAT I CAN HIDE THIS BOX AND IT WILL ONLY SEND TO ONE USERNAME SO MY CUSTOMERS DONT HAVE THE OPTION TO SEND TO WHO EVER THEY WANT"></td>
              </tr>
              
              <tr>
                <td width="150px" align="left" valign="top"><p>Subject</p></td>
                <td width="" align="left" valign="top"><input name="subject" type="text" id="subject" value="<?php echo "$subject"; ?>"></td>
              </tr>
              
              <tr>
                <td width="150px" align="left" valign="top"><p>Message</p></td>
                <td width="" align="left" valign="top"><textarea name="message" type="text" id="message" value="" cols="50" rows="10"></textarea></td>
              </tr>
                  
              <tr>  
                <td></td>
                <td><input type="submit" name="Submit" value="Send Message"></td>
                <td><a href="#" class="lbAction" rel="deactivate">Cancel</a></td>


              </tr>
            </table>
            </center>
            </form>
            <?php
            }
        }    
    ?>

Link to comment
https://forums.phpfreaks.com/topic/143790-solved-post-get-help/#findComment-754487
Share on other sites

I'm confused, you want the current username in the text box or you want it hidden with the value of $user?

 

In compose.php:

[code]

 

You need to give it the correct value which I'm almost positive is $user or you could give it the username from SESSION

 

Change it to:

 


 

In profile.php you need to use the POST method not the get method...

 

$username = mysql_real_escape_string($_POST['username']);

 

 

Where is the link on Profile.php that sends the user to Compose.php?

 

I guess he wanted a text field but I have no clue...

 

Link to comment
https://forums.phpfreaks.com/topic/143790-solved-post-get-help/#findComment-754506
Share on other sites

Ok basically this is what i mean

 

in profile.php when someone is viewing a profile the profile username is made into a varible

 

so what i need to do is post that varible to compose.php eg.

 

Profile.php

 

<?php

$usernamepost = $_POST['$username'];

?>

 

Then on my Compose.php it will look like this

 

<?php

 

$usernamepost = $_GET['$username'];

 

?>

 

And then i can do this

 

<input type="hidden" value="<?php print $username ?>">

 

If you get what i mean lol ?

Link to comment
https://forums.phpfreaks.com/topic/143790-solved-post-get-help/#findComment-754511
Share on other sites

Yes, but where on profile.php is the link to compose.php?

 

Im not using a link i am using a ajax popup box and its basically like a IFrame that will show the compose.php in it, and what i will do is in compose.php where it says mysql_query blah blah blah instead of it saying (reciever) Values ($reciever) i will put $username so it will input the username of the person's profile they was viewing

Link to comment
https://forums.phpfreaks.com/topic/143790-solved-post-get-help/#findComment-754524
Share on other sites

So is the user clicking a link from somewhere (not mentioned) to get to compose.php?  Then you want to store the username in a hidden field in compose.php and pass it to profile.php?

 

So your steps should look like this:

 

Profile.php

$usernamepost = $_POST['usernamepost'];
?>

 

Then on my Compose.php it will look like this

$usernamepost = $_GET['$username'];
?>

 

And then i can do this


 

PS - Never use short tags, always use <?php.

Link to comment
https://forums.phpfreaks.com/topic/143790-solved-post-get-help/#findComment-754525
Share on other sites

didnt work :(,

 

i have found a easyer way around this

 

 

this is the link on profile.php

 

<a href="../messages/compose.php" class="lbOn">Send Message</a>

 

 

if i change the link to this

 

<a href="../messages/compose.php?username=$username" class="lbOn">Send Message</a>

 

how would i make it so that in the compose.php it will get the $username part from that ?

Link to comment
https://forums.phpfreaks.com/topic/143790-solved-post-get-help/#findComment-754546
Share on other sites

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.