Jump to content

Viewing a particular record in a database


fmsguy06

Recommended Posts

Hello to all!

 

I have made a database allowing others to enter information about themselves (create.php):

 

<?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
//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 databse.php:

 


<?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. ");



?>

 

I created an edit and delete of the index.php, which work fine. To view what is in the database, I'm not sure how to go about. I can see the firs and last name and ID in index, and delete it if need be, but in a view.php I'm trying to make it so that, first and last as well as gender and bio can be seen, of the selected, when view is selected in the index.php next to a name. Any advice? I thank you in advance!

How I have the link to view.php next to every name in the database

 


<?php

//

      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/>";

//

?>

 

Edit and delete work fine, but I am not sure what to place in view.php itself to allow all the information they entered to actually be seen.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.