mister2quick Posted April 29, 2009 Share Posted April 29, 2009 I apologize ahead of time if this is a n00b question, but i'm trying to scrape the rust off from 6 years ago. I would like to edit entries in the database and here's a simple breakdown of how i have it set up: page 1: view database and select entry via ID# (submit via form page 2) *WORKING* page 2: I would like to input the row information into text boxes to allow for ease of editing. Example- Name: [box containing name], Address: [box containing address], etc... (submit via form to page 3) Page 3: Update database with new information $_POST from page 2 *WORKING* What would be the easiest way to do this, or is there a better way to do this than what I am trying to accomplish? Any and all help is greatly appreciated, thanks! Link to comment https://forums.phpfreaks.com/topic/156145-select-and-update-command-question/ Share on other sites More sharing options...
Ken2k7 Posted April 29, 2009 Share Posted April 29, 2009 Seems like they're working. Is there a problem? Is it very slow and you want an easier way? Link to comment https://forums.phpfreaks.com/topic/156145-select-and-update-command-question/#findComment-821963 Share on other sites More sharing options...
revraz Posted April 29, 2009 Share Posted April 29, 2009 Your logic looks fine. Link to comment https://forums.phpfreaks.com/topic/156145-select-and-update-command-question/#findComment-822007 Share on other sites More sharing options...
mister2quick Posted April 29, 2009 Author Share Posted April 29, 2009 Here's some code snippets from the pages. Page 1: <form id="form1" name="form1" method="post" action="admin_editing.php"> <label><br /> ID#: <input name="VEND_CODE" type="text" id="VEND_CODE" size="3" /> </label> <p> <label> <input type="submit" name="submit" id="submit" value="Submit" /> </label> </p> </form> Page 2: <form id="form1" name="form1" method="post" action="admin_edited.php"> <?php $code = $_POST['VEND_CODE']; // Make a MySQL Connection mysql_connect("localhost", "kioskUser", "areallylongpasswordusuallymeetstherequirementsofsecuritystandards") or die(mysql_error()); mysql_select_db("vendor") or die(mysql_error()); // Select a row of information into the table "vendor" mysql_query("SELECT * FROM vendor WHERE VEND_CODE= $code") or die(mysql_error()); //Input data into text boxes to edit //$agency = vendor.VEND_AGENCY; //$address = vendor.VEND_ADDRESS; //$phone = vendor.VEND_PHONE; //$website = vendor.VEND_WEBSITE; //$type = vendor.TYPE_CODE; //$show = vendor.VEND_SHOW; ?> <p> <label> <input type="submit" name="submit" id="submit" value="Submit" /> </label> </p> </form> and finally Page 3: <?php $code = $_POST['VEND_CODE']; $agency = $_POST['VEND_AGENCY']; $address = $_POST['VEND_ADDRESS']; $phone = $_POST['VEND_PHONE']; $website = $_POST['VEND_WEBSITE']; $type = $_POST['TYPE_CODE']; $show = $_POST['VEND_SHOW']; // Make a MySQL Connection mysql_connect("localhost", "kioskUser", "areallylongpasswordusuallymeetstherequirementsofsecuritystandards") or die(mysql_error()); mysql_select_db("vendor") or die(mysql_error()); // Insert a row of information into the table "vendor" mysql_query("UPDATE vendor VEND_AGENCY = '$agency', VEND_ADDRESS = '$address', VEND_PHONE = '$phone', VEND_WEBSITE = '$website', TYPE_CODE = '$type', VEND_SHOW = '$show' WHERE VEND_CODE=$code;") or die(mysql_error()); echo "Data updated Successfully!"; echo "<br/>"; echo "You will be redirected back to the edit page in 5 seconds"; ?> My issue lies on page 2: how can i get the SELECT fields to populate the editable text boxes? I'm not exactly sure how to code it. Link to comment https://forums.phpfreaks.com/topic/156145-select-and-update-command-question/#findComment-822019 Share on other sites More sharing options...
revraz Posted April 29, 2009 Share Posted April 29, 2009 You need to FETCH the data first, then you can populate the form with the variables from the Database. Link to comment https://forums.phpfreaks.com/topic/156145-select-and-update-command-question/#findComment-822029 Share on other sites More sharing options...
Ken2k7 Posted April 29, 2009 Share Posted April 29, 2009 Page two: Just one question - is VEND_CODE a unique code that has only one entry in the DB? If so, you can add a LIMIT 1 to the query. <?php // Select a row of information into the table "vendor" $result = mysql_query("SELECT * FROM vendor WHERE VEND_CODE='$code' LIMIT 1") or die(mysql_error()); $row = mysql_fetch_assoc($result); ?> <input type="text" name="VEND_AGENCY" value="<?php echo $row['VEND_AGENCY']; ?>" /> . . . You can fill in the rest with that right? Page three: Forgot the SET keyword in UPDATE query and quotes on VEND_CODE mysql_query("UPDATE vendor SET VEND_AGENCY = '$agency', VEND_ADDRESS = '$address', VEND_PHONE = '$phone', VEND_WEBSITE = '$website', TYPE_CODE = '$type', VEND_SHOW = '$show' WHERE VEND_CODE='$code';") Link to comment https://forums.phpfreaks.com/topic/156145-select-and-update-command-question/#findComment-822033 Share on other sites More sharing options...
mister2quick Posted April 29, 2009 Author Share Posted April 29, 2009 That was exactly what i was looking for! Thank you for the quick answer! My last question deals with Drop down menus: I have 2 drop down menus in the form: TYPE_CODE (int) and VEND_SHOW (varchar). (Code has 16 options, show has 2) Is there any way i can get the options to auto-select based on their existing condition? Vendor Category: <select name="TYPE_CODE" id="TYPE_CODE" > <option value="0">--SELECT A CATEGORY--</option> <option value="1">Category1</option> Make Vendor Visible?: <select name="VEND_SHOW" id="VEND_SHOW" > <option value="YES">YES</option> <option value="NO">NO</option> </select> Link to comment https://forums.phpfreaks.com/topic/156145-select-and-update-command-question/#findComment-822141 Share on other sites More sharing options...
Ken2k7 Posted April 29, 2009 Share Posted April 29, 2009 Is there any way i can get the options to auto-select based on their existing condition? I don't fully understand. What existing condition? Details, details. =] Link to comment https://forums.phpfreaks.com/topic/156145-select-and-update-command-question/#findComment-822143 Share on other sites More sharing options...
revraz Posted April 29, 2009 Share Posted April 29, 2009 If they are stored in the DB, sure. Just read the setting and in your code you can have "selected" as a variable, and show it if it matches. Link to comment https://forums.phpfreaks.com/topic/156145-select-and-update-command-question/#findComment-822146 Share on other sites More sharing options...
mister2quick Posted April 29, 2009 Author Share Posted April 29, 2009 Is there any way i can get the options to auto-select based on their existing condition? I don't fully understand. What existing condition? Details, details. =] The information stored in the database for TYPE_CODE is integers 1-16, and each corresponds to a different category. The VEND_SHOW is a varchar that is set to either YES or NO in the database. So if the type code is set to 1, then the drop down menu for type_code would automatically change to "category 1" and if the vend_show is set to 'YES' then it would change to 'YES' in the options. Link to comment https://forums.phpfreaks.com/topic/156145-select-and-update-command-question/#findComment-822160 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.