Jump to content

[SOLVED] Creating a form with PHP, putting variable for initial value with space..how??


Recommended Posts

Ok so, let me explain what the problem is.

Its easier if i just show you the code:

<?php
$initialvalue= "bob smith";
//Several lines later...
echo '<form action="" method="post">';
echo " YourName: <input type='text' name='newname' value=".$initialvalue." /><br>";
echo '<input type="submit" name="submit" value="Proceed" /></form>';
?>

 

When i run this code, only bob comes out, and not bob smith, in the text box as the default value

 

Anyone see a problem  :confused:? How can i make this work?

 

THanks!!

You need to put delimeters around the value just like you have the name and type attributes...

 

echo " YourName: <input type='text' name='newname' value='".$initialvalue."' /><br>";

and just to point something else out quick, stay consistent with your quotes, ie. first line you used single-quotes, second line double-quotes, then back to single-quotes .. will cause yourself some serious headaches.

 

that is all.

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.