Re: How to show the data from a database

From: Date: Mon, 05 Jun 2000 21:40:04 +0000
Subject: Re: How to show the data from a database
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-1098@lists.php.net to get a copy of this message
one thing that I find really facilitates things is to use an array for the form data (name the elements like 'myarray[myfield1], myarray[myfield2]'). This method will work for everything except select multiple's. ex. mysql: create table users (user_id, password, firstname, lastname, description) note: password should be md5 encrypted on its way into the database in this example. (see md5() in the php manual) -- login.html ----------------------------------- <form action=myform.php method=post> <input type=text name=user_id> <input type=password name=password> </form> ------------------------------------------------- -- myform.php ----------------------------------- // $user_id and $password are passed from login.html if ($user_id && $password) { $epass = md5 ($password); // check them against the database $q_user = "select * from users where user_id='$user_id' and password='$epass'"; $r_user = mysql_query ($q_user); // run the user query if (mysql_num_rows ($r_user) == 0) { // did we return a row? // they're not in the db/invalid login echo "Login Incorrect. <a href='$PHP_SELF'>Back to login.</a>"; exit; } else { // we got a row from the user query if (isset($submit_button)) { // did somebody click the button? // build the update query while (list ($k, $v) = each ($form_data)) { $a_update[] .= "$k=\"$v\""; } $q_update = implode (", ", $a_update); $query = "update users set $q_update where user_id='$user_id'"; // ok, run the query mysql_query ($query); // now rerun the user query to get the updated data $r_user = mysql_query ($q_user); } // set the form data $form_data = mysql_fetch_array($r_user, MYSQL_ASSOC); // returns associative array } echo "<form action='$PHP_SELF' method=post>"; echo "<input type=hidden name=user_id value='$user_id'>"; echo "<input type=hidden name=epass value='$epass'>"; echo "<input type=text name=form_data[firstname] value=\"$form_data[firstname]\"><br> echo "<input type=text name=form_data[lastname] value=\"$form_data[lastname]\"><br>"; echo "<input type=text name=form_data[description] value=\"$form_data[description]\"><br>"; echo "<input type=submit name=submit_button value='Update'>"; echo "</form>"; } else { echo "No username/password."; } -------------------------------------------------- Hope this helps, Ryan On Mon, Jun 05, 2000 at 10:46:03PM +0200, Emir Musabasic wrote: > Hi guys, > > I'm fairly new to PHP and I've stumbled into a problem that I can't figure > out how to solve, basically what I want to do is to have a user log in and > when a user logs in using his login name and password that I have stored in > a mysql table called users, then I want to show him the data that he has > submitted before and that is stored in a mysql database and give him the > ability to change that data, so if I for example have a directory I want > the users listed in it to be able to change for example the description of > their site and so on. Can anybody help me with this or if somebody has the > code to do something like this send it to me. I would be really grateful > for all the help, I sure need it. > I've tried to find something about this in the manual but I really don't > know what I need to do so that I can pull this off, kinda hard to find it > then. :)))))) > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net ---end quoted text---

« previous php.general (#1098) next »