Jump to content

Recommended Posts

I need help with this form everytime I submit a new name to be added to the data base it refreshes the page and clears the form I think my problem is on the mysql hope some one can help.

 

 

<?php

session_start();

if (!isset($_SESSION["manager"])) {

  header("location: admin_login.php");

  exit();

}

// Be sure to check that this manager SESSION value is in fact in the database

// $managerID = preg_replace('#[^0-9]#i', '', $_SESSION["id"]); // filter everything but numbers and letters

// $manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["manager"]); // filter everything but numbers and letters

// $password = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"]); // filter everything but numbers and letters

// Run mySQL query to be sure that this person is an admin and that their password session var equals the database information

// Connect to the MySQL database

include "../storescripts/connect_to_mysql2.php";

// $sql = mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1"); // query the person

// ------- MAKE SURE PERSON EXISTS IN DATABASE ---------

// $existCount = mysql_num_rows($sql); // count the row nums

// if ($existCount == 0) { // evaluate the count

//    echo "Your login session data is not on record in the database.";

//    exit();

// }

// Error Reporting

error_reporting(E_ALL);

ini_set('display_errors', '1');

?>

 

<?php

 

// Parse the form data and add customer to the system

if (isset($_POST['customer_name']) && isset($_POST['address']) && isset($_POST['city'])&& isset($_POST['state'])&& isset($_POST['zip_code']) && isset($_POST['phone_number']) && isset($_POST['email'])&& isset($_POST['order_number'])&& isset($_POST['order_date'])&& isset($_POST['medication'])&& isset($_POST['comment_box'])&& isset($_POST['extra'])){

 

  $customer_name= mysql_real_escape_string($_POST['customer_name']);

    $address = mysql_real_escape_string($_POST['address']);

  $city = mysql_real_escape_string($_POST['city']);

  $state = mysql_real_escape_string($_POST['state']);

  $zip_code = mysql_real_escape_string($_POST['zip_code']);

  $phone_number = mysql_real_escape_string($_POST['phone_number']);

  $email = mysql_real_escape_string($_POST['email']);

  $order_number = mysql_real_escape_string($_POST['order_number']);

  $order_date = mysql_real_escape_string($_POST['order_date']);

  $medication = mysql_real_escape_string($_POST['medication']);

  $comment_box = mysql_real_escape_string($_POST['comment_box']);

  $extra = mysql_real_escape_string($_POST['extra']);

  //See if that customer name is an identical match to another customer in the system

    $sql = mysql_query("SELECT customer_name, COUNT(customer_name) AS NumOccurrences FROM cpanel GROUP BY customer_name HAVING ( COUNT(customer_name) > 1 )");

    $customerMatch = mysql_num_rows($sql); // count the output amount

  if ($customerMatch > 0) {

   

      echo 'Sorry you tried to place a duplicate "Customer Name" into the system, <a href="customer_list.php">Click Here</a>';

      exit();

  }

    // Add new customer into the database now

  $sql = mysql_query("INSERT INTO cpanel (customer_name, address, city, state, zip_code, phone_number, email, order_number, order_date, medication, comment_box, extra, date_added)

 

  VALUES('$customer_name','$address','$city','$state','$zip_code','$phone_number','$email',$order_number','$order_date','$medication','$comment_box','$extra',now())") or die (mysql_error());

  //$cid = mysql_insert_id();

   

 

    header("location: customer_list.php");

      exit(); 

 

}

?>

<?php

// This block grabs the whole list for viewing

$customer_list ="";

$sql = mysql_query("SELECT * FROM `cpanel` ORDER BY `customer_name` DESC LIMIT 0, 30");

$customerCount = mysql_num_rows($sql); // count the output amount

if ($customerCount > 1) {

  while($row = mysql_fetch_array($sql)){

          $id = $row["id"];

          $customer_name = $row["customer_name"];

          $address = $row["address"];

          $city = $row["city"];

          $state = $row["state"];

          $zip_code = $row["zip code"];

          $phone_number = $row["phone number"];

          $email = $row["email"];

          $order_number = $row["order number"];

          $order_date = $row["order date"];

          $medication = $row["medication"];

          $comment_box = $row["comment box"];

          $extra = $row["extra"];

          $customer_list .= "customer ID: $id - $customer_name - $medication - $phone_number - $order_date <br />";

    }

} else {

  $customer_list = "You have no customer yet";

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Customer List</title>

</head>

 

<body>

<div align="center" id="mainWrapper">

 

  <div id="pageContent"><br />

  <div align="left"><strong><a href="logout.php" class="style3">Logout</a></strong><span class="style1">

    </p>

    <div align="right" style="margin-right:32px;"><a href="customer_list.php#customerForm">+ Add New customer </div>

<div align="left" style="margin-left:24px;">

      <h2 align="center"><strong>Customer List</strong></h2>

      <?php echo $customer_list; ?>   

    </div>

    <hr />

    <a name="customerForm" id="customerForm"></a>

    <h3 align="center">

    ↓ Add New Customer ↓ 

    </h3>

    <form action="customer_list.php" method="post" enctype="multipart/form-data">

    <table width="90%" border="0" cellspacing="0" cellpadding="6">

      <tr>

      <td width="20%" align="right">Customer Name</td>

      <td width="80%"><label>

        <input name="customer_name" type="text" id="customer_name" size="64" />

      </label></td> 

      </tr>

      <tr>

      <td align="right">Address</td>

      <td>

        <input name="address" type="text" id="address" size="64" />

      </td>

      </tr>

      <tr>

      <td align="right">City</td>

      <td>

        <input name="city" type="text" id="city" size="30" />

        </td>

      </tr>

      <tr>

    <td align="right">State</td>

   

    <td><select name="state" id="state">

    <option value="AK">AK</option><option value="AL">AL</option><option value="AP">AP</option><option value="AR">AR</option><option value="AS">AS</option><option value="AZ">AZ</option><option value="CA">CA</option><option value="CO">CO</option><option value="CT">CT</option><option value="DC">DC</option><option value="DE">DE</option><option value="FL">FL</option><option value="FM">FM</option><option value="GA">GA</option><option value="GU">GU</option><option value="HI">HI</option><option value="IA">IA</option><option value="ID">ID</option><option value="IL">IL</option><option value="IN">IN</option><option value="KS">KS</option><option value="KY">KY</option><option value="LA">LA</option><option value="MA">MA</option><option value="MD">MD</option><option value="ME">ME</option><option value="MH">MH</option><option value="MI">MI</option><option value="MN">MN</option><option value="MO">MO</option><option value="MP">MP</option><option value="MS">MS</option><option value="MT">MT</option><option value="NC">NC</option><option value="ND">ND</option><option value="NE">NE</option><option value="NH">NH</option><option value="NJ">NJ</option><option value="NM">NM</option><option value="NV">NV</option><option value="NY">NY</option><option value="OH">OH</option><option value="OK">OK</option><option value="OR">OR</option><option value="PA">PA</option><option value="PR">PR</option><option value="PW">PW</option><option value="RI">RI</option><option value="SC">SC</option><option value="SD">SD</option><option value="TN">TN</option><option value="TX">TX</option><option value="UT">UT</option><option value="VA">VA</option><option value="VI">VI</option><option value="VT">VT</option><option value="WA">WA</option><option value="WI">WI</option><option value="WV">WV</option><option value="WY">WY</option>

   

        </select></td>

    </tr>

  <tr>

    <td align="right">Zip Code</td>

    <td>

    <input name="zip_code" type="text" id="zip_code" size="30" />

    </td>

  </tr>

  <tr>

    <td align="right">Phone Number</td>

    <td>

    <input name="Phone_Number" type="text" id="Phone_Number" size="30" />

    </td>

  </tr>

  <tr>

    <td align="right">Email</td>

    <td>

    <input name="Email" type="text" id="Email" size="30" />

    </td>

  </tr>

  <tr>

    <td align="right">Order Number</td>

    <td>

    <input name="Order_Number" type="text" id="Order_Number" size="30" />

    </td>

  </tr><tr>

    <td align="right">Order Date</td>

    <td><label>

    <select name="order_date" id="order_date" cols="20" rows="1"></textarea>

      class="hideDropDown moduleDrop"><option value="1">Jan</option>

 

<option value="2">Feb</option>

 

<option value="3">Mar</option>

 

<option value="4">Apr</option>

 

<option value="5">May</option>

 

<option value="6">Jun</option>

 

<option value="7">Jul</option>

 

<option value="8">Aug</option>

 

<option value="9">Sep</option>

 

<option value="10">Oct</option>

 

<option value="11">Nov</option>

 

<option value="12">Dec</option>

 

<option value="-1000" selected="selected">Month</option></select>

                  <select name="day" class="hideDropDown"><option value="1">1</option>

 

<option value="2">2</option>

 

<option value="3">3</option>

 

<option value="4">4</option>

 

<option value="5">5</option>

 

<option value="6">6</option>

 

<option value="7">7</option>

 

<option value="8">8</option>

 

<option value="9">9</option>

 

<option value="10">10</option>

 

<option value="11">11</option>

 

<option value="12">12</option>

 

<option value="13">13</option>

 

<option value="14">14</option>

 

<option value="15">15</option>

 

<option value="16">16</option>

 

<option value="17">17</option>

 

<option value="18">18</option>

 

<option value="19">19</option>

 

<option value="20">20</option>

 

<option value="21">21</option>

 

<option value="22">22</option>

 

<option value="23">23</option>

 

<option value="24">24</option>

 

<option value="25">25</option>

 

<option value="26">26</option>

 

<option value="27">27</option>

 

<option value="28">28</option>

 

<option value="29">29</option>

 

<option value="30">30</option>

 

<option value="31">31</option>

 

<option value="-1000" selected="selected">Day</option></select>

                 

             

             

                  <select name="Time"><option <option value="0100">1 am</option>

 

<option value="0200">2 am</option>

 

<option value="0300">3 am</option>

 

<option value="0400">4 am</option>

 

<option value="0500">5 am</option>

 

<option value="0600">6 am</option>

 

<option value="0700">7 am</option>

 

<option value="0800">8 am</option>

 

<option value="0900">9 am</option>

 

<option value="1000">10 am</option>

 

<option value="1100">11 am</option>

 

<option value="1200">12 pm</option>

 

<option value="1300">1 pm</option>

 

<option value="1400">2 pm</option>

 

<option value="1500">3 pm</option>

 

<option value="1600">4 pm</option>

 

<option value="1700">5 pm</option>

 

<option value="1800">6 pm</option>

 

<option value="1900">7 pm</option>

 

<option value="2000">8 pm</option>

 

<option value="2100">9 pm</option>

 

<option value="2200">10 pm</option>

 

<option value="2300">11 pm</option>

 

<option value="0000">12 am</option></select>

    </label></td>

  </tr>

  <tr>

    <td align="right">Medication</td>

    <td><label>

    <textarea name="medication" id="medication" cols="64" rows="2"></textarea>

    </label></td>

  </tr>

  <tr>

    <td align="right">Comment Box</td>

    <td><label>

    <textarea name="comment_box" id="comment_box" cols="64" rows="10"></textarea>

    </label></td>

  </tr>

  <tr>

    <td align="right">Extra</td>

    <td><label>

    <textarea name="extra" id="extra" cols="64" rows="2"></textarea>

    </label></td>

  </tr><br />

<br />

 

<td align="right"><label>

        <input type="submit" name="button" id="button" value="Add Customer Now" />

    </label></td>

  </tr>

</table>

</form>

    <br />

  <br />

  </div>

  </div>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/244842-help-with-form-post/
Share on other sites

Make sure your If statement is coming through as true. I'm assuming there's nothing wrong with this code block because

if (isset($_POST['customer_name']) && isset($_POST['address']) && isset($_POST['city'])&& isset($_POST['state'])&& isset($_POST['zip_code']) && isset($_POST['phone_number']) && isset($_POST['email'])&& isset($_POST['order_number'])&& isset($_POST['order_date'])&& isset($_POST['medication'])&& isset($_POST['comment_box'])&& isset($_POST['extra'])){

This line never gets executed

header("location: customer_list.php");

Link to comment
https://forums.phpfreaks.com/topic/244842-help-with-form-post/#findComment-1257746
Share on other sites

I still need help with this my error must be on the insert to statement no values are stored in my database

 

this is how my table is structure please help I need to finish this so I can start with my next project I have try changing different things around but no luck and no errors thanks for all your help

 

id

customer_name

address

city

state

zip code

phone number

email

order number

order date

medication

comment box

extra

Link to comment
https://forums.phpfreaks.com/topic/244842-help-with-form-post/#findComment-1258404
Share on other sites

This works fine for me...

 

 

 <?php
  
  {

  $customer_name= mysql_real_escape_string($_POST['customer_name']);
   $address = mysql_real_escape_string($_POST['address']);
   $city = mysql_real_escape_string($_POST['city']);
   $state = mysql_real_escape_string($_POST['state']);
   $zip_code = mysql_real_escape_string($_POST['zip_code']);
   $phone_number = mysql_real_escape_string($_POST['phone_number']);
   $email = mysql_real_escape_string($_POST['email']);
   $order_number = mysql_real_escape_string($_POST['order_number']);
   $order_date = mysql_real_escape_string($_POST['order_date']);
   $medication = mysql_real_escape_string($_POST['medication']);
   $comment_box = mysql_real_escape_string($_POST['comment_box']);
   $extra = mysql_real_escape_string($_POST['extra']);




$sql = "INSERT INTO users (customer_name, address, city, state, zip_code, phone_number, email, order_number, order_date, medication, comment_box, extra, date_added) VALUES ('$customer_name','$address','$city','$state','$zip_code','$phone_number','$email',$order_number','$order_date','$medication','$comment_box','$extra');"; 

$db->exec($sql);

}
?>

Link to comment
https://forums.phpfreaks.com/topic/244842-help-with-form-post/#findComment-1258417
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.