Jump to content

I guess very simple - declaring variables from a user input


Recommended Posts

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

Your intentions are completly wrong. PHP runs on the server and generates the output back to the browser. You canno do this:
[code]input name="imageField" type="image"  ... onClick="<?php $Username = $_POST['txtLogInUserName']; ?>" >[/code]
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:
[code=php:0]<?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>[/code]


When you first go to the page, [i]Please fill out the form below, click submit when done[/i] 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.
Link to comment
Share on other sites

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