...

View Full Version : Need help Iím PHP beginner.



jetpower8888
01-05-2006, 01:15 PM
I have a problem regarding with my code or maybe to my PHP configuration. I write a simple code, when I execute it to IE, no value of my variable “name”, can anybody advice me what to do.

here's my code:

<html>
<head>
<title>Jet Search</title>
</head>

<body>
<h2>Search for First name</h2>
<form action="rname.php" method="post">
Please Enter name:
<br>
<input name="name" type=text id="name">
<br>
<input type=submit value="Search">

</form>
</body>
</html>

Rname code

<?
echo $name;
?>
:confused:

Rich Pedley
01-05-2006, 01:53 PM
Posted in wrong board but while I'm here:



<?php
echo $_POST['name'];
?>

jetpower8888
01-05-2006, 02:21 PM
thx, I'll try it but still no result.

NancyJ
01-05-2006, 02:26 PM
<? if(!empty($_POST)){
echo "This is the form data I recieved:<br />"
print_r($_POST);
}
else
{
echo "No form data recieved. "
}

jetpower8888
01-06-2006, 03:24 AM
Thanks NancyJ, your code gives me a result by the way without using print_r($_POST) statement, instead using simply echo “$var” statement. I think it’s my PHP configuration is the problem, can you give some information about configuring PHP that work smoothly, I’m using PHP-4.3.11 XP IE Apache 2.

missing-score
01-06-2006, 03:50 AM
Try this, and let us know what output you get:



<?php
echo 'PHP Script Output: ';
if( !empty( $_POST['name'] ) ){
echo $_POST['name'];
} else {
echo 'No data sent';
}
?>

jetpower8888
01-06-2006, 07:40 AM
Result

PHP Script Output: Gaw

Thanks Missing-Score, for your nice code, without using $_POST, instead using a simply echo ď$nameĒ statement.

Just like this:

<?
echo $name;
?>

Can I get the value of var $name, with this code in my computer no result.

Is this a PHP configuration problem? can you give some information about configuring PHP that work smoothly, Iím using PHP-4.3.11 XP IE Apache 2.
:confused:

ralph l mayo
01-06-2006, 08:09 AM
Using just $name works with register globals set on in your php.ini. It's off by default because it's generally considered to be a security issue. You can read more about it here: http://us3.php.net/register_globals

Here's a function that emulates register globals in the post array, but it's subject to the same problems and should be used sparingly or not at all if you can help it.



if (isset($_POST))
{
foreach ($_POST as $key=>$value)
{
${$key} = $value;
}
}

if (isset($name))
{
echo $name;
}

GO ILLINI
01-07-2006, 01:57 AM
Yes $name is easier, but its bad form if, like ralph l mayo said, you are on a server that doesnt use them. If you are learning a programing language its best to learn with proper form then when you are comfortable with thoose use the shortcuts if you can.

felgall
01-07-2006, 10:09 PM
Write your code so it will work with register globals off and it will still work with register globals on. This will avoid the need to change your code once your host becomes security concious.

jetpower8888
01-09-2006, 05:40 AM
Thanks guy:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum