View Full Version : MySQL-PHP syntax
bennystromberg
01-04-2004, 09:32 AM
I would like some help to solve a problem. I´m coding a web-application in PHP that uses MySQL. I would like to have a webpage that receives information about people in a company from a database and puts the information in textboxes. Each textbox has a label.
Example: If the user Alan Smith logs in then his page would look like this
Name Alan Smith
Title CEO
Adress England
The text that comes after the label should be displayed in textboxes so that the user could change the information about himself and then press a update button to save the information to the database.
I would be grateful if somebody could help me.
Thanks in advance!
What exactly do you need help with? Do you already have some code?
Displaying the data in textfields, is just the same as displaying it as text. You only need to print the data as the value of that textbox, instead of as plain text. Like
<input type="text" name="flabel" size="24" value="<?php echo $row['variable'] ?>" />
or
echo('<input type="text" name="username" size="24" value="'. $row['namevariable'] .'" />');
(assuming $row[] contains the row from the recordset)
Then saving the changed values is just the same as saving regular textfield-values. Like
$update=("UPDATE table SET namevariable='" . $_POST['username'] . "' WHERE pkvalue=" . $_SESSION['userid']);
bennystromberg
01-04-2004, 10:26 AM
Is it easiest to post the information if a make a form? Should I make a update.php-file that then updates the db or can it be implemented in the same code? Sorry that I´m asking so simple questions but I´m a beginner :)
Is it easiest to post the information if a make a form?
If you want to get values from a textfield, then that is the only option.
Should I make a update.php-file that then updates the db or can it be implemented in the same code?
Well, i usually work with multi-purpose pages. The formdata is selected, the form is build with the data in it, it is posted to itself, and then the form is evaluated and the values in the db are updated. All in one page. It makes it easier to display errormessages if the values are invalid etc.
Sorry that I´m asking so simple questions but I´m a beginner
I see. In the beginning it can be quite tough, but one you've written a few pages you can fall back on, it will all start to make sense.
I sadly don't have the time to write this out for you.
But there are a lott of good tutorials at www.hotscripts.com
Just search for tutorials or scripts about forms.
A good getting startde article is http://www.mysql.com/articles/ddws/index.html
If you read through part 4 ( http://www.mysql.com/articles/ddws/20.html )
then you will pretty much get the idea and code for the job your after.
If you have any, more precise, questions, then don't hesitate to post them here or in the PHP forum.
bennystromberg
01-05-2004, 08:24 AM
Thanks a lot for your help!
Jeewhizz
01-08-2004, 07:28 PM
I can also recommend the PHP101 tutorials at www.devshed.com
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.