stevegingell
asked on
Update form not working
Hi,
I am going crazy withis update code. I am trying to update a page which has data pulled from a database. But those fields are empty every time. Even when i fill it up and hit update i get an error. I am posting the code...hope it makes sense:
<?php require_once ('../includes/config.inc') ?>
<?php require_once ("../../mysql_connect.php" ) ?>
<?php include ("../includes/customer_hea der.html") ?>
<?php if(isset($_SESSION["userna me"]))
{
// get customerid from session
$cid = $_SESSION['customerid'];
if (isset($_POST['submit'])) { // Handle the form.
$message = NULL; // Create an empty new variable.
if (empty($_POST['first_name' ]) || empty($_POST['last_name']) || empty($_POST['business_nam e'])) {
$message .= "<span class='errormessage'><p align='left'>We could not process your request for the following reason(s):</p></span>";
}
//Check for first_name
if (empty($_POST['first_name' ])) {
$fn = False;
$message .= "<span class='errormessage'><div align='left'>• Missing First Name.</div></span>";
} else {
$fn = escape_data($_POST['first_ name']);
}
//Check for last_name
if (empty($_POST['last_name'] )) {
$ln = False;
$message .= "<span class='errormessage'><div align='left'>• Missing Last Name.</div></span>";
} else {
$ln = escape_data($_POST['last_n ame']);
}
//Check for business_name
if (empty($_POST['business_na me'])) {
$bn = False;
$message .= "<span class='errormessage'><div align='left'>• Missing Business Name.</div></span>";
} else {
$bn = escape_data($_POST['busine ss_name']) ;
}
if ($fn && $ln && $bn) { // If everything's OK.
// Make the query.
$query = "UPDATE customers SET first_name='$fn', last_name='$ln', business_name='$bn' WHERE customerid='$cid'";
$result = @mysql_query ($query); // Run the query.
if (mysql_affected_rows() == 1) { // If it ran OK.
$message .= "<span class='errormessage'><div align='center'>Your store info has been updated.</div></span>";
} else { // If it did not run OK.
$message .= "<span class='errormessage'><div align='center'>Your store info could not be updated due to a system error. We apologize for any inconvenience.</div></span ><p>" . mysql_error() . "</p>";
}
mysql_close(); //close database connection
}
} //end of submit conditional
// Retrieve the user's information.
$query = "SELECT * FROM customers WHERE customerid = '$cid'";
$result = @mysql_query ($query); // Run the query.
if (mysql_num_rows($result) == 1) { // Valid user ID, show the form.
// Get the user's information.
$row = mysql_fetch_array($result, MYSQL_ASSOC);
echo ' <table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" width="370"><a href="index.php">Home</a> » <span class="content">Edit Store Info</span></td>
<td valign="top">
<p align="right"><span class="content">You are logged in as: <b>'.$_SESSION["username"] ;
echo '</b></span><br><a href="../logout.php">Logou t</a></td>
</tr>
</table>
<div align="center">';
if(isset($message)) echo $message;
echo' </div><br><br>
<div align="center">
<table border="0" width="70%" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" align="right"><span class="darkbluesmall">All fields marked * are required.</span></td>
</tr>
</table>
</div>
<form name="form1" method="post" action='.$_SERVER["PHP_SEL F"];
echo '>
<div align="center">
<table class="inputform" borderColor="#f0f0f0" border="1">
<tr class="rowcolor1"><td width="162">First Name:</td>
<td><input type="text" name="first_name" class="textbox" maxlength="50" value="';
if(isset($_POST['first_nam e'])) echo $_POST['first_name'];
echo'"><span class="darkbluesmall"> *</span></td>
</tr>
<tr class="rowcolor2"><td width="162">Last Name:</td>
<td><input type="text" name="last_name" class="textbox" maxlength="50" value="';
if(isset($_POST['last_name '])) echo $_POST['last_name'];
echo'"><span class="darkbluesmall"> *</span></td>
</tr>
<tr class="rowcolor1"><td width="162">Business Name:</td>
<td><input type="text" name="business_name" class="textbox" maxlength="200" value="';
if(isset($_POST['business_ name'])) echo $_POST['business_name'];
echo'"><span class="darkbluesmall"> *</span></td>
</tr>
<tr class="rowcolor2"><td width="162">Address:</td>
<td><input type="text" name="address1" class="textbox" maxlength="200" value="';
if(isset($_POST['address1' ])) echo $_POST['address1'];
echo'"><br><input type="text" name="address2" class="textbox" maxlength="200" value="';
if(isset($_POST['address2' ])) echo $_POST['address2'];
echo'"></td>
</tr>
</table>
</div>
<div align="center">
<table cellSpacing="0" cellPadding="0" width="70%" border="0">
<tr>
<td width="50%">
<p align="right"><BR><input type="submit" name="submit" value="Edit Store" class="button">
</p>
</td>
<td width="1%"></td>
<td width="49%">
<p align="left"><BR><input type="reset" name="Submit2" value="Clear" class="button">
</td>
</tr>
</table>
</form>
</div> ';
} else { // Not a valid user ID.
echo '<h1 id="mainhead">Page Error</h1>
<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
}
} else {
echo '<span class="content"><br><br><b r><br><br> <br><p align="center">You are not logged in.<br><br>To login click <a href="../login.php">here</ a>.</p></s pan>';
}
include ('../includes/customer_foo ter.html') ;
?>
I am going crazy withis update code. I am trying to update a page which has data pulled from a database. But those fields are empty every time. Even when i fill it up and hit update i get an error. I am posting the code...hope it makes sense:
<?php require_once ('../includes/config.inc')
<?php require_once ("../../mysql_connect.php"
<?php include ("../includes/customer_hea
<?php if(isset($_SESSION["userna
{
// get customerid from session
$cid = $_SESSION['customerid'];
if (isset($_POST['submit'])) { // Handle the form.
$message = NULL; // Create an empty new variable.
if (empty($_POST['first_name'
$message .= "<span class='errormessage'><p align='left'>We could not process your request for the following reason(s):</p></span>";
}
//Check for first_name
if (empty($_POST['first_name'
$fn = False;
$message .= "<span class='errormessage'><div align='left'>• Missing First Name.</div></span>";
} else {
$fn = escape_data($_POST['first_
}
//Check for last_name
if (empty($_POST['last_name']
$ln = False;
$message .= "<span class='errormessage'><div align='left'>• Missing Last Name.</div></span>";
} else {
$ln = escape_data($_POST['last_n
}
//Check for business_name
if (empty($_POST['business_na
$bn = False;
$message .= "<span class='errormessage'><div align='left'>• Missing Business Name.</div></span>";
} else {
$bn = escape_data($_POST['busine
}
if ($fn && $ln && $bn) { // If everything's OK.
// Make the query.
$query = "UPDATE customers SET first_name='$fn', last_name='$ln', business_name='$bn' WHERE customerid='$cid'";
$result = @mysql_query ($query); // Run the query.
if (mysql_affected_rows() == 1) { // If it ran OK.
$message .= "<span class='errormessage'><div align='center'>Your store info has been updated.</div></span>";
} else { // If it did not run OK.
$message .= "<span class='errormessage'><div align='center'>Your store info could not be updated due to a system error. We apologize for any inconvenience.</div></span
}
mysql_close(); //close database connection
}
} //end of submit conditional
// Retrieve the user's information.
$query = "SELECT * FROM customers WHERE customerid = '$cid'";
$result = @mysql_query ($query); // Run the query.
if (mysql_num_rows($result) == 1) { // Valid user ID, show the form.
// Get the user's information.
$row = mysql_fetch_array($result,
echo ' <table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" width="370"><a href="index.php">Home</a> » <span class="content">Edit Store Info</span></td>
<td valign="top">
<p align="right"><span class="content">You are logged in as: <b>'.$_SESSION["username"]
echo '</b></span><br><a href="../logout.php">Logou
</tr>
</table>
<div align="center">';
if(isset($message)) echo $message;
echo' </div><br><br>
<div align="center">
<table border="0" width="70%" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" align="right"><span class="darkbluesmall">All fields marked * are required.</span></td>
</tr>
</table>
</div>
<form name="form1" method="post" action='.$_SERVER["PHP_SEL
echo '>
<div align="center">
<table class="inputform" borderColor="#f0f0f0" border="1">
<tr class="rowcolor1"><td width="162">First Name:</td>
<td><input type="text" name="first_name" class="textbox" maxlength="50" value="';
if(isset($_POST['first_nam
echo'"><span class="darkbluesmall"> *</span></td>
</tr>
<tr class="rowcolor2"><td width="162">Last Name:</td>
<td><input type="text" name="last_name" class="textbox" maxlength="50" value="';
if(isset($_POST['last_name
echo'"><span class="darkbluesmall"> *</span></td>
</tr>
<tr class="rowcolor1"><td width="162">Business Name:</td>
<td><input type="text" name="business_name" class="textbox" maxlength="200" value="';
if(isset($_POST['business_
echo'"><span class="darkbluesmall"> *</span></td>
</tr>
<tr class="rowcolor2"><td width="162">Address:</td>
<td><input type="text" name="address1" class="textbox" maxlength="200" value="';
if(isset($_POST['address1'
echo'"><br><input type="text" name="address2" class="textbox" maxlength="200" value="';
if(isset($_POST['address2'
echo'"></td>
</tr>
</table>
</div>
<div align="center">
<table cellSpacing="0" cellPadding="0" width="70%" border="0">
<tr>
<td width="50%">
<p align="right"><BR><input type="submit" name="submit" value="Edit Store" class="button">
</p>
</td>
<td width="1%"></td>
<td width="49%">
<p align="left"><BR><input type="reset" name="Submit2" value="Clear" class="button">
</td>
</tr>
</table>
</form>
</div> ';
} else { // Not a valid user ID.
echo '<h1 id="mainhead">Page Error</h1>
<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
}
} else {
echo '<span class="content"><br><br><b
}
include ('../includes/customer_foo
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Still nothing happens when the page comes up, my fields are still not pulling in anything from the database. Even after i tried the die command like you said.
Also when i myself fill everything in, and hit update i get the following error.
An error occurred in script c:\program files\easyphp1-8\www\scrat