Page 1 of 1

Passing value to other file PHP!

Posted: Mon Jun 16, 2008 3:54 pm
by dgrzalja
Hi! I'm in the process of learning PHP.
I must 'exchange' data between files, so i created a HTML file called workout_calc_var.html
and this is it's contents:

Code: Select all

 
<HTML>
<HEAD>
  <title>Submit</title>
</HEAD>
<BODY>
  <TABLE BORDER="0" CELLPADDING="10" WIDTH="100%">
   <TR>
     <TD BGCOLOR=”#F0F8FF” ALIGN="CENTER" VALIGN="TOP" WIDTH="150">
     </TD>
     <TD BGCOLOR=”#FFFFFF” ALIGN="LEFT" VALIGN="TOP" WIDTH="83%">
       <H1>Workout calculator (passing a variable)</H1>
        <P>Enter an exercise, and we’ll tell you how long you’d have
    to do it<BR />to burn one pound of fat.</P>
 
       <FORM METHOD=”post” ACTION=”wc_handler_var.php”>
        <INPUT TYPE=”text” SIZE="50" NAME=”exercise” />
        <p><input type="submit" value="exercise"/></p>
       </FORM>
     </TD>
   </TR>
  </TABLE>
</BODY>
</HTML>
 
After this i created PHP file "wc_handler_var.php" that will get the value and display it like this:

Code: Select all

 
<?php
$exercise = $_POST[‘exercise’];
?>
<HTML>
<HEAD>
<STYLE TYPE=”text/css”>
<!--
BODY, P {color: black; font-family: verdana;
font-size: 10 pt}
H1 {color: black; font-family: arial; font-size: 12 pt}
-->
</STYLE>
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=10 WIDTH=100%>
<TR>
<TD BGCOLOR=”#F0F8FF” ALIGN=CENTER VALIGN=TOP WIDTH=150>
</TD>
<TD BGCOLOR=”#FFFFFF” ALIGN=LEFT VALIGN=TOP WIDTH=83%>
<H1>Workout calculator handler, part 1</H1>
<P>We’ve successfully passed the contents of the
text input field,<BR>
as a variable called “exercise” with a value of
<B><?php echo $exercise; ?></B>.<BR>
But before we can do anything interesting with it,
we need to learn about strings.</P>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
 


So, i open first HTML file with my web browser (http://localhost/2/workout_calc_var.html) and enter
a value and click on submit and get following error:

Not Found
The requested URL /2/”wc_handler_var.php” was not found on this server.

Why is this? And when i run the other file nothing get's to it?
What im I doing wrong? Maybe it's simple but i'm a begginer in PHP so don't laugh much...
Thanks! Daniel! :banghead:

Re: Passing value to other file PHP!

Posted: Mon Jun 16, 2008 11:00 pm
by lonelywolf

Code: Select all

<FORM METHOD=”post” ACTION=”wc_handler_var.php”>
<INPUT TYPE=”text” SIZE="50" NAME=”exercise” />
Your problem is the quote mark :wink: , you can replace by single quote or double quote.
Correct code here:

Code: Select all

<FORM METHOD="post" ACTION="wc_handler_var.php">
<INPUT TYPE="text' SIZE="50" NAME="exercise" />
enjoy learning php :wink:

Re: Passing value to other file PHP!

Posted: Tue Jun 17, 2008 5:29 am
by dgrzalja
Thanks for your reply!
I don't get it, you changed my code, only the input part to:

Code: Select all

<INPUT TYPE="text' SIZE="50" NAME="exercise" />
So, you replaced

Code: Select all

TYPE="text"
with

Code: Select all

TYPE="text'
Can you please explain why was that the error i was looking for?
What difference does one " make? Thanks!

Re: Passing value to other file PHP!

Posted: Tue Jun 17, 2008 6:03 am
by WebbieDave
His intent was to change all of your ” characters to " characters. Notice the difference between those two characters. The first is not valid in HTML, the second is.

Re: Passing value to other file PHP!

Posted: Tue Jun 17, 2008 6:37 am
by dgrzalja
Oh.... I can see the problem, how stupid of me... THANKS!