PDA

Click to See Complete Forum and Search --> : variable problem


samsyl
May 21st, 2009, 07:51 AM
can anyone tell me why $btnSubmit doesnt show any value?
it works wen i run in my pc
but wen i upload to my server it doesnt show any value

thanks

<?php
echo("Hi");
echo($btnSubmit);
?>

<html>
<body>
<form name="frm1">
<table border='0' align='center'>
<tr>
<td align='centre'>Enter Admin Password</td>
</tr>
<tr>
<td><input type="password" name="txtpass"></td>
</tr>
<tr>
<td align='center'><input type="submit" value="Enter" name="btnSubmit"></td>
</tr>
</table>
</form>
</body>
</html>

kfcSmitty
May 21st, 2009, 08:52 AM
Several things are wrong with your code.

#1 You have no method on your form. It should be either POST or GET or else the server has no idea what kind of data it is dealing with.

#2 You're echoing a variable that has never been set. I'm not sure how it ever worked for you.

What exactly are you attempting to do with this?

Here is what I think you're attempting to do.


<?php
echo("Hi," . $_POST['name']);
?>

<!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>POST Example</title>
</head>
<body>
<form name="frm1" method="post" action="">
<table border='0' align='center'>
<tr>
<td align='center'>Enter Admin Password</td>
</tr>
<tr>
<td><input type="text" name="name" id="name" /><input type="password" name="txtpass" id="txtpass" /></td>
</tr>
<tr>
<td align='center'><input type="submit" value="Enter" name="btnSubmit" /></td>
</tr>
</table>
</form>
</body>
</html>


Now the above code works as I think you intended, but the code still needs a lot of work.

I would recommend following the tutorials below for some help.

XHTML: http://www.w3schools.com/xhtml/default.asp
PHP: http://www.w3schools.com/php/default.asp

kows
May 21st, 2009, 02:51 PM
$btnSubmit would be defined, it just means that register_globals is on on his local installation. however, this is bad practice, and I would definitely follow the advice above. and also, try putting or tags around your code in the future!

samsyl
May 22nd, 2009, 05:42 AM
thanks both of u for ur help

samsyl
May 22nd, 2009, 07:21 AM
now following code working in server but not in my pc.
i m using Apache 1.3 and PHP4
anything wrong with software versions?


<?php
if ($_POST['btnSubmit'])
{
$logpass = $_POST['txtpass'];

mysql_connect ("127.0.0.1");
mysql_select_db("huntandblake");

$res=mysql_query("select * from logid where logincode='$logpass'");

$row=mysql_fetch_array($res);
if(!($row))
{
header("location:index.html");
}
else
{
header("location:AdminHome.PHP");
}
}
?>

<!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>POST Example</title>
</head>
<body>
<form name="frm1" method="post" action="">
<table border='0' align='center'>
<tr>
<td align='center'>Enter Admin Password</td>
</tr>
<tr>
<td><input type="password" name="txtpass" id="txtpass" /></td>
</tr>
<tr>
<td align='center'><input type="submit" value="Enter" name="btnSubmit" /></td>
</tr>
</table>
</form>
</body>
</html>

kfcSmitty
May 22nd, 2009, 07:43 AM
Where is it failing?

Also, you should not do


if ($_POST['btnSubmit'])


Because if a user is in IE and hits enter rather than clicking on the button to submit your form, that field will be blank.

See the below post for more detail.

http://www.vbforums.com/showthread.php?t=562749



*edit* I just checked it and it does not send it through properly from what I can tell.

If you use the PHP function str_split, you can split it on a # of characters though.


$textLineByLine = str_split($_POST["area"],13);

samsyl
May 22nd, 2009, 08:29 AM
its failing to understand this condition

if ($_POST['btnSubmit'])

i dont know y? its working in server but my pc its always false.

thanks for reply

kfcSmitty
May 22nd, 2009, 10:11 AM
The link in my previous post should point you in the right direction.

visualAd
May 23rd, 2009, 04:48 AM
You should use isset instead.