echo in form input value

Thread Solved

Join Date: Sep 2009
Posts: 14
Reputation: andym67 is an unknown quantity at this point 
Solved Threads: 0
andym67 andym67 is offline Offline
Newbie Poster

echo in form input value

 
0
  #1
Sep 9th, 2009
This is driving me crazy and should be very easy. I am trying to pre-fill an html form with session data using echo. I can compile and run but the form field contains a / if the session data is blank. How can I get rid of the /

Heres the code:


  1.  
  2. <input name="fname" type="text" class="textfield" id="fname" value = <?php echo $_SESSION["namevalue"]; ?> />

I have tried several combinations of '"` etc and it seems I am just missing the obvious. Thanks in advance - anyone.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 804
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Practically a Posting Shark

Re: echo in form input value

 
0
  #2
Sep 9th, 2009
Hi andym67 and welcome to DaniWeb

A better approach is this:
  1. if(isset($_SESSION["namevalue"]))
  2. $val = $_SESSION["namevalue"];
  3. else
  4. $val = "";
  5. // maybe do some validation on $val here
  6. echo "<input name='fname' type='text' class='textfield' id='fname' value='$val' />";
or:
  1. <?php
  2. if(isset($_SESSION["namevalue"]))
  3. $val = $_SESSION["namevalue"];
  4. else
  5. $val = "";
  6. // maybe do some validation on $val here
  7. ?>
  8. <input name="fname" type="text" class="textfield" id="fname" value="<?php echo $val; ?>" />;
Last edited by darkagn; Sep 9th, 2009 at 8:54 pm.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 525
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: echo in form input value

 
0
  #3
Sep 9th, 2009
Look at your value attribute,:
  1. value = <?php echo $_SESSION["namevalue"]; ?> />

This should be:
  1. value="<?php echo $_SESSION["namevalue"]; ?>" />
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,394
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 170
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: echo in form input value

 
0
  #4
Sep 9th, 2009
Agree with Xan's code fix


embedding php inside html, it is important to get all the quotes in.
only add a usefula(maybe) caveat to the code he provided, a recommendation to change whatever editor used to something that code highlights
It becomes easy to see when something is missing if the text is some bright colour when a(the) quote(s) Brace(s) Bracket(s) < > is(are) missing
Notepad++ Notepad2 & a bunch of good code highlighting editors

without the quotes output html for a nul field is value= /> your visble backslash
with quotes a nul gives value="" />
Last edited by almostbob; Sep 9th, 2009 at 9:31 pm.
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 14
Reputation: andym67 is an unknown quantity at this point 
Solved Threads: 0
andym67 andym67 is offline Offline
Newbie Poster

Re: echo in form input value

 
0
  #5
Sep 10th, 2009
Hey All - Thanks for the several different suggestions. I am using
  1. if(isset($_SESSION["namevalue"]))
but was able to determin that the previously mentioned part was where I was messing up so hence my limited code post.

I am still getting used to PHP and NetBeans both so the color scheme/code completion and the exact ;,'"` where have you was throwing me off.

Thanks again.!

Andy
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 554 | Replies: 4
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC