Jump to content

[SOLVED] What is wrong here?


sheep01

Recommended Posts

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

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

<!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?

<!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 />");
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.