Forum Moderators: open

Message Too Old, No Replies

From database to forms

How do I get data from MYSQL into a form?

         

fonduelover

2:06 pm on Dec 30, 2006 (gmt 0)

10+ Year Member



Hello,

Beginner here!

I have a database with names, addresses, etc and I want to have a page where when I click one of the names of the people in the list, their details from the database fill a form on that page, which can be editted and then the database is submitted.

How do I gets those details into the form and then how do I submit then back to database?

Thanks,
Sarah

justageek

2:48 pm on Dec 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That depends on what language you are using. For PHP look here at example 1: [us2.php.net ]

JAG

henry0

1:43 pm on Jan 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And without taking a trip
Stay at Home [webmasterworld.com]

Tons of good info
Scroll down you will find
"The basic of extracting data... PHP MySQL"

Discovery

7:13 am on Jan 2, 2007 (gmt 0)

10+ Year Member



U can also do this things using AJAX its little bit dificult but i think this is the best way, as now days big sites like gmail and orkut do
learn AJAX
[ajaxtutorial.net...]

fearandir

12:22 am on Jan 9, 2007 (gmt 0)

10+ Year Member



Hello everyone, I'm new on this forum and in PHP programming with use of SQL.
I've already searched the site and found no answer for my question, which is pretty similar as to this one of this thread.
The thing is that I'm developing some customer area for my website. I'm making the admin page, where the admins should be able to add/remove/modify users. The users are stored in a database in a MySQL Server.

I can easily add and remove users from the database. The problem is when modifying:
I'd like to insert the user name into a field and have the other fields (let's say, name, surname, e-mail) completed with the data extracted from the SQL table. Then, after modifying (or not), submit the whole bunch of data and run the UPDATE string to the SQL.

[[I don't know how to turn the data extracted from the SQL into a value for each input of the form. I have both text fields and boxes.]]

Besides, I'd like to make it work without impliying too much webpages (have all integrated into one if possible, even if I need several ".php")

Could anyone give a hand with this? I saw several excellent tutorials and already learnt a lot from you, so any help will be appreciate!
Thanks in advance, see you around. And excuse my english, it's not mi native tongue.

eelixduppy

12:30 am on Jan 9, 2007 (gmt 0)



fearandir, Welcome to WebmasterWorld!

It would be something along these lines:


//connect to db, select database
$query = "SELECT col1,col2 FROM table WHERE userid = 'something'";
$result = [url=http://us2.php.net/manual/en/function.mysql-query.php]mysql_query[/url]($query) or [url=http://us2.php.net/manual/en/function.die.php]die[/url]([url=http://us2.php.net/manual/en/function.mysql-error.php]mysql_error[/url]());

$row = [url=http://us2.php.net/manual/en/function.mysql-fetch-array.php]mysql_fetch_array[/url]($result);
echo '<input type="text" name="col1" value="'.$row['col1'].'" />';
echo '<textarea name="col2">'.$row['col2'].'</textarea>';

*Note: This is only for if one row is returned; if you need more you have to loop through the results.

I think this explains it well enough :)

Also, if you want to continue learning about this process, can you please keep it in the PHP Forum [webmasterworld.com] as that is where this belongs. ;)

txbakers

2:39 am on Jan 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



AJAX is really cool, but from what I understand still not Mac compatible. Is that still true?

eelixduppy

2:50 am on Jan 9, 2007 (gmt 0)



>>Is that still true?


Microsoft first implemented the XMLHttpRequest object in Internet Explorer 5 for Windows as an ActiveX object. Engineers on the Mozilla project implemented a compatible native version for Mozilla 1.0 (and Netscape 7). Apple has done the same starting with Safari 1.2.

[developer.apple.com...]

fearandir

3:35 am on Jan 9, 2007 (gmt 0)

10+ Year Member



Thank you eelixduppy!
I realize I can insert the data as the component of an array, but should I write the entire form with "echo"? And what should I do if I want to "fill" the form with the data of the query without reloading the page? (that is, without having to hit a "submit" after writing the user name). Is there any other way of triggering the query proccess that would keep me in the same page? Any suggestion?

Oh, and:

Also, if you want to continue learning about this process, can you please keep it in the PHP Forum as that is where this belongs. ;)

My bad! I'd continue in the PHP but wouldn't want to lose my initial question. Would a moderator be so gentle as to move these last replies to a new thread in the PHP Forum? I'd appreciate that!
Thanks and again, excuse me if my english is messy.

eelixduppy

3:44 am on Jan 9, 2007 (gmt 0)



Now you are talking about implementing an Ajax solution. Here are some references to keep you busy ;)
Rasmus' 30 second AJAX Tutorial [news.php.net]
The HttpRequest Object [w3schools.com]

Good luck!

P.S. Your English is perfect! Stop worrying about it! :)

fearandir

4:09 am on Jan 9, 2007 (gmt 0)

10+ Year Member



oooh, eelixduppy, thanks but no! No AJAX for me by now!
Funny thing is I have a degree in Tourism, this thing of the PHP and SQL it's kinda temporary, and it's just the result of my willingness to learn.
Perhaps AJAX would be my next challenge, but I have a lot to learn: I just got started with PHP (and already owe you guys a lot!).
Thanks and sorry for this offtopic.