This is my thought process: if the edit form is submitted, then update the database, if not, display the form to update.
<?php
// connect to the database
include('config.php');
$table_name="users";
$id=mysql_real_escape_string($_GET['id']);
$query = "SELECT * FROM $table_name WHERE contactid='$id'";
$result = mysql_query($query) or die("Cannot check for existing ID " . mysql_error());
$form_submit="";
if ($row = mysql_fetch_array($result)) //this is where I wanted to check for the value of submit=Update but I got a boolen error{
$contactid = htmlentities($row['contactid']);
$account_number = htmlentities($row['account_number']);
$organization_title = htmlentities($row['organization_title']);
$account_name = htmlentities($row['account_name']);
$organizationDBA = htmlentities($row['organizationDBA']);
$network_representative = htmlentities($row['network_representative']);
$network = htmlentities($row['network']);
$member_login = htmlentities($row['member_login']);
$title = htmlentities($row['title']);
$salutation = htmlentities($row['salutation']);
$firstname = htmlentities($row['firstname']);
$lastname = htmlentities($row['lastname']);
$communication_method = htmlentities($row['communication_method']);
$phone = htmlentities($row['phone']);
$mobile = htmlentities($row['mobile']);
$otherphone= htmlentities($row['otherphone']);
$fax = htmlentities($row['fax']);
$email_opt_out= htmlentities($row['email_opt_out']);
$email = htmlentities($row['email']);
}
?>
//display the form
<form action="editmember.php" method="post">
<div>
<p><strong>ContactID:</strong> <input type="text" name="contactid" value="<?php echo $contactid; ?>"/></p>
<p><strong>Account Number:</strong> <input type="text" name="accountnumber" value="<?php echo $account_number; ?>"/></p>
<p><strong>Organization Title:</strong> <input type="text" name="organizationtitle" value="<?php echo $organization_title; ?>"/></p>
<p><strong>Account Name:</strong> <input type="text" name="accountname" value="<?php echo $account_name; ?>"/></p>
<p><strong>Organization DBA:</strong> <input type="text" name="dba" value="<?php echo $organizationDBA; ?>"/></p>
<p><strong>Network Representative:</strong> <input type="text" name="networkrep" value="<?php echo $network_representative; ?>"/></p>
<p><strong>Network</strong> <input type="text" name="network" value="<?php echo $network; ?>"/></p>
<p><strong>Login:</strong> <input type="text" name="login" value="<?php echo $member_login; ?>"/></p>
<p><strong>Title:</strong> <input type="text" name="title" value="<?php echo $title; ?>"/></p>
<p><strong>Salutation:</strong> <input type="text" name="salutation" value="<?php echo $salutation ?>"/></p>
<p><strong>First Name:</strong> <input type="text" name="firstname" value="<?php echo $firstname; ?>"/></p>
<p><strong>Last Name:</strong> <input type="text" name="lastname" value="<?php echo $lastname; ?>"/></p>
<p><strong>Communication Method:</strong> <input type="text" name="commethod" value="<?php echo $communication_method; ?>"/></p>
<p><strong>Phone:</strong> <input type="text" name="phone" value="<?php echo $phone; ?>"/></p>
<p><strong>Mobile:</strong><input type="text" name="mobile" value="<?php echo $mobile; ?>"/></p>
<p><strong>Other Phone:</strong> <input type="text" name="other" value="<?php echo $otherphone; ?>"/></p>
<p><strong>Fax:</strong> <input type="text" name="fax" value="<?php echo $fax; ?>"/></p>
<p><strong>Email Opt Out:</strong> <input type="text" name="emailopt" value="<?php echo $email_opt_out; ?>"/></p>
<p><strong>Email</strong> <input type="text" name="email" value="<?php echo $email; ?>"/></p>
<input type="submit" name="submit" value="Update">
</div>
</form>
<?php
else if ($form_submit == "Update") {
mysql_query("UPDATE $table_name SET contactid='$contactid',account_number='$account_number',organization_title='$organization_title', account_name='$account_name', organizationDBA='$organizationDBA', network_representative='$network_representative', network='$network', member_login='$member_login', member_password='$member_password', title='$title', salutation='$salutation', firstname='$firstname', lastname='$lastname',communication_method='$communication_method', phone='$phone', mobile='$mobile', otherphone='$otherphone', fax='$fax', email_opt_out='$email_opt_out', email='$email' WHERE contactid='$id'")
or die(mysql_error());
mysql_query($query) or die("Cannot update record with id $id ID " . mysql_error());
echo 'Member Updated!';
}
It wasn't working- still not working. Never got to the updating part, just died at the cannot update record. Which is why I thought about checking the submit value. Is there a better way to go about it? maybe a isset?
Thanks!