jug Posted September 5, 2006 Share Posted September 5, 2006 <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 meany response will be much appreciatedcheers -- jug Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 5, 2006 Share Posted September 5, 2006 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. Quote Link to comment Share on other sites More sharing options...
jug Posted September 5, 2006 Author Share Posted September 5, 2006 <?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 problemmany thanks in advance - jugps also what does <i> </i> and ="<?php echo $_SERVER['PHP_SELF']; ?>" just for future reference Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 6, 2006 Share Posted September 6, 2006 Oops missed out the semi-colon after this:Change:$Username = $_POST['txtLogInUserName']to this:$Username = $_POST['txtLogInUserName']; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.