FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » display data from mysql db in text box??
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: display data from mysql db in text box?? [message #169389 is a reply to message #169374] Thu, 09 September 2010 07:20 Go to previous messageGo to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma:
Senior Member
El 08/09/2010 21:12, PAkerly escribió/wrote:
> I want to create a simple page to edit a record, and when submit is
> clicked I want to update the record.
>
> First I want to display all the data for the record, based on ID, on
> the page
> Here is what I am doing:
>
> <?php
> $txtid= $_POST[txtid];

You are (inadvertently) using an undefined constant. This should trigger
a notice. Try this instead:

<?php

error_reporting(E_ALL);
ini_set('display_errors', TRUE);

$txtid = isset($_POST['txtid']) ? $_POST['txtid'] : NULL;

>
> $sql = "SELECT date, user1, user2, user3, role, id
> FROM myuserdata
> WHERE id= $txtid
> ORDER BY id";

You are basically taking raw random input from an untrusted source,
injecting it into a SQL statement and running the resulting query
against your database server. It's not very different from publishing
your password in the front page :)

You don't say what DB library you are using but, in this case, you can
probably do something like this:

if( !is_null($txtid) ){
$sql = 'SELECT date, user1, user2, user3, role, id
FROM myuserdata
WHERE id=' . (int)$txtid;
// ...
}

Please note I've removed the ORDER BY statement: there's no point in
sorting a result set than can contain at most one row.


> And so then I have text boxes on the page and I want to fill those in
> based on the current ID
>
> I tried to do this:
>
> <input type="text" name="txtdate" id="txtdate" value=<?php echo
> [date];?> />
>
> <input type="text" name="txtuser1" id="txtuser1" value=<?php echo
> [user1];?> />
>
> this did not work. How would I display the actual db fields in the
> textboxes?

Perhaps you mean this:

<input type="text" name="txtuser1" id="txtuser1" value=<?php echo
htmlspecialchars($a_variable_name); ?> />

Or this:

<input type="text" name="txtuser1" id="txtuser1" value=<?php echo
htmlspecialchars($an_array_name['user1']); ?> />


PHP is very picky: you must use the PHP syntax to write PHP code; you
cannot invent your own.



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Php code for ajax encoding
Next Topic: Re: get_object_vars ($this) and member visibility
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 05:54:03 GMT 2024

Total time taken to generate the page: 0.05989 seconds