sheep01 Posted July 12, 2007 Share Posted July 12, 2007 I can echo the number on the "math.php" but I cannot preform any math functions with it such as getting the absolute value or the cosine. PHP version is 4.3 (I think) So any help is much needed. Heres where the number is input <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <head> <title>Submit a number!</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <form action="math.php" method="post"> Choose a Number <input type="text" name="$n" /><br /> <input type="submit" name="submit" value="Submit me!" /> </form> </body> </html> Heres the output/not working part. But if I add "echo $_REQUEST['$n'];" then it echos the number but nothing else. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <head> <title>Fancy Internet Thingy!</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <?php $_REQUEST['$n']; echo(abs('$n') . "<br />"); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/59562-solved-what-is-wrong-here/ Share on other sites More sharing options...
cooldude832 Posted July 12, 2007 Share Posted July 12, 2007 because $n is nothing you would need to say $n = $_POST['n']; to initialize a value for $n at the minimal, otherwise it is considered null when it is used unset(); Link to comment https://forums.phpfreaks.com/topic/59562-solved-what-is-wrong-here/#findComment-295980 Share on other sites More sharing options...
tsilenzio Posted July 12, 2007 Share Posted July 12, 2007 Ok here is your proble you have: <?php $_REQUEST['$n']; echo(abs('$n') . "<br />"); ?> the fix for it would be: <?php $_REQUEST['n']; echo(abs($n) . "<br />"); ?> and doing stuff like $_SESSION['var'], $_GET['var'], $_REQUEST['var'] you need to drop the $ sign same goes for when variables are inside single quotes like so: echo('$n') will output: $n instead of what ever was inside of it Link to comment https://forums.phpfreaks.com/topic/59562-solved-what-is-wrong-here/#findComment-295981 Share on other sites More sharing options...
tsilenzio Posted July 12, 2007 Share Posted July 12, 2007 forgot to mension if you would like to use variables inside quotes it HAS to be double quotes like this would work: <?php $Name = "Taylor"; echo("Hi my name is: $Name"); ?> outputs: Hi my name is: Taylor Link to comment https://forums.phpfreaks.com/topic/59562-solved-what-is-wrong-here/#findComment-295983 Share on other sites More sharing options...
sheep01 Posted July 12, 2007 Author Share Posted July 12, 2007 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <head> <title>math.php</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <?php $_REQUEST["$n"]; echo(abs("$n") . "<br />"); ?> </body> </html> It should look something like that? Link to comment https://forums.phpfreaks.com/topic/59562-solved-what-is-wrong-here/#findComment-295988 Share on other sites More sharing options...
Jewbilee Posted July 12, 2007 Share Posted July 12, 2007 you're also using a $ in the HTML form for the name... you only need to use the letter or string for the name. Link to comment https://forums.phpfreaks.com/topic/59562-solved-what-is-wrong-here/#findComment-295989 Share on other sites More sharing options...
trq Posted July 12, 2007 Share Posted July 12, 2007 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <head> <title>math.php</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <?php $_REQUEST["$n"]; echo(abs("$n") . "<br />"); ?> </body> </html> It should look something like that? No. Exactly like... <?php $n = $_REQUEST["n"]; echo(abs($n) . "<br />"); ?> Link to comment https://forums.phpfreaks.com/topic/59562-solved-what-is-wrong-here/#findComment-295993 Share on other sites More sharing options...
tapos Posted July 12, 2007 Share Posted July 12, 2007 Change this Choose a Number <input type="text" name="$n" /><br /> like this Choose a Number <input type="text" name="n" /><br /> after that in the second portion use this <?php $n = $_REQUEST["n"]; echo(abs($n) . "<br />"); ?> -- Tapos Pal Link to comment https://forums.phpfreaks.com/topic/59562-solved-what-is-wrong-here/#findComment-296032 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.