I have a form that writes to a database. Which works fine except for two things. The first of which I called the ghost writer because no matter what I put in the field for the phone number it writes back to the database a phone number I did not enter.
Here is the code below:
<div align="center">
<p><br>
<br>
<span class="style1"><u>Order Confirmation Form</u><br>
(Sales)
</span></p>
<form name="form1" method="post" action="update.php">
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="left">Order Number: </div></td>
<td> </td>
<td><input name="order_id" type="text" value="<?php echo $result["order_id"]; ?>" maxlength="11" readonly="true">
<div align="left"></div></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="159" colspan="2"><div align="left">Date of Contact</div></td>
<td width="91"><div align="left">
<input name="date_req" type="text" id="date_req" value="<?php echo $result["date_req"]; ?>" maxlength="11" readonly="true">
</div></td>
<td width="91"> </td>
<td width="176"><div align="left">Phone:</div></td>
<td colspan="2"><div align="left">
<input name="client_phone" type="text" id="phone_num4" value="<?php echo $result["client_phone"]; ?>" maxlength="10">
</div></td>
</tr>
<tr>
<td colspan="2"><div align="left">Name:</div></td>
<td colspan="2"><div align="left">
<input name="client_name" type="text" id="name4" value="<?php echo $result["client_name"]; ?>" maxlength="50">
</div></td>
<td><div align="left">Fax:</div></td>
<td colspan="2"><div align="left">
<input name="client_fax" type="text" id="fax_num5" value="<?php echo $result["client_fax"]; ?>" maxlength="10">
</div></td>
</tr>
<tr>
<td colspan="2"><div align="left">Company:</div></td>
<td colspan="2"><div align="left">
<input name="client_company" type="text" id="company4" value="<?php echo $result["client_company"]; ?>" maxlength="50">
</div></td>
<td><div align="left">Department:</div></td>
<td colspan="2"><div align="left">
<input name="client_department" type="text" id="client_department2" value="<?php echo $result["client_department"]; ?>" size="20" maxlength="50">
</div></td>
</tr>
<tr>
<td colspan="2"><div align="left">Address: </div></td>
<td colspan="2"><div align="left">
<textarea name="client_address" cols="20" rows="1" id="textarea6"><?php echo $result["client_address"]; ?></textarea>
</div></td>
<td><div align="left"></div></td>
<td colspan="2"><div align="left"></div></td>
</tr>
<tr>
<td colspan="2"><div align="left">City:</div></td>
<td colspan="2"><div align="left">
<input name="client_city" type="text" id="city4" value="<?php echo $result["client_city"]; ?>" maxlength="50">
</div></td>
<td><div align="left">Website:</div></td>
<td colspan="2"><div align="left">
<input name="client_website" type="text" id="website5" value="<?php echo $result["client_website"]; ?>" maxlength="50">
</div></td>
</tr>
<tr>
<td colspan="2"><div align="left">State: </div></td>
<td colspan="2"><div align="left">
<select name="client_state" size="1" id="select4">
<option value="<?php echo $result["client_state"]; ?>"><?php echo $result["client_state"]; ?></option>
<option value="Alaska">AK - Alaska</option>
<option value="Arizona">AZ - Arizona</option>
and so on... </select>
</div></td>
<td><div align="left">Email:</div></td>
<td colspan="2"><div align="left">
<input name="client_email" type="text" id="email4" value="<?php echo $result["client_email"]; ?>" maxlength="50">
</div></td>
</tr>
<tr>
<td colspan="2"><div align="left">Zip:</div></td>
<td colspan="2"><div align="left">
<input name="client_zip" type="text" id="zip4" value="<?php echo $result["client_zip"]; ?>" maxlength="5">
</div></td>
<td colspan="2" align="left"><div align="left">Date Production Dept. called: </div></td>
<td width="282" align="left"><div align="right">
<input name="date_contacted " type="text" id="date_production" value="<?php echo date('M d Y'); ?>" maxlength="10">
</div></td>
</tr>
<tr>
<td colspan="2"> </td>
<td colspan="2"> </td>
<td colspan="3" align="left"> </td>
</tr>
</table>
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="left"><br>
<strong>Standard Deliverables Agreed To: </strong> * Please (√) Check All Features That Apply...<br>
<?php
//passing the variable
$order_list=$_POST['order_list'];
//Including the connection information
include "config.php";
//connect to the mysql server
$link2 = mysql_connect($server, $db_user, $db_pass);
//select the database
mysql_select_db($database);
//Getting all the variables
$query2 = mysql_query ("SELECT * FROM orders WHERE order_id = ".$order_list, $link2);
//Putting the results in an array
$result2 = mysql_fetch_array($query2);
?>
<input name="on_camera" type="checkbox" value="1" <?php
if($result2["on_camera"] == "1") {
echo "checked";
}
?>
>
On-Camera Talent, and Voiceovers Studio Talent provided upon request<br>
<input name="graphics_animation" type="checkbox" value="1" <?php
if($result2["graphics_animation"] == "1") {
echo "checked";
}
?>
</div></td></tr>
</table>
<p><br>
<br>
<br>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<strong><br>
</strong></div>
The other issue is with the checkboxes:
<input name="on_camera" type="checkbox" value="1" <?php
if($result2["on_camera"] == "1") {
echo "checked";
}
?>
Even with the $result2 equal to one it doesnt always display the check after the second time I update the page by clicking the update button. Meaning if I uncheck or check it, it writes back to the database correctly but if I pull sthe page up again through the search the boxes that I unchecked might still be check and the boxes I checked are no longer checked. I go into the database and the entery is the correct one.
Here is my update code for that:
$client_id='';
$client_name=$_POST['client_name'];
$client_company=$_POST['client_company'];
$client_address=$_POST['client_address'];
$client_city=$_POST['client_city'];
$client_state=$_POST['client_state'];
$client_zip=$_POST['client_zip'];
$client_ph=$_POST['client_phone'];
$client_email=$_POST['client_email'];
$order_id=$_POST['order_id'];
$date_contacted = date("F j, Y");
// if checkbox is checked
if (isset($_POST['on_camera'])) {
// set the value
$on_camera = $_POST['on_camera'];
// if not checked
} else {
// set the value to NULL
$on_camera = '0';
}
// if checkbox is checked
if (isset($_POST['graphics_animation'])) {
// set the value
$graphics_animation = $_POST['graphics_animation'];
// if not checked
} else {
// set the value to NULL
$graphics_animation = '0';
}
//Including the connection information
include "config.php";
//connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass) or die("Could not connect to MySQL");
//select the database
mysql_select_db($database) or die ("Could not select database");
//update table orders
$query_orders = mysql_query("UPDATE orders SET on_camera='$on_camera', graphics_animation='$graphics_animation' WHERE order_id=$order_id") or die("There was a order error:" .mysql_error ());
//Close first connection
mysql_close();
//Including the connection information
include "config.php";
//connect to the mysql server
$link2 = mysql_connect($server, $db_user, $db_pass) or die("Could not connect to MySQL");
//select the database
mysql_select_db($database) or die ("Could not select database");
//update table clients
$query_clients = mysql_query ("UPDATE clients SET client_name='$client_name', client_company='$client_company', client_department='$client_department', client_address='$client_address', client_city='$client_city', client_state='$client_state', client_zip='$client_zip', client_phone='$client_ph', client_fax='$client_fax', client_website='$client_website', client_email='$client_email' WHERE order_id=$order_id") or die("There was a client error:" .mysql_error ());
//$result2 = mysql_query($query_clients) or die( "An error has ocured: " .mysql_error ());
mysql_close();
Any help would be greatly appreciated!
Modern Merlin