Jump to content

aeafisme23

Members
  • Posts

    121
  • Joined

  • Last visited

    Never

Everything posted by aeafisme23

  1. text heh, you can tell im not a true programmer.... CREATE TABLE `dealer` ( `id` mediumint(10) NOT NULL auto_increment, `dealer` varchar(65) NOT NULL default '', `address` varchar(65) NOT NULL default '', `address2` varchar(65) NOT NULL default '', `city` varchar(65) NOT NULL default '', `state` varchar(65) NOT NULL default '', `zip` int(10) NOT NULL default '0', `areacode` int(10) NOT NULL default '0', `number` varchar(20) NOT NULL default '0', `tollnumber` varchar(25) NOT NULL default '0', `ulweb` varchar(65) NOT NULL default '', `email` varchar(65) NOT NULL default '', ***was text*** now varchar? `dealerinfo` varchar(200) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ;
  2. If you are needing a better idea http://www.unitedtruckdesign.com/dealers/main_login.php user: > user pass: > pass *aint i smart lol then paste this URL in: http://www.unitedtruckdesign.com/dealers/view_records_test.php?search=574 ; you must paste this url because the login system is using sessions and it is an unlinked page from the options there are right now! Then click the edit button and you will see that it posts all the data but dealerinfo (wierd trying to figure that out right now) but it will let you think it's updated when you hit update/submit button but you can click on view records and hit in 574 and you will see that it did not update it. I hope this helps. Please do not delete record as i do not feel like re-creating test area codes. Thanks!
  3. Ok, i got my database to fill in my form for updating using an id structure and it lets me edit the text in each field, but when i hit update it says it was successful but when i go check my records via php form and via the database it really did not update at all and it posts back to its original data. I am so close to getting this to work yet im stumped! *this is not really a repost of my original, it's a different problem i feel. It has to be something to do with the Update or Posting to itself and not keeping the data. Thanks so much everyone! <?php //Get variables from config.php to connect to mysql server require 'config.php'; $connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error()); $selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error()); $codes = $_GET['id']; if(isset($_REQUEST["id"])) $nId=$_REQUEST["id"]; // will be requested.. from search page // you have selected the DATABASE now you can select the table and assign this on variable $sTable="dealer"; $sAction="Update"; // this is for update part if($_REQUEST['sAction']=="Update") { $query = "UPDATE `dealer` SET `dealer` = " . mysql_real_escape_string ( $_POST [ 'dealer' ] ) . " `address` = " . mysql_real_escape_string ( $_POST [ 'address' ] ) . " `address2` = " . mysql_real_escape_string ( $_POST [ 'address2' ] ) . " `city` = " . mysql_real_escape_string ( $_POST [ 'city' ] ) . " `state` = " . mysql_real_escape_string ( $_POST [ 'state' ] ) . " `zip` = " . mysql_real_escape_string ( $_POST [ 'zip' ] ) . " `areacode` = " . mysql_real_escape_string ( $_POST [ 'areacode' ] ) . " `number` = " . mysql_real_escape_string ( $_POST [ 'number' ] ) . " `tollnumber` = " . mysql_real_escape_string ( $_POST [ 'tollnumber' ] ) . " `ulweb` = " . mysql_real_escape_string ( $_POST [ 'ulweb' ] ) . " `email` = " . mysql_real_escape_string ( $_POST [ 'email' ] ) . " `dealerinfo` = " . mysql_real_escape_string ( $_POST [ 'dealerinfo' ] ) . " WHERE `ID` = " . mysql_real_escape_string ( $_REQUEST["id"] ); mysql_query($query); echo "Entry updated successfully!"; } // this value will be passed from the previous page and the text field will be filled with the corresponding ID if(isset($_REQUEST['up']) && isset($nId)) { $sql="select * from ".$sTable." where id=".$_REQUEST['id'].""; // here id is the id column in the table $result=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_fetch_array($result)) { $dealer=$row['dealer']; $address=$row['address']; $address2=$row['address2']; $city=$row['city']; $state=$row['state']; $zip=$row['zip']; $areacode=$row['areacode']; $number=$row['number']; $tollnumber=$row['tollnumber']; $ulweb=$row['ulweb']; $email=$row['email']; $dealerinfo=$row['dealerinfo']; $sAction="Update"; } } // end ?> <form id="update" name="update" method="post" action="<?php $_SERVER['PHP_SELF'] ?>"> <input type='hidden' name='id' value="<?php echo $nId ?>"> <input type='hidden' name='sAction' value="<?php echo $sAction ?>" > <table width="700" cellpadding="0" cellpsacing="0" border="1" bordercolor="#000000"> <tr> <td> <table width="700" cellpadding="0" cellpsacing="0" border="0" bordercolor="#000000"> <tr> <td align="left" width="180">Dealer/ Distributor Name*</td> <td width="320" align="left"><input type="text" name="dealer" value="<?php echo $dealer ?>" size="40"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">Street Address</td> <td width="320" align="left"><input type="text" name="address" value="<?php echo $address ?>" size="40"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">Address 2</td> <td width="320" align="left"><input type="text" name="address2" value="<?php echo $address2 ?>" size="40"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">City*</td> <td width="320" align="left"><input type="text" name="city" value="<?php echo $city ?>" size="30"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">State*</td> <td width="320" align="left"><input type="text" name="state" value="<?php echo $state ?>" size="20"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">Zip*</td> <td width="320" align="left"><input type="text" name="zip" value="<?php echo $zip ?>" size="10"></td> <td align="left" width="200">ex) 20100</td> </tr> <tr> <td align="left" width="180">Area Code*</td> <td width="320" align="left"><input type="text" name="areacode" value="<?php echo $areacode ?>" size="10"></td> <td align="left" width="200">ex) 489</td> </tr> <tr> <td align="left" width="180">Local Number*</td> <td width="320" align="left"><input type="text" name="number" value="<?php echo $number ?>" size="20"></td> <td align="left" width="200">ex) 123-4567</td> </tr> <tr> <td align="left" width="180">Toll Free Number</td> <td width="320" align="left"><input type="text" name="tollnumber" value="<?php echo $tollnumber ?>" size="20"></td> <td align="left" width="200">ex) 1 800-123-4567</td> </tr> <tr> <td align="left" width="180">Website Address</td> <td width="320" align="left"><input type="text" name="ulweb" value="<?php echo $ulweb ?>" size="40"></td> <td align="left" width="200">ex) www.google.com</td> </tr> <tr> <td align="left" width="180">Email Address</td> <td width="320" align="left"><input type="text" name="email" value="<?php echo $email ?>" size="40"></td> <td align="left" width="200">(i.e. “Sales” or persons name)</td> </tr> <tr> <td align="left" width="180" valign="top">Dealer Information</td> <td width="320" align="left"><textarea name="dealerinfo" value="<?php echo $dealerinfo ?>" cols="40" rows="6"></textarea></td> <td align="left" width="200"></td> </tr> <tr> <td colspan="3"> <p align="center"><input type="submit" value="Update record"></p> </td> </tr> </table> </td></tr></table> </form><br />* denotes a Required Field</center> <?php } ?>
  4. I tried this and took out alot of code, i am at the point where im just trying to manipulate code, however, i think i may have taken out some important elements let alone bad sql.... If anyone thinks that this may be easier to help me on by me sending them a .zip file i would be more than happy to send anyone it!!! Just let me know, i can also be contacted at randybennett23@hotmail.com | sorry if it is against php freak rules to display a msn screen name, let me know if im not and ill edit post. Thanks! NEW edit.php <?php //Get variables from config.php to connect to mysql server require 'config.php'; $connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error()); $selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error()); //$codes = ((int)($_GET['id'])); $codes = $_GET['id']; $searchcode_query = "SELECT * FROM dealer WHERE id = '".$codes."'"; $sql_delete_query = "UPDATE `dealer` SET `dealer` = " . mysql_real_escape_string ( $_POST [ 'dealer' ] ) . " `address` = " . mysql_real_escape_string ( $_POST [ 'address' ] ) . " `address2` = " . mysql_real_escape_string ( $_POST [ 'address2' ] ) . " `city` = " . mysql_real_escape_string ( $_POST [ 'city' ] ) . " `state` = " . mysql_real_escape_string ( $_POST [ 'state' ] ) . " `zip` = " . mysql_real_escape_string ( $_POST [ 'zip' ] ) . " `areacode` = " . mysql_real_escape_string ( $_POST [ 'areacode' ] ) . " `number` = " . mysql_real_escape_string ( $_POST [ 'number' ] ) . " `tollnumber` = " . mysql_real_escape_string ( $_POST [ 'tollnumber' ] ) . " `ulweb` = " . mysql_real_escape_string ( $_POST [ 'ulweb' ] ) . " `email` = " . mysql_real_escape_string ( $_POST [ 'email' ] ) . " `dealerinfo` = " . mysql_real_escape_string ( $_POST [ 'dealerinfo' ] ) . " WHERE `id` = " .$codes." ); $result = mysql_query($searchcode_query) or die("Error executing MySQL SELECT query<br />".mysql_error()); if( mysql_affected_rows() != 1 ) { print "<center>No such dealer exists anymore<br><br>Please go back to <a href=\"add_record.php\">add a record</a> | <a href=\"view_records.php\">view a record</a></center>"; } else { mysql_free_result($result); $result = mysql_query($sql_delete_query) or die("Error executing MySQL Update query<br />".mysql_error()); echo "<center>Updated record id = $codes<br><br>"; echo "Please go back to <a href=\"add_record.php\">add a record</a> | <a href=\"view_records.php\">view a record</a></center>"; } ?> <form id="update" name="update" method="post" action="<?php $_SERVER['PHP_SELF'] ?>"> <input type='hidden' name='id' value="<?php echo $nId ?>"> <input type='hidden' name='sAction' value="<?php echo $sAction ?>" > <table width="700" cellpadding="0" cellpsacing="0" border="1" bordercolor="#000000"> <tr> <td> <table width="700" cellpadding="0" cellpsacing="0" border="0" bordercolor="#000000"> <tr> <td align="left" width="180">Dealer/ Distributor Name*</td> <td width="320" align="left"><input type="text" name="dealer" value="<?php echo $dealer ?>" size="40"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">Street Address</td> <td width="320" align="left"><input type="text" name="address" value="<?php echo $address ?>" size="40"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">Address 2</td> <td width="320" align="left"><input type="text" name="address2" value="<?php echo $address2 ?>" size="40"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">City*</td> <td width="320" align="left"><input type="text" name="city" value="<?php echo $city ?>" size="30"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">State*</td> <td width="320" align="left"><input type="text" name="state" value="<?php echo $state ?>" size="20"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">Zip*</td> <td width="320" align="left"><input type="text" name="zip" value="<?php echo $zip ?>" size="10"></td> <td align="left" width="200">ex) 20100</td> </tr> <tr> <td align="left" width="180">Area Code*</td> <td width="320" align="left"><input type="text" name="areacode" value="<?php echo $areacode ?>" size="10"></td> <td align="left" width="200">ex) 489</td> </tr> <tr> <td align="left" width="180">Local Number*</td> <td width="320" align="left"><input type="text" name="number" value="<?php echo $number ?>" size="20"></td> <td align="left" width="200">ex) 123-4567</td> </tr> <tr> <td align="left" width="180">Toll Free Number</td> <td width="320" align="left"><input type="text" name="tollnumber" value="<?php echo $tollnumber ?>" size="20"></td> <td align="left" width="200">ex) 1 800-123-4567</td> </tr> <tr> <td align="left" width="180">Website Address</td> <td width="320" align="left"><input type="text" name="ulweb" value="<?php echo $ulweb ?>" size="40"></td> <td align="left" width="200">ex) www.google.com</td> </tr> <tr> <td align="left" width="180">Email Address</td> <td width="320" align="left"><input type="text" name="email" value="<?php echo $email ?>" size="40"></td> <td align="left" width="200">(i.e. “Sales” or persons name)</td> </tr> <tr> <td align="left" width="180" valign="top">Dealer Information</td> <td width="320" align="left"><textarea name="dealerinfo" value="<?php echo $dealerinfo ?>" cols="40" rows="6"></textarea></td> <td align="left" width="200"></td> </tr> <tr> <td colspan="3"> <p align="center"><input type="submit" value="Update record"></p> </td> </tr> </table> </td></tr></table> </form><br />* denotes a Required Field</center> <?php } ?> old.php <?php //Get variables from config.php to connect to mysql server require 'config.php'; $connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error()); $selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error()); $codes = $_GET['id']; if(isset($_REQUEST["id"])) $nId=$_REQUEST["id"]; // will be requested.. from search page // you have selected the DATABASE now you can select the table and assign this on variable $sTable="my_table"; $sAction="Update"; // this is for update part if($_REQUEST['sAction']=="Update") { $query = "UPDATE `dealer` SET `dealer` = " . mysql_real_escape_string ( $_POST [ 'dealer' ] ) . " `address` = " . mysql_real_escape_string ( $_POST [ 'address' ] ) . " `address2` = " . mysql_real_escape_string ( $_POST [ 'address2' ] ) . " `city` = " . mysql_real_escape_string ( $_POST [ 'city' ] ) . " `state` = " . mysql_real_escape_string ( $_POST [ 'state' ] ) . " `zip` = " . mysql_real_escape_string ( $_POST [ 'zip' ] ) . " `areacode` = " . mysql_real_escape_string ( $_POST [ 'areacode' ] ) . " `number` = " . mysql_real_escape_string ( $_POST [ 'number' ] ) . " `tollnumber` = " . mysql_real_escape_string ( $_POST [ 'tollnumber' ] ) . " `ulweb` = " . mysql_real_escape_string ( $_POST [ 'ulweb' ] ) . " `email` = " . mysql_real_escape_string ( $_POST [ 'email' ] ) . " `dealerinfo` = " . mysql_real_escape_string ( $_POST [ 'dealerinfo' ] ) . " WHERE `ID` = " . mysql_real_escape_string ( $_REQUEST["id"] ); mysql_query($query); echo "Entry updated successfully!"; } // this value will be passed from the previous page and the text field will be filled with the corresponding ID if(isset($_REQUEST['up']) && isset($nId)) { $sql="select * from ".$sTable." where id=".$_REQUEST['id'].""; // here id is the id column in the table $result=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_fetch_array($result)) { $dealer=$row['dealer']; $address=$row['address']; $address2=$row['address2']; $city=$row['city']; $state=$row['state']; $zip=$row['zip']; $areacode=$row['areacode']; $number=$row['number']; $tollnumber=$row['tollnumber']; $ulweb=$row['ulweb']; $email=$row['email']; $dealerinfo=$row['dealerinfo']; $sAction="Update"; } } // end ?> <form id="update" name="update" method="post" action="<?php $_SERVER['PHP_SELF'] ?>"> <input type='hidden' name='id' value="<?php echo $nId ?>"> <input type='hidden' name='sAction' value="<?php echo $sAction ?>" > <table width="700" cellpadding="0" cellpsacing="0" border="1" bordercolor="#000000"> <tr> <td> <table width="700" cellpadding="0" cellpsacing="0" border="0" bordercolor="#000000"> <tr> <td align="left" width="180">Dealer/ Distributor Name*</td> <td width="320" align="left"><input type="text" name="dealer" value="<?php echo $dealer ?>" size="40"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">Street Address</td> <td width="320" align="left"><input type="text" name="address" value="<?php echo $address ?>" size="40"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">Address 2</td> <td width="320" align="left"><input type="text" name="address2" value="<?php echo $address2 ?>" size="40"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">City*</td> <td width="320" align="left"><input type="text" name="city" value="<?php echo $city ?>" size="30"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">State*</td> <td width="320" align="left"><input type="text" name="state" value="<?php echo $state ?>" size="20"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">Zip*</td> <td width="320" align="left"><input type="text" name="zip" value="<?php echo $zip ?>" size="10"></td> <td align="left" width="200">ex) 20100</td> </tr> <tr> <td align="left" width="180">Area Code*</td> <td width="320" align="left"><input type="text" name="areacode" value="<?php echo $areacode ?>" size="10"></td> <td align="left" width="200">ex) 489</td> </tr> <tr> <td align="left" width="180">Local Number*</td> <td width="320" align="left"><input type="text" name="number" value="<?php echo $number ?>" size="20"></td> <td align="left" width="200">ex) 123-4567</td> </tr> <tr> <td align="left" width="180">Toll Free Number</td> <td width="320" align="left"><input type="text" name="tollnumber" value="<?php echo $tollnumber ?>" size="20"></td> <td align="left" width="200">ex) 1 800-123-4567</td> </tr> <tr> <td align="left" width="180">Website Address</td> <td width="320" align="left"><input type="text" name="ulweb" value="<?php echo $ulweb ?>" size="40"></td> <td align="left" width="200">ex) www.google.com</td> </tr> <tr> <td align="left" width="180">Email Address</td> <td width="320" align="left"><input type="text" name="email" value="<?php echo $email ?>" size="40"></td> <td align="left" width="200">(i.e. “Sales” or persons name)</td> </tr> <tr> <td align="left" width="180" valign="top">Dealer Information</td> <td width="320" align="left"><textarea name="dealerinfo" value="<?php echo $dealerinfo ?>" cols="40" rows="6"></textarea></td> <td align="left" width="200"></td> </tr> <tr> <td colspan="3"> <p align="center"><input type="submit" value="Update record"></p> </td> </tr> </table> </td></tr></table> </form><br />* denotes a Required Field</center> <?php } ?>
  5. Honestly that is one of the parts i was helped with by i believe xeon is his name on phpfreaks. Although here is code on how the id passes the information to my delete.php page (has other stuff like db conn). This page works very well and has no problem locating the information in say id=11 where as when i put the link in to show id=11 for edit.php it is not filling the data into the forms. I think my logic is bad... //$codes = ((int)($_GET['id'])); $codes = $_GET['id']; $searchcode_query = "SELECT * FROM dealer WHERE id = '".$codes."'"; $sql_delete_query = "DELETE FROM dealer WHERE id = '".$codes."'"; $result = mysql_query($searchcode_query) or die("Error executing MySQL SELECT query<br />".mysql_error()); if( mysql_affected_rows() != 1 ) { print "<center>No such dealer exists anymore<br><br>Please go back to <a href=\"add_record.php\">add a record</a> | <a href=\"view_records.php\">view a record</a></center>"; } else { mysql_free_result($result); $result = mysql_query($sql_delete_query) or die("Error executing MySQL DELETE query<br />".mysql_error()); echo "<center>Deleted record id = $codes<br><br>"; echo "Please go back to <a href=\"add_record.php\">add a record</a> | <a href=\"view_records.php\">view a record</a></center>"; } do i need to get rid of some stuff and do it like the delete except something like this (im way off but trying to figure out logic: $searchcode_query = "SELECT * FROM dealer WHERE id = '".$codes."'"; $sql_delete_query = "UPDATE FROM dealer WHERE id = '".$codes."'";
  6. I do not think i understand, are you telling me i need to change something or are you telling me that the code is looking for a null value...or..? Also if anyone new gets this too, take a look and see if you guys can figure out why the data is not displaying. Would it be easier if i post another topic and put current code in it? Thanks
  7. No the update does not work, even when they are blank and i put in values for them it does nothing, just re-posts to itself
  8. took out echos, then added closing brackets and it did not work, then i modified the bracket placement just to get it to show form and that was not working, but right now i converted back to originally what you told me about putting } at the end. Any more ideas? No i did not say opinions that you hate me lol jk, thanks!
  9. Updated code, unfortunately it is still not passing the data into the fields . any ideas, many thanks still! Also, could it be the while { part, should i make the form inside php or does that not matter? <?php //Get variables from config.php to connect to mysql server require 'config.php'; $connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error()); $selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error()); $codes = $_GET['id']; if(isset($_REQUEST["id"])) $nId=$_REQUEST["id"]; // will be requested.. from search page // you have selected the DATABASE now you can select the table and assign this on variable $sTable="my_table"; $sAction="Update"; // this is for update part if($_REQUEST['sAction']=="Update") { $query = "UPDATE `dealer` SET `dealer` = " . mysql_real_escape_string ( $_POST [ 'dealer' ] ) . " `address` = " . mysql_real_escape_string ( $_POST [ 'address' ] ) . " `address2` = " . mysql_real_escape_string ( $_POST [ 'address2' ] ) . " `city` = " . mysql_real_escape_string ( $_POST [ 'city' ] ) . " `state` = " . mysql_real_escape_string ( $_POST [ 'state' ] ) . " `zip` = " . mysql_real_escape_string ( $_POST [ 'zip' ] ) . " `areacode` = " . mysql_real_escape_string ( $_POST [ 'areacode' ] ) . " `number` = " . mysql_real_escape_string ( $_POST [ 'number' ] ) . " `tollnumber` = " . mysql_real_escape_string ( $_POST [ 'tollnumber' ] ) . " `ulweb` = " . mysql_real_escape_string ( $_POST [ 'ulweb' ] ) . " `email` = " . mysql_real_escape_string ( $_POST [ 'email' ] ) . " `dealerinfo` = " . mysql_real_escape_string ( $_POST [ 'dealerinfo' ] ) . " WHERE `ID` = " . mysql_real_escape_string ( $_REQUEST["id"] ); mysql_query($query); echo "Entry updated successfully!"; } // this value will be passed from the previous page and the text field will be filled with the corresponding ID if(isset($_REQUEST['up']) && isset($nId)) { $sql="select * from ".$sTable." where id=".$_REQUEST['id'].""; // here id is the id column in the table $result=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_fetch_array($result)) { $dealer=$row['dealer']; $address=$row['address']; $address2=$row['address2']; $city=$row['city']; $state=$row['state']; $zip=$row['zip']; $areacode=$row['areacode']; $number=$row['number']; $tollnumber=$row['tollnumber']; $ulweb=$row['ulweb']; $email=$row['email']; $dealerinfo=$row['dealerinfo']; $sAction="Update"; } } // end ?> <form id="update" name="update" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <input type='hidden' name='id' value="<?php echo $nId ?>"> <input type='hidden' name='sAction' value="<?php echo $sAction ?>" > <table width="700" cellpadding="0" cellpsacing="0" border="1" bordercolor="#000000"> <tr> <td> <table width="700" cellpadding="0" cellpsacing="0" border="0" bordercolor="#000000"> <tr> <td align="left" width="180">Dealer/ Distributor Name*</td> <td width="320" align="left"><input type="text" name="dealer" value="<?php echo $dealer ?>" size="40"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">Street Address</td> <td width="320" align="left"><input type="text" name="address" value="<?php echo $address ?>" size="40"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">Address 2</td> <td width="320" align="left"><input type="text" name="address2" value="<?php echo $address2 ?>" size="40"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">City*</td> <td width="320" align="left"><input type="text" name="city" value="<?php echo $city ?>" size="30"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">State*</td> <td width="320" align="left"><input type="text" name="state" value="<?php echo $state ?>" size="20"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">Zip*</td> <td width="320" align="left"><input type="text" name="zip" value="<?php echo $zip ?>" size="10"></td> <td align="left" width="200">ex) 20100</td> </tr> <tr> <td align="left" width="180">Area Code*</td> <td width="320" align="left"><input type="text" name="areacode" value="<?php echo $areacode ?>" size="10"></td> <td align="left" width="200">ex) 489</td> </tr> <tr> <td align="left" width="180">Local Number*</td> <td width="320" align="left"><input type="text" name="number" value="<?php echo $number ?>" size="20"></td> <td align="left" width="200">ex) 123-4567</td> </tr> <tr> <td align="left" width="180">Toll Free Number</td> <td width="320" align="left"><input type="text" name="tollnumber" value="<?php echo $tollnumber ?>" size="20"></td> <td align="left" width="200">ex) 1 800-123-4567</td> </tr> <tr> <td align="left" width="180">Website Address</td> <td width="320" align="left"><input type="text" name="ulweb" value="<?php echo $ulweb ?>" size="40"></td> <td align="left" width="200">ex) www.google.com</td> </tr> <tr> <td align="left" width="180">Email Address</td> <td width="320" align="left"><input type="text" name="email" value="<?php echo $email ?>" size="40"></td> <td align="left" width="200">(i.e. “Sales” or persons name)</td> </tr> <tr> <td align="left" width="180" valign="top">Dealer Information</td> <td width="320" align="left"><textarea name="dealerinfo" value="<?php echo $dealerinfo ?>" cols="40" rows="6"></textarea></td> <td align="left" width="200"></td> </tr> <tr> <td colspan="3"> <p align="center"><input type="submit" value="Update record"></p> </td> </tr> </table> </td></tr></table> </form><br />* denotes a Required Field</center> <?php } ?>
  10. thanks dennis for fixing one problem. Now i see the html form but it is not passing in the unique data into the input fields where i put <textarea name="dealerinfo" value="<?=$dealerinfo?>" etc.... Maybe i am focusing on the wrong thing right now, but all i know is it is not passing in the data from the unique id being passed. *Sidenote, the id structure is working because it's how my delete page works and it works just fine. Thanks so far!
  11. So i am not seeing edit.php show up, I got some help on this and dont understand some of the logic to make this page in particular work. viewrecord.php (shows records with delete and edit) <? // Check if session is not registered , redirect back to main page. // Put this code in first line of web page. session_start(); if(!session_is_registered(myusername)){ header("location:main_login.php"); } ?> <?php //Get variables from config.php to connect to mysql server require 'config.php'; // connect to the mysql database server. $connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error()); $selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error()); //trim whitespace from variable $searchcode = preg_replace('/\s+/', ' ', trim($_GET['search'])); //seperate multiple keywords into array space delimited $keywords = array_diff(explode(" ", $searchcode), array("")); if( !empty($searchcode) ) { foreach($keywords as $k => $v) $keywords[$k] = (int)$v; $codes = implode(",", $keywords); $searchcode_query = "SELECT * FROM dealer WHERE areacode = '".$codes."'"; //Store the results in a variable or die if query fails $result = mysql_query($searchcode_query) or die("Error executing MySQL query<br />".mysql_error()); $count = mysql_num_rows($result); } /** html code **/ echo "<center><h1>Admin View / Delete Dealer</h1><br><center><b>Other Admin Options Include: <a href=\"add_record.php\">add a record</a> | <a href=\"view_records.php\">view a record</a> | <a href=\"logout.php\">Log Out</a></b><br> <br>Please put in an area code to filter your search and the proceed to delete or to come back to other admin options.</center><br></center>"; //If users doesn't enter anything into search box tell them to. if( empty($searchcode) ){ echo "<html><head>"; echo "<title>Admin View / Delete Records</title>"; echo "</head>"; echo "<body onLoad=\"self.focus();document.searchform.search.focus()\">"; echo "<center>"; echo "<br /><form name=\"searchform\" method=\"GET\" action=\"view_records.php\">"; echo "<input type=\"text\" name=\"search\" size=\"20\" TABINDEX=\"1\" />"; echo " <input type=\"submit\" value=\"Search\" />"; echo "</form>"; } else { if( $count == 0 ){ echo "<center>Your query returned no results from the database, redirect.</center>"; } else { echo "<center><b>Admin - View Records for area code: ".$codes."</b></center><br>"; $row_count = 0; // Define the colours for the alternating rows $colour_odd = "#FDFDEA"; $colour_even = "#E0E0C7"; // If Remainder of $row_count divided by 2 == 0. $row_color = (($row_count % 2) == 0) ? $colour_even : $colour_odd; while( $row = mysql_fetch_array($result) ) { //table background color = row_color variable echo "<table width=\"550\" cellpadding=\"0\" cellspacing=\"2\">"; echo "<tr>"; echo "<td width=\"550\" valign=\"top\"><b>".$row['dealer']."</b><br> ".$row['address']." ".$row['address2']."<br> ".$row['city']." , ".$row['state'].", ".$row['zip']."<br> (".$row['areacode'].")-".$row['number']." or ".$row['tollnumber']."<br> Website: <a href=\"http://".$row['ulweb']."\">".$row['ulweb']."</a><br> Email: <a href=\"mailto:".$row['email']."\">".$row['email']."</a><br><br> <b>Dealer Information</b><br>".$row['dealerinfo']."<br> <br><a href=\"delete_record.php?id=".$row['id']."\">Delete</a> or <a href=\"edit.php?up=1&id=".$row['id']."\">Edit</a></td>"; echo "</tr></table><hr>"; $row_count++; } } } if( isset($result) ) { mysql_free_result($result); mysql_close($connect); } ?> edit.php (will not display in browser, no php error just blank page <?php //Get variables from config.php to connect to mysql server require 'config.php'; $connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error()); $selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error()); $codes = $_GET['id']; if(isset($_REQUEST["id"])) $nId=$_REQUEST["id"]; // will be requested.. from search page // you have selected the DATABASE now you can select the table and assign this on variable $sTable="my_table"; $sAction="Update"; // this is for update part if($_REQUEST['sAction']=="Update") { $query = "UPDATE `dealer` SET `dealer` = " . mysql_real_escape_string ( $_POST [ 'dealer' ] ) . " `address` = " . mysql_real_escape_string ( $_POST [ 'address' ] ) . " `address2` = " . mysql_real_escape_string ( $_POST [ 'address2' ] ) . " `city` = " . mysql_real_escape_string ( $_POST [ 'city' ] ) . " `state` = " . mysql_real_escape_string ( $_POST [ 'state' ] ) . " `zip` = " . mysql_real_escape_string ( $_POST [ 'zip' ] ) . " `areacode` = " . mysql_real_escape_string ( $_POST [ 'areacode' ] ) . " `number` = " . mysql_real_escape_string ( $_POST [ 'number' ] ) . " `tollnumber` = " . mysql_real_escape_string ( $_POST [ 'tollnumber' ] ) . " `ulweb` = " . mysql_real_escape_string ( $_POST [ 'ulweb' ] ) . " `email` = " . mysql_real_escape_string ( $_POST [ 'email' ] ) . " `dealerinfo` = " . mysql_real_escape_string ( $_POST [ 'dealerinfo' ] ) . " WHERE `ID` = " . mysql_real_escape_string ( $_REQUEST["id"] ); mysql_query($query) echo "Entry updated successfully!"; } // this value will be passed from the previous page and the text field will be filled with the corresponding ID if(isset($_REQUEST['up']) && isset($nId)) { $sql="select * from ".$sTable." where id=".$_REQUEST['id'].""; // here id is the id column in the table $result=mysql_query($sql); if(mysql_num_rows($result)>0) { $row=mysql_fetch_array($result); $dealer=$row['dealer']; $address=$row['address']; $address2=$row['address2']; $city=$row['city']; $state=$row['state']; $zip=$row['zip']; $areacode=$row['areacode']; $number=$row['number']; $tollnumber=$row['tollnumber']; $ulweb=$row['ulweb']; $email=$row['email']; $dealerinfo=$row['dealerinfo']; $sAction="Update"; } } // end ?> <form id="update" name="update" method="post" action="<?=$_SERVER['PHP_SELF']?>"> <input type='hidden' name='id' value="<?=$nId?>"> <input type='hidden' name='sAction' value="<?=$sAction?>" > <table width="700" cellpadding="0" cellpsacing="0" border="1" bordercolor="#000000"> <tr> <td> <table width="700" cellpadding="0" cellpsacing="0" border="0" bordercolor="#000000"> <tr> <td align="left" width="180">Dealer/ Distributor Name*</td> <td width="320" align="left"><input type="text" name="dealer" value="<?=$dealer?>" size="40"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">Street Address</td> <td width="320" align="left"><input type="text" name="address" value="<?=$address?>" size="40"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">Address 2</td> <td width="320" align="left"><input type="text" name="address2" value="<?=$address2?>" size="40"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">City*</td> <td width="320" align="left"><input type="text" name="city" value="<?=$city?>" size="30"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">State*</td> <td width="320" align="left"><input type="text" name="state" value="<?=$state?>" size="20"></td> <td align="left" width="200"></td> </tr> <tr> <td align="left" width="180">Zip*</td> <td width="320" align="left"><input type="text" name="zip" value="<?=$zip?>" size="10"></td> <td align="left" width="200">ex) 20100</td> </tr> <tr> <td align="left" width="180">Area Code*</td> <td width="320" align="left"><input type="text" name="areacode" value="<?=$areacode?>" size="10"></td> <td align="left" width="200">ex) 489</td> </tr> <tr> <td align="left" width="180">Local Number*</td> <td width="320" align="left"><input type="text" name="number" value="<?=$number?>" size="20"></td> <td align="left" width="200">ex) 123-4567</td> </tr> <tr> <td align="left" width="180">Toll Free Number</td> <td width="320" align="left"><input type="text" name="tollnumber" value="<?=$tollnumber?>" size="20"></td> <td align="left" width="200">ex) 1 800-123-4567</td> </tr> <tr> <td align="left" width="180">Website Address</td> <td width="320" align="left"><input type="text" name="ulweb" value="<?=$ulweb?>" size="40"></td> <td align="left" width="200">ex) www.google.com</td> </tr> <tr> <td align="left" width="180">Email Address</td> <td width="320" align="left"><input type="text" name="email" value="<?=$email?>" size="40"></td> <td align="left" width="200">(i.e. “Sales” or persons name)</td> </tr> <tr> <td align="left" width="180" valign="top">Dealer Information</td> <td width="320" align="left"><textarea name="dealerinfo" value="<?=$dealerinfo?>" cols="40" rows="6"></textarea></td> <td align="left" width="200"></td> </tr> <tr> <td colspan="3"> <p align="center"><input type="submit" value="Update record"></p> </td> </tr> </table> </td></tr></table> </form><br />* denotes a Required Field</center>
  12. it works, im just not all there, had to erase a php script above and a javascript code that was holding things up..... thanks for your reference !
  13. I have attached my code below, when i upload it nothing loads on the page, am i missing something really simple? I do not see any errors...hmph... If it is a quick fix let me know, if it's not and you know a better form for me and are willing to expel the information thats cool too! See below .... and thanks <?php // declare values $contact_email = $_POST['EmailAddress']; $contact_subject = $_POST['Subject']; $contact_name = $_POST['FullName']; $contact_message = $_POST['Message']; $mydate = date ( 'l, F d Y g:i A',time()+240 ); // where to send e-mail to $to = 'txdxdxrax3@gmail.com'; // e-mail subject $subject = "Message submitted using Contact Us form"; // e-mail message $message = "You have received a contact message:\r\n" ."----------------------------------------------------------------\r\n" ."Contact Name: $contact_name\r\n" ."Subject: $contact_subject\r\n" ."Submitted: $mydate\r\n" ."Message: $contact_message\r\n" ."Form Address: {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}"; $headers = "From: $contact_name <$contact_email>\n" ."Reply-To: $contact_email\n" ."X-Mailer: PHP/".phpversion(); // check for validation, then send the e-mail if(empty($contact_name) || empty($contact_email) || empty($contact_subject) || empty($contact_message)) { echo '<p>Send us a message, enter your information below and click \'Submit\'!</p> <form method="post" action=""> <table id="Form-Details"> <tbody> <tr><td>Name:</td><td><input type="text" name="FullName" size="20" /></td> <td>Subject:</td><td><input type="text" name="Subject" size="20" /></td></tr> <tr><td>Email:</td><td colspan="3"><input type="text" name="EmailAddress" size="20" /></td></tr> <tr><td colspan="4">Message:</td></tr> <tr><td colspan="4"><textarea rows="6" name="Message" cols="47" class="input"></textarea></td></tr> <tr><td colspan="4" class="right1"><input type="submit" value="Submit" /><input type="reset" value="Reset" /></td></tr> </tbody> </table> </form>'; } elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $contact_email)) { echo "<p>ERROR: Please enter a valid e-mail address.</p>"; } else { mail( $to, $subject, $message, $headers ); echo "<h3>Message Sent!</h3><p>Dear $contact_name,<br /><br />We will get back to you as soon as possible using $contact_email."; } ?>
  14. Hey neon, i wish there was a way to modify my original post and not my reply, but on my reply i added a new edit_record.php that had forms built in. if anyone see's this dont look at the first edit_record but my reply, and with that said I am still trying to figure out a way to get it to work. Sorry neon if you were referring to my reply then i apparently am as worthless as a box of screws on a boat in the middle of an ocean
  15. Sorry it was red of me to put that edit_records.php with out a better attempt so here it is: It says that the query is empty..... http://www.thegreatestsave.org/ut/search.php?search=574 and hit "EDIT" not delete please <?php //Get variables from config.php to connect to mysql server require 'config.php'; // connect to the mysql database server. $connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error()); $selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error()); //$codes = ((int)($_GET['id'])); $codes = $_GET['id']; $searchcode_query = "SELECT * FROM `dealer` WHERE `ID` = " . mysql_real_escape_string ( $_GET['ID'] ); mysql_select_db ( $database, $connect ); if ( @mysql_query ( $sql ) ) { $query = mysql_query ( $sql ); $row = mysql_fetch_assoc ( $query ); if ( array_key_exists ( '_submit_check', $_POST ) ) { if ( $_POST [ 'areacode' ] != '' && $_POST [ 'dealer' ] != '' && $_POST [ 'dealerinfo' ] != '' ) { mysql_select_db ( $database, $connect ); $query = "UPDATE `dealer` SET `areacode` = " . mysql_real_escape_string ( $_POST [ 'areacode' ] ) . " `dealer` = " . mysql_real_escape_string ( $_POST [ 'dealer' ] ) . " `dealerinfo` = " . mysql_real_escape_string ( $_POST [ 'dealerinfo' ] ) . " WHERE `ID` = " . mysql_real_escape_string ( $_GET['ID'] ); if ( @mysql_query ( $query ) ) { $success = 'Article updated successfully!'; } else { die ( mysql_error () ); } } else { echo 'Please ensure that you have a all info!'; } } } else { die ( mysql_error () ); } if ( isset ( $success ) ) { echo $success; } else { //we need this form only if we don't have the success message ?> <form id="update" name="update" method="post" action="<?=$_SERVER['PHP_SELF']?>"> <input type="hidden" name="_submit_check" value="1"/> Area Code:<br /> <input name="areacode" type="text" id="areacode" size="55" value="<?php if ( isset ( $_POST['areacode'] ) ){ echo $_POST['areacode']; }else{ echo $row['areacode'];} ?>" /> <br /><br /> Dealer:<br /> <input name="dealer" type="text" id="dealer" size="55" value="<?php if ( isset ( $_POST['dealer'] ) ){ echo $_POST['dealer']; }else{ echo $row['dealer'];} ?>" /> <br /><br /> Dealer Info:<br /> <textarea name="dealerinfo" cols="55" rows="5" id="dealerinfo"><?php if ( isset ( $_POST['dealerinfo'] ) ){ echo $_POST['dealerinfo']; }else{ echo $row['dealerinfo'];} ?></textarea> <br /><br /> <input type="submit" name="Submit" value="Update Record" /> </form> <?php } ?>
  16. As my subject line says, I am not too sure on how to approach a edit page. The add form works , the delete works , but the edit i have not really grasped how i actually lay it out and to show the appropriate row to Update. I will include the 2 files so you can see the variables and what not being passed to help: search.php (works fine displays edit and delete) <?php //Get variables from config.php to connect to mysql server require 'config.php'; // connect to the mysql database server. $connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error()); $selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error()); //trim whitespace from variable $searchcode = preg_replace('/\s+/', ' ', trim($_GET['search'])); //seperate multiple keywords into array space delimited $keywords = array_diff(explode(" ", $searchcode), array("")); if( !empty($searchcode) ) { foreach($keywords as $k => $v) $keywords[$k] = (int)$v; $codes = implode(",", $keywords); $searchcode_query = "SELECT * FROM dealer WHERE areacode = '".$codes."'"; //Store the results in a variable or die if query fails $result = mysql_query($searchcode_query) or die("Error executing MySQL query<br />".mysql_error()); $count = mysql_num_rows($result); } /** html code **/ echo "You searched for ".$codes."<br />"; //If users doesn't enter anything into search box tell them to. if( empty($searchcode) ){ echo "<html><head>"; echo "<title>search</title>"; echo "</head>"; echo "<body onLoad=\"self.focus();document.searchform.search.focus()\">"; echo "<center>"; echo "<br /><form name=\"searchform\" method=\"GET\" action=\"search.php\">"; echo "<input type=\"text\" name=\"search\" size=\"20\" TABINDEX=\"1\" />"; echo " <input type=\"submit\" value=\"Search\" />"; echo "</form>"; } else { if( $count == 0 ){ echo "Your query returned no results from the database"; } else { $row_count = 0; while( $row = mysql_fetch_array($result) ) { //table background color = row_color variable echo "<center><table width=\"680\" bgcolor=".($row_count % 2) ? $color1 : $color2.">"; echo "<tr>"; echo "<td width=\"100\" valign=\"top\">".$row['areacode']."</td>"; echo "<td width=\"150\" valign=\"top\">".$row['dealer']."</td>"; echo "<td width=\"300\" valign=\"top\">".$row['dealerinfo']."</td>"; echo "<td width=\"65\" valign=\"top\"><a href=\"#\">Edit</a></td> <td width=\"65\" valign=\"top\"><a href=\"delete_record.php?id=".$row['id']."\">Delete</a></td></tr>"; echo "</table></center>"; $row_count++; } } } if( isset($result) ) { mysql_free_result($result); mysql_close($connect); } ?> edit_record.php ( no clue, i just kind of copied my delete_records.php and then added a UPDATE where ever i see a DELETE) <?php //Get variables from config.php to connect to mysql server require 'config.php'; // connect to the mysql database server. $connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error()); $selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error()); //$codes = ((int)($_GET['id'])); $codes = $_GET['id']; $searchcode_query = "SELECT * FROM dealer WHERE id = '".$codes."'"; $sql_delete_query = "Update FROM dealer WHERE id = '".$codes."'"; $result = mysql_query($searchcode_query) or die("Error executing MySQL SELECT query<br />".mysql_error()); if( mysql_affected_rows() != 1 ) { print "No such dealer"; } else { mysql_free_result($result); $result = mysql_query($sql_delete_query) or die("Error executing MySQL Update query<br />".mysql_error()); echo "Updated: ".$code; } /** ... **/ ?>
  17. ok so i see definitely what you are talking about http://www.thegreatestsave.org/ut/delete_record.php?id= its not passing the auto increming id in my database, if i manually put in anumber like 5 for instance it will erase it from the database through my control panel so i know the code works in delete_records.php, but <a href=\"delete_record.php?id=$id\">[code] is not pulling the id. is this something i need to use a isset($id) at the top of the mysql on search.php? [/code]
  18. http://www.thegreatestsave.org/ut/search.php if you put in 574 , and delete a record it goes to delete_record.php and it says No such dealer. and it is not deleting. I will paste complete code one for search.php and delete_record.php, i believe the problem lies in delete_record.php.... ahhhhhh <?php //Get variables from config.php to connect to mysql server require 'config.php'; // connect to the mysql database server. if( !mysql_connect($dbhost, $dbusername, $dbuserpass) ) { die("Error connecting to mysql host<br />".mysql_error()); } //select the database if( !mysql_select_db($dbname) ) { die("Cannot select database<br />".mysql_error()); } //trim whitespace from variable $_GET['search'] = preg_replace('/\s+/', ' ', trim($_GET['search'])); //seperate multiple keywords into array space delimited $keywords = array_diff(explode(" ", $_GET['search']), array("")); if( !empty($_GET['search']) ) { foreach($keywords as $k => $v) $keywords[$k] = (int)$v; $codes = implode(",", $keywords); //Store the results in a variable or die if query fails $result = mysql_query("SELECT * FROM dealer WHERE areacode IN ($codes)"); if(!$result) { die("Error executing MySQL query<br />".mysql_error()); } $count = mysql_num_rows($result); } /** html code **/ echo "You searched for $codes<br />"; //If users doesn't enter anything into search box tell them to. if( empty($_GET['search']) ){ echo "<html><head>"; echo "<title>search</title>"; echo "</head>"; echo "<body onLoad=\"self.focus();document.searchform.search.focus()\">"; echo "<center>"; echo "<br /><form name=\"searchform\" method=\"GET\" action=\"search.php\">"; echo "<input type=\"text\" name=\"search\" size=\"20\" TABINDEX=\"1\" />"; echo " <input type=\"submit\" value=\"Search\" />"; echo "</form>"; } else { if( $count == 0 ){ echo "Your query returned no results from the database"; } else { $row_count = 0; while( $row = mysql_fetch_array($result) ) { //table background color = row_color variable echo "<center><table width=\"680\" bgcolor=".($row_count % 2) ? $color1 : $color2.">"; echo "<tr>"; echo "<td width=\"100\" valign=\"top\">".$row['areacode']."</td>"; echo "<td width=\"150\" valign=\"top\">".$row['dealer']."</td>"; echo "<td width=\"300\" valign=\"top\">".$row['dealerinfo']."</td>"; echo "<td width=\"65\" valign=\"top\"><a href=\"#\">Edit</a></td> <td width=\"65\" valign=\"top\"><a href=\"delete_record.php?id=$id\">Delete</a></td></tr>"; echo "</table></center>"; $row_count++; } } } if( isset($result) ) { mysql_free_result($result); } ?> <?php //Get variables from config.php to connect to mysql server require 'config.php'; // connect to the mysql database server. if( !mysql_connect($dbhost, $dbusername, $dbuserpass) ) { die("Error connecting to mysql host<br />".mysql_error()); } //select the database if( !mysql_select_db($dbname) ) { die("Cannot select database<br />".mysql_error()); } $id = ((int)($_GET['id'])); if( !($result = mysql_query("SELECT id FROM dealer WHERE id = $id")) ) { die("MySQL Error : ".mysql_error()); } if( mysql_num_rows($result) == 0 ) { print "No such dealer"; } else { mysql_query("DELETE FROM dealer WHERE id=$id"); } /** ... **/ ?>
  19. Thanks teng84, i know you probably hate when people repost so much but i really think that this will be the last one consider what you did last fixed search.php, now delete.php is having that int problem. first to recap: Fatal error: Call to undefined function: int() in /home/thegr29/public_html/ut/delete_record.php on line 11 $id = int($_GET['id']); i then changed it to both $id = (int)($_GET['id']); and $id = (int($_GET['id'])); and each came with a mysql error. I usuallly dont have so many problems but ive never used int in code before. Thanks again teng84 and others for your help, its very much appreciated.
  20. Thanks for clearing up that problem, but now another: It happens when i put in a value into the text box, you can see it here to test: http://www.thegreatestsave.org/ut/search.php Fatal error: Call to undefined function: int() in /home/thegr29/public_html/ut/search.php on line 23 //seperate multiple keywords into array space delimited $keywords = array_diff(explode(" ", $_GET['search']), array("")); if( !empty($_GET['search']) ) { foreach($keywords as $k => $v) $keywords[$k] = int($v); $codes = implode(",", $keywords); //Store the results in a variable or die if query fails $result = mysql_query("SELECT * FROM dealer WHERE areacode IN ($codes)"); if(!$result) { die("Error executing MySQL query<br />".mysql_error()); } $count = mysql_num_rows($result); }
  21. Thanks for the repost, I am getting an error: Parse error: syntax error, unexpected '{' in /home/thegr29/public_html/ut/search.php on line 29 it's saying that { is structured wrong somehow and i guess i can't see where im missing or add one too many {, any help would be so much appreciated this is the newly implemented code: <?php //Get variables from config.php to connect to mysql server require 'config.php'; // connect to the mysql database server. if( !mysql_connect($dbhost, $dbusername, $dbuserpass) ) { die("Error connecting to mysql host<br />".mysql_error()); } //select the database if( !mysql_select_db($dbname) ) { die("Cannot select database<br />".mysql_error()); } //trim whitespace from variable $_GET['search'] = preg_replace('/\s+/', ' ', trim($_GET['search'])); //seperate multiple keywords into array space delimited $keywords = array_diff(explode(" ", $_GET['search']), array("")); if( !empty($_GET['search']) ) { foreach($keywords as $k => $v) $keywords[$k] = int($v); $codes = implode(",", $keywords); //Store the results in a variable or die if query fails if( !($result = mysql_query("SELECT * FROM dealer WHERE areacode IN ($codes)") ) { die("Error executing MySQL query<br />".mysql_error()); } $count = mysql_num_rows($result); } /** html code **/ echo "You searched for $codes<br />"; //If users doesn't enter anything into search box tell them to. if( empty($_GET['search']) ){ echo "Enter something..."; } else { if( $count == 0 ){ echo "Your query returned no results from the database"; } else { $row_count = 0; while( $row = mysql_fetch_array($result) ) { //table background color = row_color variable echo "<center><table width=\"680\" bgcolor=".($row_count % 2) ? $color1 : $color2.">"; echo "<tr>"; echo "<td width=\"100\" valign=\"top\">".$row['areacode']."</td>"; echo "<td width=\"150\" valign=\"top\">".$row['dealer']."</td>"; echo "<td width=\"300\" valign=\"top\">".$row['dealerinfo']."</td>"; echo "<td width=\"65\" valign=\"top\"><a href=\"#\">Edit</a></td> <td width=\"65\" valign=\"top\"><a href=\"delete_record.php?id=$id\">Delete</a></td></tr>"; echo "</table></center>"; $row_count++; } } } if( isset($result) ) { mysql_free_result($result); } ?>
  22. Database Structure: fields: id, areacode, dealer, dealerinfo test link: http://thegreatestsave.org/ut/search.php (574 and 765, 456 are the only working ones i put for test purposes) added from a form from here http://thegreatestsave.org/ut/add_record.html (no validation on it yet so if your going to test it please fill it out all the way until i do come back to it). Basically i have no clue on how to get it to delete the individual record when hitting delete and the more i look at other people code and manipulate the more i get confused. Any help would be appreciated search.php <?php //Get variables from config.php to connect to mysql server require 'config.php'; // connect to the mysql database server. mysql_connect ($dbhost, $dbusername, $dbuserpass); //select the database mysql_select_db($dbname) or die('Cannot select database'); //search variable = data in search box or url if(isset($_GET['search'])) { $search = $_GET['search']; } //trim whitespace from variable $search = trim($search); $search = preg_replace('/\s+/', ' ', $search); //seperate multiple keywords into array space delimited $keywords = explode(" ", $search); //Clean empty arrays so they don't get every row as result $keywords = array_diff($keywords, array("")); //Set the MySQL query if ($search == NULL or $search == '%'){ } else { for ($i=0; $i<count($keywords); $i++) { $query = "SELECT * FROM dealer WHERE areacode = '$keywords[$i]'"; } //Store the results in a variable or die if query fails $result = mysql_query($query) or die(mysql_error()); } if ($search == NULL or $search == '%'){ } else { //Count the rows retrived $count = mysql_num_rows($result); } echo "<html>"; echo "<head>"; echo "<title>search</title>"; echo "</head>"; echo "<body onLoad=\"self.focus();document.searchform.search.focus()\">"; echo "<center>"; echo "<br /><form name=\"searchform\" method=\"GET\" action=\"search.php\">"; echo "<input type=\"text\" name=\"search\" size=\"20\" TABINDEX=\"1\" />"; echo " <input type=\"submit\" value=\"Search\" />"; echo "</form>"; //If search variable is null do nothing, else print it. if ($search == NULL) { } else { echo "You searched for <b><FONT COLOR=\"blue\">"; foreach($keywords as $value) { print "$value "; } echo "</font></b>"; } echo "<p> </p><br />"; echo "</center>"; //If users doesn't enter anything into search box tell them to. if ($search == NULL){ echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br /></center>"; } elseif ($search == '%'){ echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br /></center>"; //If no results are returned print it } elseif ($count <= 0){ echo "<center><b><FONT COLOR=\"red\">Your query returned no results from the database. (redirect goes here)</font></b><br /></center>"; //ELSE print the data in a table } else { //Table header echo "<center><table width=\"680\" id=\"search\" bgcolor=\"#AAAAAA\">"; echo "<tr>"; echo "<td width=\"100\" valign=\"top\"><b>Area Code</b></td>"; echo "<td width=\"150\" valign=\"top\"><b>Dealer</b></td>"; echo "<td width=\"300\" valign=\"top\"><b>Dealer Info</b></td>"; echo "<td width=\"65\" valign=\"top\"> </td><td width=\"65\" valign=\"top\"> </td><tr>"; echo "</table></center>"; //Colors for alternation of row color on results table $color1 = "#d5d5d5"; $color2 = "#e5e5e5"; //While there are rows, print it. while($row = mysql_fetch_array($result)) { //Row color alternates for each row $row_color = ($row_count % 2) ? $color1 : $color2; //table background color = row_color variable echo "<center><table width=\"680\" bgcolor=".$row_color.">"; echo "<tr>"; echo "<td width=\"100\" valign=\"top\">".$row['areacode']."</td>"; echo "<td width=\"150\" valign=\"top\">".$row['dealer']."</td>"; echo "<td width=\"300\" valign=\"top\">".$row['dealerinfo']."</td>"; echo "<td width=\"65\" valign=\"top\"><a href=\"#\">Edit</a></td><td width=\"65\" valign=\"top\"><a href=\"delete_record.php?id=$id\">Delete</a></td></tr>"; echo "</table></center>"; $row_count++; //end while } //end if } echo "</body>"; echo "</html>"; if ($search == NULL or $search == '%') { } else { //clear memory mysql_free_result($result); } ?> delete_record.php <?php $con = mysql_connect("localhost","x","x"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("x", $con); mysql_query("DELETE FROM dealer WHERE id=$id");mysql_close($con); ?> you deleted results (and how do i show them ?) areas i believe im doing wrong are not declaring the right variable to pass to delete_record.php and then correctly coding delete_record.php.
  23. mysql_query("DELETE FROM dealer WHERE id=$id");mysql_close($con); that is the only thing in delete_record.php that it shows id. I think there is something wrong with the search.php but i cant locate it for the life of me. If anyone need more info or to repost all the code let me know. Thanks everyone for the re-posts.
  24. Changed it and still when i hover over "delete" on search.php the status bar of a browser says delete_record.php?id= For whatever reason it's saying that the id is null for that when in reality checking my database it is very clear that each record has an id. Did i miss something in search.php to make sure the id is declared?
  25. Ok so i changed the structure a little bit of my database and added a auto incremented field called id and then changed this on: (I think on search.php -above- i am not passing it to the delete page, check the url if your new to this post to see demo. Thanks so much for a response already! search.php <a href=\"delete_record.php?id='$id'\">Delete</a> and changed this on delete_records.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>United Truck Parts - Delete Results</title> </head> <body> <?php //Get variables from config.php to connect to mysql server require 'config.php'; // connect to the mysql database server. mysql_connect ($dbhost, $dbusername, $dbuserpass); //select the database mysql_select_db($dbname) or die('Cannot select database'); $keywords = mysql_escape_string($_GET['id']); // Delete a row from a table mysql_query("DELETE FROM dealer WHERE id = '$id'") or die(mysql_error()); ?> you deleted results <?php echo $search ; ?> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.