Sorry Guys you're probably sick of me asking these questions that are probably obvious to you!
But here is the first one, I have the following code on a page, that gets submitted to istelf, but i want it so that if the user does not fill in one of the fields in the form, it will not sumbit it to the database, instead it wil bring them back and tell them to enter the relevant data, here is the code:
<?php
session_start();
include '../db.php';
$ID = $SESSION['userid'];
$name = $SESSION['first_name'];
$userid = $SESSION['userid'];
$oldpass = $GET['oldpass'];
$newpass = $GET['newpass'];
$Change = $GET['Change'];
$checknewpass = $_GET['checknewpass'];
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="get" action="?PHP_SELF">
<p> </p>
<p> </p>
<table width="359" border="0" cellpadding="0" cellspacing="3">
<tr>
<td width="162">Current Password:</td>
<td width="181"><input type="text" name="oldpass"></td>
</tr>
<tr>
<td>New Password:</td>
<td><input type="text" name="newpass"></td>
</tr>
<tr>
<td>Re-Enter Password:</td>
<td><input type="text" name="checknewpass"></td>
</tr>
</table>
<p> </p>
<p>
<input type="submit" name="Change" value="Save Changes">
</p>
</form>
<?php
$old = md5 ($oldpass);
$new = md5 ($newpass);
?>
<?php
$pass = mysql_query ("SELECT * FROM users WHERE userid = $userid");
$record = mysql_fetch_array($pass);
$databaseold = $record["PASSWORD"];
?>
<?php
if ($Change == 'Save Changes' && $old == $databaseold && $newpass == $checknewpass)
{
$update = "UPDATE users SET PASSWORD = '$new' WHERE userid = $userid";
}
if (@($update))
{
echo("Thank you! Information updated.\n");
}
else
{
echo("<p>Error updating your password! The Reason Was Because The " . mysql_error() . "</p>");
}
?>
<p></p>
</body>
</html>
The above code works perfect, well perfect for my use anyway, but i don't want them to be able to submit it if they haven't filled in a field, the code i tried to use was this:
if ($Save == 'Save Changes')
//then do
if ((!$oldpass) || (!$newpass) || (!$checknewpass)){
echo 'You did not submit the following required information! <br />';
if(!$oldpass){
echo "First Name is a required field. Please enter it below.<br />";
}
if(!$newpass){
echo "Last Name is a required field. Please enter it below.<br />";
}
if(!$checknewpass){
echo "Email Address is a required field. Please enter it below.<br />";
}
exit();
}
before php submits data to the database, so could someone tell me what is the correct way to do this?
The second question is this, is there anyway to destroy data sent from a form to a page after it has been processed, so that when a user hits the refresh button on the submitted page it does not resend the data to the database again, causing it to produce errors, i am trying to do this on another part of my site not the page listed above.
Because i have a page that gets submitted to another page, where data gets entered into a database but when the user hits refresh after it was submitted it resends the data to the database which causes lots of errors.
I hope someone can help me!
Cheers
Dan
Coatsy35@lycos.co.uk