Jump to content

ohkered

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Everything posted by ohkered

  1. Thanks a lot wolf. will try it out now. appreciate your help ! and thanks for your time!
  2. k.. sounds good.. It's my tutorial, just trying to learn php, sql, html etc.. [attachment deleted by admin]
  3. 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?
  4. 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?
  5. 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>"; } ?>
  6. 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>
  7. $sn = (int)$_GET["sn"]; my student ID consist of int and char, what should i replace with int? thanks! the code is almost working. *edit:ahh change it to 'String' .
  8. I have a recordID in my database which is unique, and my studentID is Index. which is, yeah unique. ok i'll look into your codes later, gotta rest. thanks requinix!
  9. hi guys, Basically, what I did was i displayed my database information by a table. on which on the last column there's 2 link, which is edit and delete. My question is what code should i put that when I click on the edit or delete link, so that it can indicate that particular data (or ID) has been selected (or stored) ? sorry for my poor english. hope u guys understand what i need. thanks and help pls SQLversion: 5.5.8 <?php //connects to database require('connect.php'); //select table $select = mysql_query("SELECT * FROM studentinfo") or die('No table exist!'); $numrows = mysql_num_rows($select); echo <<<EOM <table border='1'> <tr> <th>Student Number</th> <th>First Name</th> <th>Last Name</th> <th>Email Address</th> <th>Phone Number</th> <th>Actions</th> </tr> EOM; while ($row = mysql_fetch_assoc($select)) { echo <<<EOM <tr> <td>{$row['StudentNumber']}</td> <td>{$row['FirstName']}</td> <td>{$row['LastName']}</td> <td>{$row['EmailAddr']}</td> <td>{$row['PhoneNumber']}</td> <td><a href='update.php'>Edit</a> <a href='delete.php'>Delete</a></td> </tr> EOM; } echo <<<EOTABLE </table> EOTABLE; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.