Can I see an example of something..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Can I see an example of something..

Post by seeker2921 »

I've seen alot of sites that use a qurey string like this:

index.php?user=username&pass=password&page=edit.php

I would like to see a simple example of how to do this?
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

What is your point? What do you want to see?

index.php?user=$user&pass=$pass&page=$page

$user, $pass, $page are all values posted using a form.

Sorry, I can't understand what example that you want to see.
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

I just don't understand how to do that.. Everytime I have tried in the past it doesn't work..
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Following will be automatically send the variables to the file itself...

Code: Select all

<form action="<?=$PHP_SELF;?>" method="post">
<input type="text" name="pass" size="10">
<input type="text" name="name" size="10">
<input type="hidden" name="file" size="10" value="edit.php">
<input type="submit" value="SEND">
</form>
And end of file, you have a link, like that

Code: Select all

<a href="<?=$PHP_SELF;?>?name<?=$name;?>&pass<?=$pass;?>&file<?=$file;?>">proceed</a>

And this link leads you a page like you want to see ;)
Hope, this will help.
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

Can it be used with functions?
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Yes of course, what do you want to do?
If you specify what you are trying to accomplish, may be i can help better.
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

Well, I have a simple blog I'm trying to write.. and I'm making the admin section for it and I want it all to be in one page (admin.php) and have one config file but It isn't working well.. so I'm trying to figuare out what I can do to make it work.. I thought if I knew how to do the whole index.php?user=user&pass=pass ect.. It would help me..
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Code: Select all

<?php
//If I understand right, this will help you.

//We have page named  admin.php as follows ;

//==========admin.php===============

echo "<html>";
echo "<body>";

$cm = str_replace("''", "''", $cm);
switch($cm){
     case 11:
         include('admin1.php');
         break;
     case 12:
         include('admin2.php');
         break;
     default :
         include('adminD.php');

echo "</body>";
echo "</html>";


//And the other filesss

//=========admin1.php=========

echo "<html>";
echo "<body>";

echo "admin properties 1";
echo "</body>";
echo "</html>";

//=========admin2.php=========

echo "<html>";
echo "<body>";

echo "admin properties 2";
echo "</body>";
echo "</html>";



//=========adminD.php=========

echo "<html>";
echo "<body>";
echo "<form action="admin.php" method="post">";
echo "<input type="text" name="cm" size="4">";
echo "<input type="submi\t" value="SEND">";
echo "</form>";
echo "</body>";
echo "</html>";



//-----------------------------------------

//If this will not help, let me know.

//Kind Regards.
?>
Last edited by dethron on Fri Feb 13, 2004 3:23 am, edited 1 time in total.
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

Well, Heres what I have so far..

Code: Select all

admin.php

<?
include('/home/oblivion/public_html/admin/inc/config.php');
$strPAGE=$_SERVER['PHP_SELF'];
if(!isset($id)){
echo('<a href=admin.php?id=showadd>Add Entry</a>');
}
elseif($id==showadd){
$date = date ("Y-m-d H:i:s");
echo"<html><body>
<form name='form1' method='post' action='$strPAGE'>

  <p class='date'>Date: 
    <input name='date' type='text' value='$date' maxlength='20'>
  </p>
  <p class='topic'>Topic : 
    <input name='topic' type='text' size='90' maxlength='180'>
  </p>
  <p class='entry'>Entry:</p>
  <p>
    <textarea name='entry' cols='90' rows='20'></textarea>
  </p>
  <p>
    <input type='submit' name='addentry' value='Submit'>
  </p>
</form>
<p>&nbsp;</p></body>
</html>";
}

if(submit=="addentry"){
addentry();
}

function addentry(){ 
$query = "INSERT INTO $table VALUES ('NULL','$date','$topic','$entry')"; 
$result = mysql_query($query); 
if ($result) { 
echo("done"); 
} else { 
echo ("Entry not added.  There was a problem somewhere, fix it."); 
} 
} 

?>

config.php

<?
//Include strings
include('/home/oblivion/public_html/admin/inc/strings.php');

//MySQL Connection Var's
define('DB_NAME', 'oblivion_main');
define('DB_HOST', 'localhost');
define('DB_USER', 'oblivion_oblivio');
define('DB_PASS', 'digital1');
$table=("journal");
$url=('http://www.o-blivion.com/site/blog');
?>
Perhaps this will help for what I am looking for
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

For debugging purposes, use the following line :

echo $id;

And always remember that

elseif($id=="showadd"){

is better than

elseif($id==showadd){


Until know i can't see any problem.
Use echo $id at the top of the page, and then observe what you posted?

I see right values, and it is working. There shouldn't be any problem.

But let me check again.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

dethron wrote:I see right values, and it is working. There shouldn't be any problem.
There will be a problem if register_globals is OFF.

Please read:
Concerning Passing Variables in PHP 4.2+

Mac

[Edit: had to make a change because another poster changed their name]
Last edited by twigletmac on Fri Feb 13, 2004 8:34 am, edited 2 times in total.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Ahh, an oldie, but goodie. =)
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

:) srry
thnx jason :)
.... dethron
================================

Like A Ghost In Daylight
On An Overcrowded Street
He Wishes
To Be Something He Is Not.

Lie A Shadow At Midnight
That Originate In Air
He Wishes To Release...


================================
User avatar
voodoo9055
Forum Commoner
Posts: 51
Joined: Sat Apr 26, 2003 3:27 pm
Location: Montgomery, AL

Post by voodoo9055 »

Code: Select all

<form method="post" action="index.php?user=<?php echo $user;?>&pass=<?php echo $pass;?>">
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

So what is your point?
Post Reply