LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-02-2012, 12:59 PM   #1
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 127

Rep: Reputation: 1
I want to insert a string into a form


Hi Guys...

I am writing a shopping cart, starting with a freeby that I found on the Internet.

I am also using a 'login script' that I found on the Internet.
A customer cannot buy unless he is logged in.

When the customer moves to CHECKOUT he is presented with a form to fill in.
Since we already have all the user's details in the database I would like to use this information and pre-fill the form for the user.
This is part of the code in the checkout:
Code:
$name = $row['full_name'];

$output[] = '<tr height="30">';  
$output[] = '<td align="right">Your Name: </td>';  
$output[] = '<td align="left"><input type="text" name="name" size="30" value=$name </td>'; 
$output[] = '</tr>';
$name does contain the name of the user.
I cannot get it to fill in the value of $name.

Can anybody help and point me in the right direction ?
 
Old 07-02-2012, 01:31 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,352

Rep: Reputation: 5385Reputation: 5385Reputation: 5385Reputation: 5385Reputation: 5385Reputation: 5385Reputation: 5385Reputation: 5385Reputation: 5385Reputation: 5385Reputation: 5385
I thought PHP won't expand variables in single-quoted strings?

PHP Code:
$output[] = '<td align="left"><input type="text" name="name" size="30" value=$name </td>'
Try changing it to a double-quoted string:

PHP Code:
$output[] = "<td align=\"left\"><input type=\"text\" name=\"name\" size=\"30\" value=$name </td>"

Last edited by dugan; 07-02-2012 at 01:43 PM.
 
Old 07-02-2012, 02:37 PM   #3
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 127

Original Poster
Rep: Reputation: 1
Hi dugan...
Thank you for your reply
Quote:
I thought PHP won't expand variables in single-quoted strings?
It will actually work BOTH ways:
Code:
$output[] = '<td align="left"><input type="text" name="name" size="30" value=$name </td>';
and
Code:
$output[] = "<td align="left"><input type='text' name='name' size='30' value=$name </td>";
These will both work when using $output[]

However, your suggested quote:
Code:
$output[] = "<td align=\"left\"><input type=\"text\" name=\"name\" size=\"30\" value=$name </td>";
only produced the first name instead of both first and surname.
No idea why.

I found that the answer was:
Code:
$output[] = '<td align="left"><input type="text" name="name" size="30" value="'.$name.'" </td>';
Once again, THANK YOU
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sed (?) insert string between 2 others czezz Programming 10 05-21-2010 12:13 PM
howto insert a string kscott121 Linux - Software 6 12-26-2006 04:50 PM
Insert a string to Syslog? Ransak Linux - Software 4 10-26-2006 04:51 AM
insert string with sed greg108 Programming 7 02-18-2005 02:11 PM
Insert Data by FORM in MYSQL gruger Linux - Software 0 07-16-2003 01:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration