Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
can use $_GET['username']; for some reason
Old 05-14-2008, 11:33 AM can use $_GET['username']; for some reason
Banned

Posts: 23
Trades: 0
ok something not right is happening lol... when i run <? $user = $_GET['username'];
echo $user;?>
on its own it displays the users name on url

BUT when i do this

PHP Code:
<?php session_start();?>
<style type="text/css">
<!--
.message {
color: #000000;
font-family: Verdana;
font-size: 10px;}

.username {
color: #FF9900
font-family: Verdana;
font-size: 10px;
font-weight: bold}

.date {
color: #707070;
font-family: Verdana;
font-size: 9px;}

.forms {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10 px;
color: #6CA05A;
text-decoration: none;
background-color: #CCCCCC;
border-color: #6CA05A;
border-style: solid;
border: 1px}

.submit {
background-color: #CCCCCC;
border-color: #6CA05A;
color: #2A343C;
font-family: Verdana;
font-size: 10px;
border-style: solid;
border 1 px;}
-->
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="padding: 2px">
<?php

// If submitted
if($_POST['submit']) {

// Verify if the fields were filled.
if(!$_POST['message']) {
echo
'Error, You need to post a Message!';
die;
}

// Date format

$date = date("d/m/y"); // http://www.php.net/date

// Assign variables of the forms
// Connect to the database
include('../../settings.php');
$id = $_SESSION['user_id'];
$username = get_username($id);
$user = $_GET['username'];
$message = $_POST['message'];
$ip = $_SERVER['REMOTE_ADDR'];





// Insert the info in the shoutbox table.
$query = "INSERT INTO shoutbox (`user`, username, message, date, ip)
VALUES ('$user','$username','$message','$date','$ip')"
or die(mysql_error());
mysql_query($query);
// close connection


// Show message to let them return to the shoutbox
?>
<div align="center">Thank you for submitting.<br>
Return to the <a href="shoutbox.php">shoutbox</a>!
<?php
// If NOT submitted
} else {




$query = "SELECT * FROM shoutbox ORDER BY id DESC LIMIT 10";
$result = mysql_query($query);
// Create a table
?>

<table width="100%" cellpadding="0" cellspacing="0" border="0">

<?
// Run a While loop for the rows
while($c = mysql_fetch_array($result))
{
?>
<tr>
<td>
<? echo $c[username] ?> says:
<div align="justify"><? echo $c[message] ?></div>
</td>
</tr>
<tr><td>on <? echo $c[date] ?>
<hr noshade="noshade" size="1" style="border-style: dashed" color="#000000" /></td></tr>
<? } ?>

</table>

<form method="post" action="box.php">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Message :</td>
<td><input type="text" name="message" class="forms"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Speak!" class="subtmit"></td>
</tr>
</table>
</form>

<?php } ?>

</body>
</html>

it does not display the username within the url :S even if i echo $user... strange
runnerjp is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-14-2008, 11:45 AM Re: can use $_GET['username']; for some reason
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
HTML Code:
<form method="post" action="box.php"> 
and
PHP Code:
$user $_GET['username']; 
are bound to not work...

Try a
PHP Code:
$user $_POST['username']; 
instead...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 05-14-2008, 11:50 AM Re: can use $_GET['username']; for some reason
Banned

Posts: 23
Trades: 0
sorry i hould explain that
PHP Code:
<? $_GET['username']; ?>
should get the username from the url...

PHP Code:
RewriteEngine on
RewriteBase 
/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d

RewriteRule 
^([^/.]+)/?$ members/index.php?page=profile&username=$
just like this script
PHP Code:
$id $_SESSION['user_id']; 
$username get_username($id); 
gets the username of the perosn logged in which works fine
runnerjp is offline
Reply With Quote
View Public Profile
 
Old 05-14-2008, 03:04 PM Re: can use $_GET['username']; for some reason
Banned

Posts: 23
Trades: 0
ok above if($_POST['submit']) i can crap the name via $_GET['username'] but anything below then i cannot echo it...how comes??
PHP Code:
<?php 
$user 
= isset($_GET['username'])? $_GET['username'] : ""
//echo $user; this displays the user name but anything below it does not
if($_POST['submit']) {

// Verify if the fields were filled.
if(!$_POST['message']) {
echo 
'Error, You need to post a Message!';
die;
}

// Date format

$date date("d/m/y"); // http://www.php.net/date

// Assign variables of the forms
// Connect to the database

include('../settings.php');

$id $_SESSION['user_id'];
$username get_username($id);
$message $_POST['message'];
$ip $_SERVER['REMOTE_ADDR'];
 
 



// Insert the info in the shoutbox table.
$query "INSERT INTO shoutbox (`user`, username, message, date, ip)
VALUES ('
$user','$username','$message','$date','$ip')";
  
$resultmysql_query($query)
    or die(
"QUERY ERROR:<br />{$query}<br />" mysql_error() );
mysql_query($query);
// close connection


// Show message to let them return to the shoutbox
?>
runnerjp is offline
Reply With Quote
View Public Profile
 
Old 05-14-2008, 06:17 PM Re: can use $_GET['username']; for some reason
Banned

Posts: 23
Trades: 0
ok i tried it and it will not display the user name at al i dont get whats going on so for 1 last attempt lol im going to fully expalin whats going on

ok above if($_POST['submit']) i can grab the name via $_GET['username'] but anything below then i cannot echo it...how comes??
PHP Code:

get username gets the name of the profile form the url due to this
PHP Code:
RewriteRule ^([^/.]+)/?$ members/index.php?page=profile&username=$
PHP Code:
<?php session_start(); 
 
 
 
?>
<?php 
$user 
= isset($_GET['username'])? $_GET['username'] : ""
//echo $user; this displays the user name but anything below it does not
if($_POST['submit']) {
 
// Verify if the fields were filled.
if(!$_POST['message']) {
echo 
'Error, You need to post a Message!';
die;
}
 
// Date format
 
$date date("d/m/y"); // http://www.php.net/date
 
// Assign variables of the forms
// Connect to the database
 
include('../settings.php');
$user1 $_POST['usersaccount'];
$id $_SESSION['user_id'];
$username get_username($id);
$message $_POST['message'];
$ip $_SERVER['REMOTE_ADDR'];
 
 
 
 
 
// Insert the info in the shoutbox table.
$query "INSERT INTO shoutbox (`user`, username, message, date, ip)
VALUES ('
$user1','$username','$message','$date','$ip')";
mysql_query($query);
// close connection
 
 
// Show message to let them return to the shoutbox
?>
<div align="center">Thank you for submitting.<br>
Return to the <a href="shoutbox.php">shoutbox</a>!
<?php
// If NOT submitted
} else {
 
 
 
 
$query "SELECT * FROM shoutbox ORDER BY id DESC LIMIT 3";
$result mysql_query($query);
// Create a table
?>
 
<table width="100%" cellpadding="0" cellspacing="0" border="0">
 
<?
// Run a While loop for the rows
while($c mysql_fetch_array($result))
{
?>
<tr>
<td>
<? echo $c[username?> says:
<div align="justify"><? echo $c[message?></div>
</td>
</tr>
<tr><td>on <? echo $c[date?>
<hr noshade="noshade" size="1" style="border-style: dashed" color="#000000" /></td></tr>
<? ?>
 
</table>
 
<form method="post" action="box.php"> 
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Message :</td>
<td><input type="text" name="message" class="forms"><input type="hidden" id="usersaccount" name="usersaccount" value="<?php $user ;?>" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Speak!" class="subtmit"></td>
</tr>
</table>
</form>
 
<?php ?>
 
</body>
</html>
is it because i need to do somethingwith action="box.php" .... this page is actually box.php itself so allits really doing is sending it back to this page....

the page i have included this script on has the name in the url... if i went to just mywebsite.com/box.php it would look like that so i included it on http://www.mywebsite.com/username i thought i best tell you all this as it might be very improtant lol
runnerjp is offline
Reply With Quote
View Public Profile
 
Old 05-15-2008, 05:08 AM Re: can use $_GET['username']; for some reason
Banned

Posts: 23
Trades: 0
btw i have tried
PHP Code:
<form method="post" action="box.php?$user="<?php echo $_GET['username']; ?>>
but user is not echo'd
runnerjp is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to can use $_GET['username']; for some reason
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.50486 seconds with 12 queries