logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 



Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



Ghost writer? PHP question

 
Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner



View previous topic :: View next topic  
Author Message
Modern Merlin



Joined: 30 Oct 2007
Posts: 10
Location: Roseville

PostPosted: Thu 15 Nov '07 8:03    Post subject: Ghost writer? PHP question Reply with quote

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:

Code:

<?php
//passing the variable
$order_list=$_POST['order_list'];

//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");

//Getting all the variables
$query = mysql_query ("SELECT * FROM clients WHERE order_id = ".$order_list, $link) or die("<center>There was an error and we could not load the Client list</center>");

//Putting the results in an array
$result = mysql_fetch_array($query);

?>

    <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>&nbsp;</td>
              <td><input name="order_id" type="text" value="<?php echo $result["order_id"]; ?>" maxlength="11" readonly="true">             
              <div align="left"></div></td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</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">&nbsp;</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:&nbsp;&nbsp;&nbsp;</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>
                    <option value="Arkansas">AR - Arkansas</option>
                    <option value="California">CA - California</option>
                    <option value="Colorado">CO - Colorado</option>
                    <option value="Connecticut">CT - Connecticut</option>
                    <option value="Delaware">DE - Delaware</option>
                    <option value="District of Columbia">DC - District of Columbia</option>
                    <option value="Florida">FL - Florida</option>
                    <option value="Georgia">GA - Georgia</option>
                    <option value="Hawaii">HI - Hawaii</option>
                    <option value="Idaho">ID - Idaho</option>
                    <option value="Illinois">IL - Illinois</option>
                    <option value="Indiana">IN - Indiana</option>
                    <option value="Iowa">IA - Iowa</option>
                    <option value="Kansas">KS - Kansas</option>
                    <option value="Kentucky">KY - Kentucky</option>
                    <option value="Louisiana">LA - Louisiana</option>
                    <option value="Maine">ME - Maine</option>
                    <option value="Maryland">MD - Maryland</option>
                    <option value="Massachusetts">MA - Massachusetts</option>
                    <option value="Michigan">MI - Michigan</option>
                    <option value="Minnesota">MN - Minnesota</option>
                    <option value="Mississippi">MS - Mississippi</option>
                    <option value="Missouri">MO - Missouri</option>
                    <option value="Montana">MT - Montana</option>
                    <option value="Nebraska">NE - Nebraska</option>
                    <option value="Nevada">NV - Nevada</option>
                    <option value="New Hampshire">NH - New Hampshire</option>
                    <option value="New Jersey">NJ - New Jersey</option>
                    <option value="New Mexico">NM - New Mexico</option>
                    <option value="New York">NY - New York</option>
                    <option value="North Carolina">NC - North Carolina</option>
                    <option value="North Dakota">ND - North Dakota</option>
                    <option value="Ohio">OH - Ohio</option>
                    <option value="Oklahoma">OK - Oklahoma</option>
                    <option value="Oregon">OR - Oregon</option>
                    <option value="Pennsylvania">PA - Pennsylvania</option>
                    <option value="Rhode Island">RI - Rhode Island</option>
                    <option value="South Carolina">SC - South Carolina</option>
                    <option value="South Dakota">SD - South Dakota</option>
                    <option value="Tennessee">TN - Tennessee</option>
                    <option value="Texas">TX - Texas</option>
                    <option value="Utah">UT - Utah</option>
                    <option value="Vermont">VT - Vermont</option>
                    <option value="Virginia">VA - Virginia</option>
                    <option value="Washington">WA - Washington</option>
                    <option value="West Virginia">WV - West Virginia</option>
                    <option value="Wisconsin">WI - Wisconsin</option>
                    <option value="Wyoming">WY - Wyoming</option>
                </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">&nbsp;</td>
              <td colspan="2">&nbsp;</td>
              <td colspan="3" align="left">&nbsp;</td>
            </tr>
          </table>
          <table width="800" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><div align="left"><br>
                <strong>Standard Deliverables Agreed To: </strong>&nbsp;&nbsp;&nbsp;* Please (&radic;) 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) or die("Could not connect to MySQL");

//select the database
mysql_select_db($database) or die ("Could not select database");

//Getting all the variables
$query2 = mysql_query ("SELECT * FROM orders WHERE order_id = ".$order_list, $link2) or die("<center>There was an error and we could not load the Order list</center>");

//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:

Code:
 <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:

Code:
$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 field is not empty
if (isset($_POST['client_fax'])) {
// set the value
    $client_fax = $_POST['client_fax'];
// if it is empy
} else {
// set the value to NULL
    $client_fax = '0000000000';
}

// if field is not empty
if (isset($_POST['client_department'])) {
// set the value
    $client_department = $_POST['client_department'];
// if it is empy
} else {
// set the value to NULL
    $client_department = 'None';
}

// if field is not empty
if (isset($_POST['client_website'])) {
// set the value
    $client_website = $_POST['client_website'];
// if not checked
} else {
// set the value to NULL
    $client_website = '0';
}

// 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';
}


//if no name entered send an error
if (empty($client_name)){
die("<center>No name was entered.<br>Please hit your back button in your browser and include your name.</center><BR>");
}


//if no email entered send an error
if (empty($client_email)){
die("<center>No email was entered.<br>Please hit your back button in your browser<BR> and include your email address.</center><BR>");
}


//if no company entered send an error
if (empty($client_company)){
die("<center>No company name was entered.<br>Please hit your back button in your browser<BR> and include your companie's name.</center><BR>");
}


//if no address entered send an error
if (empty($client_address)){
die("<center>No address was entered.<br>Please hit your back button in your browser<BR> and include your address.</center><BR>");
}


//if no city entered send an error
if (empty($client_city)){
die("<center>No city was entered.<br>Please hit your back button in your browser<BR> and include the city your business is in.</center><BR>");
}


//if no zip entered send an error
if (empty($client_zip)){
die("<center>No zip code was entered.<br>Please hit your back button in your browser<BR> and include the zip code.</center><BR>");
}


//if no phone entered send an error
if (empty($client_ph)){
die("<center>No phone number was entered.<br>Please hit your back button in your browser<BR> and include your phone number.</center><BR>");
}




//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[/code]
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6255
Location: Germany, Next to Hamburg

PostPosted: Tue 04 Dec '07 10:43    Post subject: Reply with quote

Code:

<input name="on_camera" type="checkbox" value="1" <?php
      if($result2["on_camera"] == "1") {
      echo "checked";
      }
      ?>


In the $_POST a checkbox is "on" or "off" and not "0" or "1"

---

you should echo your build sql query to see what it selects.
Back to top


Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner
Page 1 of 1