1

I have been trying all different ideas from different threads around the internet but i cant seem to find any ideas why my form will not submit or reset the changes i have made to the data. The code works to pull the data from the data base but when i make changes the submit and reset buttons do nothing.

<?php
session_start();
//check session first
if (!isset($_SESSION['employee_id'])){
    echo "You are not logged in!";
    exit();
}else{
    //include the header
    include ("../includes/managerheader.php");
    require_once ('../../mysqli_connect.php');
    $customer_id=$_GET['customer_id']; 
    $query = "SELECT * FROM customers WHERE customer_id=$customer_id"; 
    $result = @mysqli_query ($dbc, $query);
    $num = mysqli_num_rows($result);
    if ($num > 0) { // If it ran OK, display all the records.
        while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
?>
            <form action="customerupdate2.php" method="post">
            Customer ID: <input name="customer_id" size=50 value="<? echo $row['customer_id']; ?>"></br></br>
            First Name: <input name="first_name" size=50 value="<? echo $row['first_name']; ?>"><p>
            Last Name: <input name="last_name" size=50 value="<? echo $row['last_name']; ?>"><p>
            Email Address: <input name="email" size=50 value="<? echo $row['email']; ?>"><p>
            Password: <input name="password" size=50 value="<? echo $row['password']; ?>"><p>
            Address: <input name="address" size=50 value="<? echo $row['address']; ?>"><p>
            City: <input name="city" size=50 value="<? echo $row['city']; ?>"><p>
            State: <input name="state" size=50 value="<? echo $row['state']; ?>"><p>
            Zip: <input name="zip" size=50 value="<? echo $row['zip']; ?>"><p>
            Telephone: <input name="telephone" size=50 value="<? echo $row['telephone']; ?>"><p>
            Payment Type: <input name="payment_type" size=50 value="<? echo $row['payment_type']; ?>"><p>
            Card Number: <input name="card_number" size=50 value="<? echo $row['card_number']; ?>"><p>
            <input type="submit" value="update">
            <input type="reset" value="reset">
            <input type="hidden" name="customer_id" value="<? echo $row['customer_id']; ?>">
            </form>
<?
        } //end while statement
    } //end if statement
    mysqli_close($dbc);
    //include the footer
    include ("../includes/footer.php");
}
?>

The action of the form is linked to this:

<?php
session_start();
//check the session
if (!isset($_SESSION['manager'])){
    echo "You are not logged in!";
    exit();
}else{
    //include the header
    include ("../includes/managerheader.php");
    require_once ('../../mysqli_connect.php');
    #execute UPDATE statement
    $first_name = mysqli_real_escape_string($dbc, $_POST['first_name']);
    $last_name = mysqli_real_escape_string($dbc, $_POST['last_name']);
    $email = mysqli_real_escape_string($dbc, $_POST['email']);
    $password = mysqli_real_escape_string($dbc, $_POST['password']);
    $address = mysqli_real_escape_string($dbc, $_POST['address']);
    $city = mysqli_real_escape_string($dbc, $_POST['city']);
    $state = mysqli_real_escape_string($dbc, $_POST['state']);
    $zip = mysqli_real_escape_string($dbc, $_POST['zip']);
    $telephone = mysqli_real_escape_string($dbc, $_POST['telephone']);
    $payment_type = mysqli_real_escape_string($dbc, $_POST['payment_type']);
    $card_number = mysqli_real_escape_string($dbc, $_POST['card_number']);  


    $query = "UPDATE employees SET employe_id='$employe_id',first_name='$first_name',last_name='$last_name',email='$email',
    password='$password',address='$address',city='$city',state='$state',zip='$zip',
    telephone='$telephone',payment_type='$payment_type',card_number='$card_number', WHERE id='$id'"; 
    $result = @mysqli_query ($dbc, $query); 
    if ($result){
        echo "<center><p><b>The selected customer has been updated.</b></p>"; 
        echo "<a href=managerloggedin.php>Home</a></center>"; 
    }else {
        echo "<p>The customer could not be updated due to a system error" . mysqli_error() . "</p>"; 
    }
    mysqli_close($dbc);
    //include the footer
    include ("../includes/footer.php");
}

?>
Joe C
  • 11
  • 2
  • 2
    Unrelated to your actual problem, but: You have a lot of opening `

    ` tags in your form which aren't closed anywhere...

    – Johannes Aug 07 '18 at 22:59
  • i replaced them earlier with to ensure they were not causing some sort of formatting problem. they are just giving simple spacing for the form as is. – Joe C Aug 07 '18 at 23:03
  • 1
    still, that's invalid HTML and can only work in browsers which tolerate and correct these errors. – Johannes Aug 07 '18 at 23:04
  • Invalid HTML causes unpredictable results. First fix that then see if things work – RiggsFolly Aug 07 '18 at 23:13
  • 1
    Your script is wide open to [SQL Injection Attack](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Even [if you are escaping inputs, its not safe!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) Use [prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) in either the `MYSQLI_` or `PDO` API's – RiggsFolly Aug 07 '18 at 23:14
  • Your problem description is not really clear, but this doesn't look quite right: ` echo $row['customer_id']; ?>` . That should either be `` or (using the shortcut syntax) `=$row['customer_id']; ?>` – Johannes Aug 07 '18 at 23:17
  • Your script does not actually do anything specific based upon which button you press. You always just refresh the page with the current contents of the database. Its not surprising that you see no changes when you press either button – RiggsFolly Aug 07 '18 at 23:17
  • 1
    In case `short tags` are not turned on on your PHP use ` – RiggsFolly Aug 07 '18 at 23:18
  • i added the form action code as well. i fixed all the open

    tags and still nothing. The reset doesn't return the customer data to before any changes either.

    – Joe C Aug 07 '18 at 23:46

0 Answers0