Ugluth Posted October 31, 2008 Share Posted October 31, 2008 Hello there, i got a page where the administrator of the site is supposed to go and modify data about a customer. I got a dropdown to show the customer names, and after a customer is selected i show all his data on some textboxes. If the user hits the second submit its supposed to do an update query on the specified customer. Anyway, here's the code <?php session_start(); include("dbconn.php"); $customer = $_POST['menuCust']; $query_menu=("SELECT Customer_ID, Customer_Name, Customer_Surname FROM customers"); $result_menu = mysql_query($query_menu) or die("Query failed: " . mysql_error()); $query_insert = ("UPDATE customers SET Customer_ID = '".$_POST['txtID']."', Customer_Name = '".$_POST['txtName']."', Customer_Surname = '".$_POST['txtSurname']."', Phone = '".$_POST['txtPhone']."', Join_Date = '".$_POST['txtDate']."' WHERE Customer_ID = '$customer'"); $query_customer = ("SELECT Customer_ID, Customer_Name, Customer_Surname, Phone, Join_Date FROM customers WHERE Customer_ID = '$customer'"); $result_customer = mysql_query($query_customer) or die ("Query failed: " . mysql_error()); if (isset($_POST['txtID'])) { mysql_query($query_insert); $update = "Update was succesfull"; } ?> Here's the dropdown <form id="frmMenu" name="frmCust" method="post" action="edit_customers.php"> Customers <select name="menuCust"> <option value=" "> </option> <?php while ($line = mysql_fetch_array($result_menu, MYSQL_NUM)) { echo "<option value=\"$line[0]\""; if ($_POST["menuCust"]==$line[0]) echo " selected" ; echo ">".$line[1]." ".$line[2]." </option>" ; } ?> </select> <input type="submit" name="Submit" value="Submit" /> </form> And finally here are the textboxes <form id="frmCust" name="form1" method="post" action="edit_customers.php"> <?php if (isset($customer)){ while ($line = mysql_fetch_array($result_customer, MYSQL_NUM)) { ?> <p>Customer ID <input name="txtID" type="text" id="txtID" value="<?php echo $line[0]; ?>" /> </p> <p>Name <input name="txtName" type="text" id="txtName" value="<?php echo $line[1]; ?>" /> </p> <p>Surname <input name="txtSurname" type="text" id="txtSurname" value="<?php echo $line[2]; ?>" /> </p> <p>Phone <input name="txtPhone" type="text" id="txtPhone" value="<?php echo $line[3]; ?>" /> </p> <p>Join Date <input name="txtDate" type="text" id="txtDate" value="<?php echo $line[4]; ?>" /> <input type="submit" name="Submit2" value="Submit" /> </p> <?php } } ?> </form> <?php echo $update; $update = " "; mysql_free_result($result_customer); mysql_free_result($result_menu); ?> My problem is that it wont update even though the query works, when i used if (!mysql_query($query_insert)) { die(mysql_error()); }else{ $update= "Update was succesfull"; } it did update. So any help with it please? thanks in advance! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.