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

Link to comment
Share on other sites

<!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
Share on other sites

<!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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.