Cowprint Posted November 24, 2010 Share Posted November 24, 2010 Hello, I'm a bit new to PHP and mysql. Basically i'm trying to build something that will allow users to input information into several fields (mixture of text fields and check boxes), store the data in the database and then be able to view all current info in the database. Then I need them to be able to edit the stored information by selecting one of the lines of stored information, and update the info. I have managed to build the database with a table, and can add information into it, but how do I allow users to select the entry they have made, and then edit it? Here's my code: The index.php page <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <?php //Make the connection mysql_connect ("localhost", "noah77_noah", "appleface") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("noah77_cinternal"); //Build query $query = mysql_query("SELECT * FROM `table1` ORDER BY `table1`.`FName` DESC LIMIT 0 , 30"); //Display results while ($row = mysql_fetch_array($query)) { "<br /> <b>ID:</b> " .$row['ID']. "<br /> <b>First Name:</b> ".$row['FName']. "<br /> <b>Last Name:</b> ".$row['LName']. "<br /> <b>Phone:</b> ".$row['PHON']. "<br />"; } ?> <body> </body> </html> The form.php page: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <form method="post" action="update.php"> First Name: <br /> <input type="text" name="FName" size="30" /><br /> Last Name: <br /> <input type="text" name="LName" size="30" /><br /> Phone Number: <br /> <input type="text" name="PHON" size="12" /><br /> <input type="submit" value="Update Database" /> </body> </html> The updateinfo.php page: Titel:<br/> <input type="text" value="<?php echo $titel;?>" name="Titel" size=60/> <br/> Acteur:<br/> <input type="text" value="<?php echo $acteur;?>" name="Acteur" size=60/> <br/> Taal:<br/> <input type="text" value="<?php echo $taal;?>" name="Taal"/> <br/> Jaar:<br/> <input type="text" value="<?php echo $jaar;?>" name="Jaar" size=10/> <br/> IMDB:<br/> <input type="text" value="<?php echo $imdb;?>" name="IMDB" size=38/> <br/> Summary:<br/> <TEXTAREA NAME="Summary" ROWS=6 COLS=45> <?php echo $summary;?> </TEXTAREA> <br/> Foto locatie:<br/> <input type="text" value="<?php echo $foto;?>" name="Foto" size=59/> </br> <input type="submit" value="submit changes"/> </form> </body> </html> Also how do I format/style the information that is inputted into the database? Thanks, Noah Quote Link to comment https://forums.phpfreaks.com/topic/219718-storing-information-in-mysql-viewing-it-and-editing-it/ Share on other sites More sharing options...
jdavidbakr Posted November 24, 2010 Share Posted November 24, 2010 You'll need to have either a separate form for editing or modify your form to include a way to look up the current information. You need to tell the form which row you're editing, so you might put it into the query string, something like form.php?id=15 - and then as you build your form, retrieve the row with id 15 and use those values to populate the form. You also might want to include a hidden input type to store the ID, so when you process the submission you know whether you are editing an existing row or adding a new one. As for styling in the database, if I understand your question, you don't do any styling in the database. As you draw the page that has the info in the database you style it using the html/php code. The data in the database is just that - raw data. Quote Link to comment https://forums.phpfreaks.com/topic/219718-storing-information-in-mysql-viewing-it-and-editing-it/#findComment-1139095 Share on other sites More sharing options...
Cowprint Posted November 25, 2010 Author Share Posted November 25, 2010 Yeah I had a rough idea of how to do it, but I don't know the code to use, are there any good tutorials online anywhere? I found a few but they don't seem to work.... Yeah as for styling, I know that you need to do it in PHP/HTML, but I can't seem to get the styling to work, how to you put the HMTL into the PHP page? Quote Link to comment https://forums.phpfreaks.com/topic/219718-storing-information-in-mysql-viewing-it-and-editing-it/#findComment-1139498 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.