PHP in Single line TextField

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Leao
Forum Commoner
Posts: 49
Joined: Mon Aug 21, 2006 8:57 pm
Location: London

PHP in Single line TextField

Post by Leao »

Is it possible to have a single line TextField that retrieves text using PHP from a Mysql database? I've managed to do it with a Multi line Textarea but the same code doesn't seem to work with a Single line TextField. It's necessary as the data to be retrieved is short and doesn't need the scroll bar that a Multi line TextField automatically wraps around it.

Thanks again

Leao
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Why wouldn't it be possible?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Code: Select all

<input type="text" name="sometextfield" value="<?php echo $data_from_database; ?>" />
?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Remember to do an htmlentities() on that.. ;)
Leao
Forum Commoner
Posts: 49
Joined: Mon Aug 21, 2006 8:57 pm
Location: London

Post by Leao »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi, I've attached the code I used for the Multi line text area and the code I tried for the Single line TextField that failed. Haven't I done already what you suggested?

thanx

leao

Code: Select all

<form method="post" action="meetthecommunity.php">
          <div align="center">
            <p>
              <textarea name="meetthecommunity" cols="43" rows="14" id="meetthecommunity"><?php
mysql_connect("mysql","username","password") or die(mysql_error());
mysql_select_db("database_text") or die(mysql_error()); 

$result = mysql_query("SELECT * FROM grid")
or die(mysql_error());  

$row = mysql_fetch_array( $result );

echo $row['meetthecommunity'];

?>
</textarea>
            </p>
            <p>
              <input type="submit" value="upload text">
              </p>
          </div>
        </form>

Code: Select all

<form method="post" action="nnameamember1.php">
          <div align="center">
            <p>
              <input name="nnameamember1" type="text" id="nnameamember1" value="<?phpmysql_connect("mysql","username","password") or die(mysql_error());mysql_select_db("database_text") or die(mysql_error()); $result = mysql_query("SELECT * FROM grid")or die(mysql_error());  $row = mysql_fetch_array( $result );echo $row['nnameamember1'];?>" size="20">
            </p>
            <p>
              <input type="submit" value="change nickname">
              </p>
          </div>
        </form>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
jito
Forum Commoner
Posts: 85
Joined: Sat Mar 25, 2006 4:32 am
Location: india

Post by jito »

yes.
need a space here:<?phpmysql_connect, should be
<?php mysql_connect("server","user","pass")...

what u really want to do? updation form?
Leao
Forum Commoner
Posts: 49
Joined: Mon Aug 21, 2006 8:57 pm
Location: London

Post by Leao »

Thanks, that works brilliantly. I'm using the form to update my mySQL database. Do you have any tips for making such a form secure?

Thanks again – Leao
jito
Forum Commoner
Posts: 85
Joined: Sat Mar 25, 2006 4:32 am
Location: india

Post by jito »

use @ instead of using die().
Post Reply