Forum Moderators: coopster
sorry, i should have put the whole codes. can you help me out with this one please...
<input type="hidden" name="username" value= "<?print ((isset($_POST['username']))? $_POST['username'] : "")?>">
<input type="hidden" name="password" value= "<?print ((isset($_POST['password']))? $_POST['password'] : "")?>">
dc
if(isset($_POST["id"])) $id = (int)$_POST["id"];
elseif(isset($_GET["id"])) $id = (int)$_GET["id"l;
else $id = 0;//or without this line. Depends only on you. However if you don't have this line then before DELETE you should write:
if($id)
{
mysql_query...
}
(int)$ ... is to converge data from post to strict integer. This way nobody will be able to do sth badly to your db.
BTW "Is not defined" error means, that never in the script you wrote, what the $id exactly is.
best regards
Michal Cibor
$db="mydatabase";
$link = mysql_connect("localhost","root", "");
//$link = mysql_connect("localhost",$_POST['username'],$_POST['password']);
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
mysql_query("DELETE FROM birthdays where id = $id")or die("Delete Error: ".mysql_error());
mysql_close($link);
print "Record Removed.\n";
?>
<br><br>
<form method="POST" action="birthdays_delete_form.php">
<input type="hidden" name="username" value="<?php print $_POST['username']?>">
<input type="hidden" name="pass" value="<?php print $_POST['password']?>">
<input type="submit" value="Delete Another">
</form><br>
<form method="POST" action="birthdays_dbase_interface.php">
<input type="hidden" name="username" value="<?php print $_POST['username']?>">
<input type="hidden" name="pass" value="<?php print $_POST['password']?>">
<input type="submit" value="DBase Interface">
</form>
</body>
</html>
Please tell me what have i done wrong... it keeps saying undefined variable line 24...please tell...
<input type="hidden" name="id" value="<?php echo $id?>">
And I would still put:
or die("Couldn't open $db: ".mysql_error());
if($id)mysql_query("DELETE FROM birthdays where id = $id")or die("Delete Error: ".mysql_error());
mysql_close($link);
Best wishes
Michal Cibor
$db="mydatabase";
$link = mysql_connect("localhost","root", "");
//$link = mysql_connect("localhost",$_POST['username'],$_POST['password']);
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
if($id)mysql_query("DELETE FROM birthdays where id = $id")or die("Delete Error: ".mysql_error());
mysql_close($link);
print "Record Removed.\n";
?>
<br><br>
<form method="POST" action="birthdays_delete_form.php">
<input type="hidden" name="id" value="<?php print $_POST ['id']?>">
<input type="hidden" name="username" value="<?php print $_POST['username']?>">
<input type="hidden" name="pass" value="<?php print $_POST['password']?>">
<input type="submit" value="Delete Another">
</form><br>
<form method="POST" action="birthdays_dbase_interface.php">
<input type="hidden" name="username" value="<?php print $_POST['username']?>">
<input type="hidden" name="pass" value="<?php print $_POST['password']?>">
<input type="submit" value="DBase Interface">
</form>
</body>
</html>
PLEASE.... i am still having problems. its staying undefined variables and undefined index... please help.
<form method="POST" action="birthdays_delete_form.php">
<input type="hidden" name="id" value="<?php print $_POST ['id']?>">
<input type="hidden" name="username" value="<?php print $_POST['username']?>">
<input type="hidden" name="pass" value="<?php print $_POST['password']?>">
<input type="submit" value="Delete Another">
</form><br>
<form method="POST" action="birthdays_dbase_interface.php">
<input type="hidden" name="username" value="<?php print $_POST['username']?>">
<input type="hidden" name="pass" value="<?php print $_POST['password']?>">
<input type="submit" value="DBase Interface">
</form>
to this:
<form method="POST" action="birthdays_delete_form.php">
<input type="hidden" name="id" value="<?php print ((isset($_POST['id']))? $_POST['id'] : "")?>">
<input type="hidden" name="username" value="<?php print ((isset($_POST['username']))? $_POST['username'] : "")?>">
<input type="hidden" name="pass" value="<?php print ((isset($_POST['password']))? $_POST['password'] : "")?>">
<input type="submit" value="Delete Another">
</form><br>
<form method="POST" action="birthdays_dbase_interface.php">
<input type="hidden" name="username" value="<?php print ((isset($_POST['username']))? $_POST['username'] : "")?>">
<input type="hidden" name="pass" value="<?php print ((isset($_POST['password']))? $_POST['password'] : "")?>">
<input type="submit" value="DBase Interface">
</form>
dc