Viewing a particular record in a database |
![]() ![]() |
Viewing a particular record in a database |
Nov 16 2009, 03:53 AM
Post
#1
|
|
|
Advanced Member ![]() ![]() ![]() Group: Members Posts: 8,266 Joined: 23-November 08 Member No.: 6,521 |
Hello to all!
I have made a database allowing others to enter information about themselves (create.php): PHP Code: <?php require_once("database.php"); if (isset($_POST['submit'])) { $firstname = mysql_real_escape_string( $_POST['firstname'] ); $lastname = mysql_real_escape_string( $_POST['lastname'] ); $bio = mysql_real_escape_string( $_POST['bio'] ); $gender = mysql_real_escape_string( $_POST['gender'] ); $sql = "INSERT INTO profiles VALUES(null, '".$firstname."','".$lastname."','".$bio."','".$gender."')"; $run = mysql_query($sql); if ($run) { echo "Your Project Was Created Successfully"; } else { echo "There was an error".mysql_error(); } } else { ?> <form action="create.php" method="post"> First Name:<input type="text" name="firstname" /><br /> Last Name:<input type="text" name="lastname" /><br /> BIO:<br /> <textarea name="bio" cols="50" rows="4"></textarea><br /> Female:<input type="radio" name="gender" value="female"> Male:<input type="radio" name="gender" value="male"><br /> <input type="submit" name="submit" value="Create Profile" /> </form> <?php } ?> which is stored in index.php: PHP Code: <?php //list out records in our table require_once('database.php'); $sql = "SELECT id, firstname, lastname FROM profiles"; $run = mysql_query($sql); echo "<table border="1">"; echo "<tr>"; echo "<th>ID</th>"; echo "<th>First Name</th>"; echo "<th>Last Name</th>"; echo "<th>Actions</th>"; echo "</tr>"; while ($row = mysql_fetch_array($run)) { echo "Another "; echo "<tr>"; echo "<td>".$row['id']."</td>"; echo "<td>".$row['firstname']."</td>"; echo "<td>".$row['lastname']."</td>"; echo "<td>"; echo "<a href="view.php?id=".$row['id']."">View |<a/>"; echo "<a href="edit.php?id=".$row['id']."">Edit |<a/>"; echo "<a href="delete.php?id=".$row['id']."">Delete<a/>"; echo "</td>"; echo "</tr>"; } echo "</table>"; ?> And here is the main database.php: PHP Code: <?php $db_server = "localhost"; $db_name = "project"; $db_user = "root"; $db_password = ""; $dbc = mysql_connect( $db_server, $db_user, $db_password ) or die("Could not connect to Database. "); $dbs = mysql_select_db( $db_name ) or die("Could not select database. "); ?> Everything works, except for view.php (which is used in index.php.) I'm not sure how to make it do what I am trying to do. This: PHP Code: echo "<a href="delete.php?id=".$row['id']."">Delete<a/>"; Allows deletion in database. This: PHP Code: echo "<a href="edit.php?id=".$row['id']."">Edit |<a/>"; Allows editing of information already stored. And This: PHP Code: echo "<a href="view.php?id=".$row['id']."">View |<a/>"; I'm trying to get this to show all information that was entered about a person. I'm not sure how to do this... I thank you all in advance! |
|
|
|
![]() ![]() ![]() |
|
Lo-Fi Version | Time is now: 10th March 2010 - 07:34 PM |