PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 6th, 2013, 12:38 PM
Cyu504 Cyu504 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2013
Posts: 1 Cyu504 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 58 sec
Reputation Power: 0
Forms: POST & GET - How can I pass the ID variable to an Update query - PHP/MYSQLI?

Hello. I'm a beginner in php and mysqli. I need to create a form that allows users to update data for a school project. I've been stuck at this for two days, but I can't figure out why my ID variable is not passed to the update query correctly. For example, I made some changes for an existing customer (i.e., ID#3), but all the changes are reflected in the record with ID # 1. I've looked at my code many times and asked people but we are unclear what the issue is. I tried "var_dump". It shows that $_POST['customer_id'] is string(3) " 1" . But I'm not sure how to fix it. Can someone take a look and give me some guidance on this? Thanks a lot. Your help is greatly appreciated!

Here is part of the code in my main php file:
PHP Code:
<div>
                <
form method="post" action="updatecustomer.php">
                    <
fieldset>
                        <
legend>Update Existing Customer</legend>
                        <
li>Customer ID:    
                        <
select name="customer_id">
            <?
php
            
if(!($stmt $mysqli->prepare("SELECT customer_id FROM customer"))){
                echo 
"Prepare failed: "  $stmt->errno " " $stmt->error;
            }

            if(!
$stmt->execute()){
                echo 
"Execute failed: "  $mysqli->connect_errno " " $mysqli->connect_error;
            }
            if(!
$stmt->bind_result($customer_id)){
                echo 
"Bind failed: "  $mysqli->connect_errno " " $mysqli->connect_error;
            }
            while(
$stmt->fetch()){
                echo 
'<option value="'.$customer_id.'">'.$customer_id.'</option>\n';
            }
            
$stmt->close();
            
?> 


Here is the updatecustomer.php

PHP Code:
if(!($stmt $mysqli->query("UPDATE customer SET fName=?, lName=?, email=?, phone_number=?, address_no=?, address_street1=?, 
    address_street2=?, address_city=?, address_state=?, address_zip=? WHERE customer_id=?"
))){
    echo 
"Prepare failed: "  $stmt->errno " " $stmt->error;
}

if(!(
$stmt->bind_param("sssiissssii",$_POST['fName'],$_POST['lName'],$_POST['email'],$_POST['phone_number'], $_POST['address_no'],
    
$_POST['address_street1'],$_POST['address_street2'],$_POST['address_city'],$_POST['address_state'], $_POST['address_zip'], $_POST['customer_id']))){
    echo 
"Bind failed: "  $stmt->errno " " $stmt->error;
}
if(!
$stmt->execute()){
    echo 
"Execute failed: "  $stmt->errno " " $stmt->error;
} else {
    echo 
"Updated " $stmt->affected_rows " rows to customer.";
    
var_dump($_POST['customer_id']);

}


$stmt->close(); 

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Forms: POST & GET - How can I pass the ID variable to an Update query - PHP/MYSQLI?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap