Forum Moderators: coopster
I would like to show just the record you have entered into the database but my coding displays all the other records in the database.
$num = mysql_num_rows ($result);
if ($num > 0 ) {
while ($row=mysql_fetch_array($result)) {
// output the rows HERE
}
}
else { echo "No records found with that query"; }
$somecontent=null;
while ($row=mysql_fetch_array($result)) {
$someconent .= $row['somefield'];
}
if (! $somecontent) { echo "No records found with that query"; }
else { echo $somecontent; }
include("connect.php");
//
if (isset($_GET['id']) and is_numeric($_GET['id']) and ($_GET['id'] > 0)) {
$id = $_GET['id'];
}
else { die("There is no ID to get!"); }
//
$query = "SELECT * FROM profile where id=$id";
$result = mysql_query($query) or die("Cannot select user profile");
//
if ($row=mysql_fetch_array($result)) {
$myfields = array(
'first_name' => 'First Name',
'surname' => 'Surname',
'company_email' => 'Company Email',
'ba_number' => 'BA Number'
);
foreach ($myfields as $fieldname => $label) {
echo "<p><b>$label:</b>" . $row[$fieldname] . "</p>\n";
}
"<p><a href=\"update.php?id=$id\">Update</a> - <a href=\"delete.php?id=$id\">Delete</a></p>";
}
else { echo "No records found with that query"; }
include("connect.php");
// Previously we only needed this for edit. Now we need it for both.
$myfields = array(
'first_name' => 'First Name',
'surname' => 'Surname',
'company_email' => 'Company Email',
'ba_number' => 'BA Number'
);
//
if (isset($_GET['id']) and is_numeric($_GET['id']) and ($_GET['id'] > 0)) {
$id = $_GET['id'];
$action = 'update.php';
$button_value = 'Update This Record';
$query = "SELECT * FROM profile where id=$id";
$result = mysql_query($query) or die("Cannot select user profile");
if ($row=mysql_fetch_array($result)) {
foreach ($myfields as $fieldname => $label) {
$_POST[$fieldname]=$row[$fieldname];
}
}
}
else {
$id=null;
$action = 'add.php';
$button_value = 'Add New Record';
// Initialize the $_POST variables so we can populate the
// form with empty values and no PHP warnings
foreach ($myfields as $fieldname => $label) {
$_POST[$fieldname]=null;
}
//
echo "<form action=\"$action\" method=\"post\">\n";
if ($id) { echo "<input type=\"hidden\" name=\"id\" value=\"$id\">\n"; }
//
foreach ($myfields as $fieldname => $label) {
echo "<p><label for=\"$fieldname\">$label:</label>
<input type=\"text\" size=\"25\" name=\"$fieldname\" id=\"$fieldname\" value=\"" . $_POST[$fieldname] . "\"></p>\n";
}
echo "<p><input type=\"submit\" value=\"$button_value\"></p>\n";
if ($id) {
echo "<p><a href=\"delete.php?id=$id\">Delete</a></p>";
}
echo "</form>";