Does this happen???
echo "$sql Record deleted!<p>";
No??
Then what is the value of $id???
Does the rest of the script work???
Dan
On Tuesday, April 8, 2003, at 11:10 AM, cameron@gwschool.com wrote:
Hello,
With the following script, I am able to enter data, but I cannot modify or
delete data, no errors, it just does nothing. obviously I'm missing
something, but I don't know what.
thanks in advance. Cameron
<html>
<body>
<?php
$db = mysql_connect("serverX", "userX", "passwordX");
mysql_select_db("email_db",$db);
if ($submit) {
if ($id) {
$sql = "UPDATE emails SET
first='$first',last='$last',email='$email',store='$store' WHERE id=$id";
} else {
$sql = "INSERT INTO emails (first,last,email,store) VALUES
('$first','$last','$email','$store')";
}
$result = mysql_query($sql);
echo "Record updated/edited!<p>";
} elseif ($delete) {
$sql = "DELETE FROM emails WHERE id=$id";
$result = mysql_query($sql);
echo "$sql Record deleted!<p>";
} else {
if (!$id) {
$result = mysql_query("SELECT * FROM emails",$db);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["id"],
$myrow["first"], $myrow["last"]);
printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF,
$myrow["id"]);
}
}
?>
<P>
<a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>
<P>
<form method="post" action="<?php echo $PHP_SELF?>">
<?php
if ($id) {
$sql = "SELECT * FROM emails WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$first = $myrow["first"];
$last = $myrow["last"];
$email = $myrow["email"];
$store = $myrow["store"];
// print the id for editing
?>
<input type=hidden name="id" value="<?php echo $id ?>">
<?
}
?>
First name:<input type="Text" name="first" value="<?php echo $first
?>"><br>
Last name:<input type="Text" name="last" value="<?php echo $last ?>"><br>
email:<input type="Text" name="email" value="<?php echo $email ?>"><br>
store:<input type="Text" name="store" value="<?php echo $store ?>"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?
}
?>
</body>
</html>
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php