ohkered Posted January 5, 2011 Share Posted January 5, 2011 hi again, after I clicked a particular data to edit, it will bring me to a html which i created, UpdateRecordForm.html In there, how do i retrieve the data from database so it will show the data in the textbox that i can edit it. <!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>adding a new data record</title> </head> <body> <form id="form1" name="form1" method="post" action="processUpdateRecord.php"> <p> <label>Student Number: <input name="StudentNumber" type="text" id="StudentNumber" size="10" /> </label> </p> <p> <label>First Name: <input name="FirstName" type="text" id="FirstName" size="20" /> </label> </p> <p> <label>Last Name: <input name="LastName" type="text" id="LastName" size="20" /> </label> </p> <p> <label>Email Address: <input name="EmailAddr" type="text" id="EmailAddr" size="50" /> </label> </p> <p> <label>Telephone: <input name="PhoneNumber" type="text" id="PhoneNumber" size="20" /> </label> </p> <p> <input type="submit" name="submit" id="submit" value="Update Record" /> </p> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/ Share on other sites More sharing options...
unlishema.wolf Posted January 6, 2011 Share Posted January 6, 2011 what type of database are you using? Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155535 Share on other sites More sharing options...
Zurev Posted January 6, 2011 Share Posted January 6, 2011 hi again, after I clicked a particular data to edit, it will bring me to a html which i created, UpdateRecordForm.html In there, how do i retrieve the data from database so it will show the data in the textbox that i can edit it. <!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>adding a new data record</title> </head> <body> <form id="form1" name="form1" method="post" action="processUpdateRecord.php"> <p> <label>Student Number: <input name="StudentNumber" type="text" id="StudentNumber" size="10" /> </label> </p> <p> <label>First Name: <input name="FirstName" type="text" id="FirstName" size="20" /> </label> </p> <p> <label>Last Name: <input name="LastName" type="text" id="LastName" size="20" /> </label> </p> <p> <label>Email Address: <input name="EmailAddr" type="text" id="EmailAddr" size="50" /> </label> </p> <p> <label>Telephone: <input name="PhoneNumber" type="text" id="PhoneNumber" size="20" /> </label> </p> <p> <input type="submit" name="submit" id="submit" value="Update Record" /> </p> </form> </body> </html> You're using raw HTML there, absolutely no php either. You're a far ways off from being able to achieve this, you might want to look into some starting PHP/MySQL tutorials. Edit: Just noticed it's action is a php file, it would be extremely helpful if we could get a look at that. Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155539 Share on other sites More sharing options...
unlishema.wolf Posted January 6, 2011 Share Posted January 6, 2011 @Zurev you should actually read some of his code. it calls to an action in php. Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155541 Share on other sites More sharing options...
Zurev Posted January 6, 2011 Share Posted January 6, 2011 @Zurev you should actually read some of his code. it calls to an action in php. @unlishema.wolf - Thanks for the attitude bud, I edited it about a minute after I posted it after re-reading. Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155542 Share on other sites More sharing options...
unlishema.wolf Posted January 6, 2011 Share Posted January 6, 2011 @Zurev Sorry my internet has a bit of lag due to being connected through a mobile phone. And it didn't load the edit. Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155543 Share on other sites More sharing options...
denno020 Posted January 6, 2011 Share Posted January 6, 2011 <!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>adding a new data record</title> </head> <body> <?php include_once "connect_to_mysql.php"; //your script to connect to your database $sqlCommand = "SELECT student_number, first_name, last_name, email, phone FROM (your table name) WHERE student_number='$student_number' LIMIT 1"; // $query = mysql_query($sqlCommand, $myConnection) or die (mysql_error()); while ($row = mysql_fetch_array($query)) { $student_number = $row["student_number"]; $first_name = $row["first_name"]; $last_name = $row["last_name"]; $email = $row["email"]; $phone = $row["phone"]; } mysql_free_result($query); ?> <form id="form1" name="form1" method="post" action="processUpdateRecord.php"> <p> <label>Student Number: <input name="StudentNumber" type="text" id="StudentNumber" size="10" value="<?php echo $student_number ?>" /> </label> </p> <p> <label>First Name: <input name="FirstName" type="text" id="FirstName" size="20" value="<?php echo $first_name ?>" /> </label> </p> <p> <label>Last Name: <input name="LastName" type="text" id="LastName" size="20" value="<?php echo $last_name ?>" /> </label> </p> <p> <label>Email Address: <input name="EmailAddr" type="text" id="EmailAddr" size="50" value="<?php echo $email ?>" /> </label> </p> <p> <label>Telephone: <input name="PhoneNumber" type="text" id="PhoneNumber" size="20" value="<?php echo $phone ?>" /> </label> </p> <p> <input type="submit" name="submit" id="submit" value="Update Record" /> </p> </form> </body> </html> If you haven't already done it, your processUpdateRecord.php script will need to update the row with student_number of (whatever student you're editing). Denno Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155544 Share on other sites More sharing options...
ohkered Posted January 6, 2011 Author Share Posted January 6, 2011 haha @zurev & wolf. anyway, am using mySQL, phpMyAdmin? and i think my question is a little mislead of what i want. I'll explain it again. and yes, it's plain HTML and the submit button action calls to another php file. now my question is, how do I display my data from a database(SQL) (how to link to my database?) and display it in the HTML textbox. Basically, this HTML is to edit my data thats why I need to show my existing data and to modify the data and submit to a .php to amend my modified data to the database. I'm still working on the processUpdateRecord.php but before that i need to finish this HTML form first. I can show u my processAddRecord.php though. Basically, i'll just tweak a few from this to work on update, like using SELECT then UPDATE. <?php //connect to the database $database = 'CCM3413'; $conn = @new mysqli('localhost', 'root', '', $database); if (mysqli_connect_errno() != 0) { $errno = mysqli_connect_errno(); $errmsg = mysqli_connect_error(); echo "Connect Failed with: ($errno) $errmsg<br/>\n"; exit; } $conn->query("SET NAMES 'utf8'"); //get values from HTML page $StudentNumber = $_POST["StudentNumber"]; $FirstName = $_POST["FirstName"]; $LastName = $_POST["LastName"]; $EmailAddr = $_POST["EmailAddr"]; $PhoneNumber = $_POST["PhoneNumber"]; //add a new record into the table StudentInfo $query_str = "INSERT INTO StudentInfo (StudentNumber, FirstName, LastName, EmailAddr, PhoneNumber) VALUES('$StudentNumber', '$FirstName', '$LastName', '$EmailAddr', '$PhoneNumber')"; $result = @$conn->query($query_str); if ($result === FALSE) { echo "Connection Failed <br/>"; $conn->close(); exit; } else { echo "<p>Inserted a new data record successfully</p>"; echo "<p><a href='displaying.php'>Display the table content</a></p>"; echo "<p><a href='AddRecordForm.html'>Add another data record</a></p>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155547 Share on other sites More sharing options...
ohkered Posted January 6, 2011 Author Share Posted January 6, 2011 <!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>adding a new data record</title> </head> <body> <?php include_once "connect_to_mysql.php"; //your script to connect to your database $sqlCommand = "SELECT student_number, first_name, last_name, email, phone FROM (your table name) WHERE student_number='$student_number' LIMIT 1"; // $query = mysql_query($sqlCommand, $myConnection) or die (mysql_error()); while ($row = mysql_fetch_array($query)) { $student_number = $row["student_number"]; $first_name = $row["first_name"]; $last_name = $row["last_name"]; $email = $row["email"]; $phone = $row["phone"]; } mysql_free_result($query); ?> <form id="form1" name="form1" method="post" action="processUpdateRecord.php"> <p> <label>Student Number: <input name="StudentNumber" type="text" id="StudentNumber" size="10" value="<?php echo $student_number ?>" /> </label> </p> <p> <label>First Name: <input name="FirstName" type="text" id="FirstName" size="20" value="<?php echo $first_name ?>" /> </label> </p> <p> <label>Last Name: <input name="LastName" type="text" id="LastName" size="20" value="<?php echo $last_name ?>" /> </label> </p> <p> <label>Email Address: <input name="EmailAddr" type="text" id="EmailAddr" size="50" value="<?php echo $email ?>" /> </label> </p> <p> <label>Telephone: <input name="PhoneNumber" type="text" id="PhoneNumber" size="20" value="<?php echo $phone ?>" /> </label> </p> <p> <input type="submit" name="submit" id="submit" value="Update Record" /> </p> </form> </body> </html> If you haven't already done it, your processUpdateRecord.php script will need to update the row with student_number of (whatever student you're editing). Denno Thanks, I'll try this now. Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155549 Share on other sites More sharing options...
unlishema.wolf Posted January 6, 2011 Share Posted January 6, 2011 <input name="FirstName" type="text" id="FirstName" size="20" value="<?php echo $first_name ?>" /> where $first_name is you replace that with whatever variable your database data is stored in. Do the same for the rest. Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155550 Share on other sites More sharing options...
ohkered Posted January 6, 2011 Author Share Posted January 6, 2011 Tried.. I'm not sure if my variables $sn, $fn, $ln, $addr, $phone actually captures data from my database. and the textbox doesn't show the data either. it just shows what's in the clause. here's a screenshot Here's my edited code: <!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>adding a new data record</title> </head> <body> <?php include_once "connect.php"; $sn = (String)$_GET['id']; $sqlcommand = "SELECT studentnumber, firstname, lastname, emailaddr, phonenumber FROM studentinfo WHERE studentnumber='$sn' LIMIT 1"; $query = mysql_query($sqlcommand, $myconnection) or die(mysql_error()); while ($row = mysql_fetch_array($query)){ $sn = $row["studentnumber"]; $fn = $row["lastname"}; $ln = $row["lastname"]; $addr = $row["emailaddr"]; $phone = $row["phonenumber"]; } mysql_free_result($query); ?> <form id="form1" name="form1" method="post" action="processUpdateRecord.php"> <p> <label>Student Number: <input name="StudentNumber" type="text" id="StudentNumber" size="10" value="<?php echo $studentnumber ?>" /> </label> </p> <p> <label>First Name: <input name="FirstName" type="text" id="FirstName" size="20" value="<?php echo $fn ?>" /> </label> </p> <p> <label>Last Name: <input name="LastName" type="text" id="LastName" size="20" value="<?php echo $ln ?>" /> </label> </p> <p> <label>Email Address: <input name="EmailAddr" type="text" id="EmailAddr" size="50" value="<?php echo $addr ?>" /> </label> </p> <p> <label>Telephone: <input name="PhoneNumber" type="text" id="PhoneNumber" size="20" value="<?php echo $phone ?>" /> </label> </p> <p> <input type="submit" name="submit" id="submit" value="Update Record" value="" /> </p> </form> </body> </html> Help me please.. I heard that we can't use php in a static HTML? is that right? Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155555 Share on other sites More sharing options...
denno020 Posted January 6, 2011 Share Posted January 6, 2011 you need to save your file as a .php. That is currently saved as a .html. Saving it this way, it will see <?php and not know what the hell is going on with it. So rename your file to be updaterecordform.php . Denno Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155556 Share on other sites More sharing options...
unlishema.wolf Posted January 6, 2011 Share Posted January 6, 2011 Yes if you switch it to .php then it will work. Thanks for the help Denno I probably would have made a lot of mistakes due to lack of sleep. It's 12:30am I'm out for the night. Peace. Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155558 Share on other sites More sharing options...
ohkered Posted January 6, 2011 Author Share Posted January 6, 2011 OK, after renaming my file to .php, the page is totally blank.. lol :'( This is actually my tutorial, so my resources are limited. I'm only allowed to use HTML as a form then php for sql_query. something like that? Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155560 Share on other sites More sharing options...
unlishema.wolf Posted January 6, 2011 Share Posted January 6, 2011 Okay can you do me a favor. Load up you web page and right click on a blank spot. Then go to see source code and post what it says. Edit: Actually upload both .php files and I will send back a working copy(at least it should). I can't test anything until either: a. My webhost registers or b. I get my localhost downloaded. Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155563 Share on other sites More sharing options...
denno020 Posted January 6, 2011 Share Posted January 6, 2011 Well if that page is blank, then that just means there is errors in the php that need to be rectified. So you're doing this for school work? There is no other way that I know of which would allow you to edit a database without using php, and therefore a .php file extension.. Denno Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155565 Share on other sites More sharing options...
Anti-Moronic Posted January 6, 2011 Share Posted January 6, 2011 OK, after renaming my file to .php, the page is totally blank.. lol :'( This is actually my tutorial, so my resources are limited. I'm only allowed to use HTML as a form then php for sql_query. something like that? The form can't be in php anyway. It needs to be HTML. If the page is blank, make sure you have error reporting turned on. Output whatever you can. "I heard that we can't use php in a static HTML? is that right?" No, that's completely wrong. There is absolutely no other way to get a result from your database inserted into the 'value' of a form field without php (in this instance). This is probably the most common use for inline php. Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155588 Share on other sites More sharing options...
ohkered Posted January 6, 2011 Author Share Posted January 6, 2011 Okay can you do me a favor. Load up you web page and right click on a blank spot. Then go to see source code and post what it says. Edit: Actually upload both .php files and I will send back a working copy(at least it should). I can't test anything until either: a. My webhost registers or b. I get my localhost downloaded. k.. sounds good.. Well if that page is blank, then that just means there is errors in the php that need to be rectified. So you're doing this for school work? There is no other way that I know of which would allow you to edit a database without using php, and therefore a .php file extension.. Denno It's my tutorial, just trying to learn php, sql, html etc.. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1155590 Share on other sites More sharing options...
ohkered Posted January 7, 2011 Author Share Posted January 7, 2011 hello guys, anything? Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1156053 Share on other sites More sharing options...
unlishema.wolf Posted January 11, 2011 Share Posted January 11, 2011 I am sorry that I haven't replied. I was busy the last few days. I am taking a look at it right now and will post again with an update. Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1157714 Share on other sites More sharing options...
unlishema.wolf Posted January 12, 2011 Share Posted January 12, 2011 Okay I have fixed the following errors in your code. 1. There was a table connection errror. That is why it would display, it was being killed by the connection. 2. I made your update record actually update instead of insert a new record. 3. I took out the lines that displayed Connected! when you connected to the database sucessfully. 4. I took out the line that randomly displayed the first name and last name twice. 5. I fixed your $fn variable to actually have $row['FirstName'] instead of $row['LastName']. 6. I fixed the CAPS on UpdateRecoredForm.php so it would actually go to it when you click edit. 7. You may have to check the processDeleteRecord.php in the display.php and make sure the CAPS MATCH. And I think that is all of it. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1158223 Share on other sites More sharing options...
ohkered Posted January 12, 2011 Author Share Posted January 12, 2011 Thanks a lot wolf. will try it out now. appreciate your help ! and thanks for your time! Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1158285 Share on other sites More sharing options...
unlishema.wolf Posted January 13, 2011 Share Posted January 13, 2011 Your welcome. If it works can you kindly mark this post as solved? Quote Link to comment https://forums.phpfreaks.com/topic/223534-display-existing-database-where-i-can-edit-in-html/#findComment-1158694 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.