Jump to content


Photo

I guess very simple - declaring variables from a user input


  • Please log in to reply
3 replies to this topic

#1 jug

jug
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts
  • LocationPlymouth, UK

Posted 05 September 2006 - 10:50 AM

<div id="lyrLogin" style="position:absolute; left:578px; top:60px; width:166px; height:45px; z-index:20; visibility: visible;">
  <form action="<?php echo $Username; ?>" method="post" name="frmLogIn" id="frmLogIn">
    <p align="left">
      <input name="txtLogInUserName" type="text" id="txtLogInUserName">
    </p>
  <P>
      <input name="imageField" type="image" src="login_button_up.gif" width="105" height="36" border="0" value="Submit" onClick="<?php $Username = $_POST['txtLogInUserName']; ?>" >
    </p>
  </form>
</div>

<img src="final_layout.jpg">

Alright i have a layer which includes an image and a text box - all i want to do is when they click the image whatever they have typed into the text box will be echo-ed out.

I am a total newbie and will allow anyone to laugh at the code but just cant think why this isnt working - makes sense to me

any response will be much appreciated

cheers -- jug

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 05 September 2006 - 11:48 AM

Your intentions are completly wrong. PHP runs on the server and generates the output back to the browser. You canno do this:
input name="imageField" type="image"  ... onClick="<?php $Username = $_POST['txtLogInUserName']; ?>" >
As befoe the HTML is even shown PHP would have created the username var and assign it it the value of whats in $_POST['txtLogInUserName'] variable.

What you'll want to do is something like this:
<?php

//check that the form has been submitted:
if(isset($_POST['imageField_x']))
{
    // form has been submitted!
   
    // now we set up the username variable:
    $Username = $_POST['txtLogInUserName']

   // Welcome the user:
   echo 'Welcome <i>' . $Username . '</i>, How are you today?<br /><br />';
}
else
{
   // Foprm hasnt been submitted so we'll tell them to:
   echo "Please fill out the form below, click submit when done<br /><br />";
}
?>
<div id="lyrLogin" style="position:absolute; left:578px; top:60px; width:166px; height:45px; z-index:20; visibility: visible;">
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="frmLogIn" id="frmLogIn">
    <p align="left">
      <input name="txtLogInUserName" type="text" id="txtLogInUserName" />
    </p>
     <p>
      <input name="imageField" type="image" src="login_button_up.gif" width="105" height="36" border="0" value="Submit" />
    </p>
  </form>
</div>


When you first go to the page, Please fill out the form below, click submit when done will be displayed above the form. But when you fill in the form and press sumit, you'll get a welcome message with the username you put in the txtLogInUserName text field.

#3 jug

jug
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts
  • LocationPlymouth, UK

Posted 05 September 2006 - 06:35 PM

<?php

if(isset($_POST['imageField_x']))
{
    $Username = $_POST['txtLogInUserName']
    echo 'Welcome <i>' . $Username . '</i>, How are you today?<br /><br />';
}
else
{
echo "Please fill out the form below, click submit when done<br /><br />";
}
?>
 
<div id="lyrLogin" style="position:absolute; left:578px; top:60px; width:166px; height:45px; z-index:20; visibility: visible;">
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" " method="post" name="frmLogIn" id="frmLogIn">
    <p align="left">
      <input name="txtLogInUserName" type="text" id="txtLogInUserName">
    </p>
  <P>
      <input name="imageField" type="image" src="login_button_up.gif" width="105" height="36" border="0" value="Submit" >
    </p>
  </form>
</div>

<img src="final_layout.jpg">




This is the new combined code - but still i get an error:

Parse error: parse error in c:\program files\easyphp1-8\www\test.php on line 7

= which is = echo 'Welcome <i>' . $Username . '</i>, How are you today?

Obviously i dont know whats up as its practically your code - please enlighten me of the problem

many thanks in advance - jug

ps also what does <i> </i> and ="<?php echo $_SERVER['PHP_SELF']; ?>" just for future reference

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 06 September 2006 - 04:01 PM

Oops missed out the semi-colon after this:
Change:
$Username = $_POST['txtLogInUserName']
to this:
$Username = $_POST['txtLogInUserName'];




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users