rendered paste body<?php require_once('../core/db.php');require_once('../core/secure.php'); # id to edit is '$editid' declared in following conditionif( $_REQUEST['action'] != 'update' && ( $editid = intval($_REQUEST['id']) ) > 0 ){ # grab info $query = "select id, catid, company_name, contact_name, address, city, state, zipcode, phone, email, url from vendors where id=". $editid; $rsVendor = mysql_query($query); if( !$rsVendor || @mysql_num_rows($rsVendor) < 1 ) die('That ID does not exist'); $query = "select catid, name from category order by name asc"; $rsCategory = mysql_query($query); $vendor = mysql_fetch_object($rsVendor);?><html> <head> <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> <link rel=stylesheet href="../style/style.css" /> </head><body> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="header"> <tr> <td align="center"><p class="pagetitle">Vendor Details</p></td> </tr> </table> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td><img src="../i/section_top_left.gif" /></td> <td width="100%" background="../i/section_top_bg.gif" valign="bottom" align="center"> <div style="font-family:verdana;font-size:10pt;color:#5D729B"><b>Add Vendor</b></div> </td> <td width="1" height="30"><img src="../i/section_top_right.gif" /></td> </tr> <tr> <td width="15" height="4"><img src="../i/section_top_left2.gif" /></td> <td background="../i/section_top_bg2.gif"></td> <td width="15" height="4"><img src="../i/section_top_right2.gif" /></td> </tr> <tr> <td colspan="3"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="7" background="../i/section_middle_left.gif"></td> <td> <!-- Start Form --> <form action="<?=$_SERVER['PHP_SELF']?>?action=update&id=<?=$editid?>" method="post"> <table width="100%" border="0" cellpadding="5" cellspacing="0"> <tr> <td class="tdrow2">Company Name:</td><td class="tdrow2" >Contact name:</td> </tr><tr> <td class="tdrow3" ><input type="text" size="40" name="company_name" value="<?= $vendor["company_name"]?>"></td> <td class="tdrow3"><input type="text" size="40" name="contact_name" value="<?= $vendor["contact_name"]?>"></td> </tr><tr> <td class="tdrow2">Address:</td><td class="tdrow2">City:</td> </tr><tr> <td class="tdrow3"><input type="text" size="40" name="address" value="<?= $vendor["address"]?>"></td> <td class="tdrow3"><input type="text" size="40" name="city" value="<?= $vendor["city?"]>"></td> </tr><tr> <td class="tdrow2">State:</td><td class="tdrow2">Zipcode:</td> </tr><tr> <td class="tdrow3"><input type="text" size="40" name="state" value="<?= $vendor["state"]?>"></td> <td class="tdrow3"><input type="text" size="40" name="zipcode" value="<?= $vendor["zipcode"]?>"></td> </tr><tr> <td class="tdrow2">Phone:</td><td class="tdrow2">Email:</td> </tr><tr> <td class="tdrow3"><input type="text" size="40" name="phone" value="<?= $vendor["phone"]?>"></td> <td class="tdrow3"><input type="text" size="40" name="email" value="<?= $vendor["email"]?>"></td> </tr><tr> <td class="tdrow2">URL:</td><td class="tdrow2">Select a category:</td> </tr><tr> <td class="tdrow3"> <input type="text" size="40" name="url" value="<?= $vendor["url?"]>"></td> <td class="tdrow3" valign="top">Category<Br /> <select class="textfield" name="catid"> <?php while ( $cat_row = mysql_fetch_array($rsCategory, MYSQL_ASSOC) ) { echo "<option value=\"". $cat_row["catid"] ."\""; if ( $vendor["catid"] == $cat_row["catid"] ) echo " selected=\"selected\""; echo ">". $cat_row["name"] ."</option>\n"; } ?> </option> </select> </td> </tr><tr> <td class="tdrow1" bgcolor="#FCFCFC" colspan="2" align="center"> <input type="hidden" name="id" value="<?= $editid?>"> <input type="submit" value="Update"> </td> </tr> </table> </form> </td> <td width="7" background="../i/section_middle_right.gif"></td> </tr> </table> </td> </tr> </table></body></html><?php} elseif( $_REQUEST['action'] == 'update' && ( $editid = intval($_REQUEST['id']) ) > 0 ) { ## id to edit is $editid, declared in condition above // check for errors $err = false; // currently, there is no errors. $errmsg = '<b>Error<b><br>'; // empty error msg. msg with no current errors. // check to see if content field is empty or not. if so, make error. if( empty($_POST['contact_name']) ) { $err = true; // there is now an error. $errmsg .= 'Content is a required field and must be filled out.<br>'; // append an error msg to the end of $errmsg } if($err) die($errmsg); // if there's an error ( $err = true ), let them know and exit. if(!$err) // if no errors, do the foloowing { // store the fields into an easier writeable variable. so you dont have to type $_POST[''] to use it everytime. $contact_name = $_POST['contact_name']; $company_name = $_POST['business_name']; //connect to the mysql server //insert the new info into the database $query = "update contact set contact_name='". $contact_name ."', business_name='". $business_name ."' where id = '".mysql_real_escape_string($editid)."'"; $result = mysql_query($query) or die(mysql_error()); echo '<a href="'.$_SERVER['PHP_SELF'].'"> return </a>'; }}?>