Jump to content

[SOLVED] PHP SQL Syntax Error


aeafisme23

Recommended Posts

ERROR:

Can't run query because You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'repeat, internet, internetdirectory, referral, yellowpages, tradeshow, other, no' at line 1

 

I get this and i've even went to standards of SQL syntax and mine runs hand in hand. This exact code works on another server but when i uploaded to a different server/hosting company it tells me im not following it by the "book". This is the INSERT sql i have; I am very greatful of anyones advice or help. Thanks

 

    $sql = "insert into rfq (name, company, address, city, zip, email, phone, fax, state, typeii, type3, burnish, chromate, hex, impregnation, strip, partnumber, partdescription, alloy, quantity, specifications, color, repeat, internet, internetdirectory, referral, yellowpages, tradeshow, other, notes) values('{$name}','{$company}','{$address}','{$city}','{$zip}','{$email}','{$phone}','{$fax}','{$state}','{$typeii}','{$type3}','{$burnish}','{$chromate}','{$hex}','{$impregnation}','{$strip}','{$partnumber}','{$partdescription}','{$alloy}','{$quantity}','{$specifications}','{$color}','{$repeat}','{$internet}','{$internetdirectory}','{$referral}','{$yellowpages}','{$tradeshow}','{$other}','{$notes}');"; 

 

this is w3schools (just a random example)

$sql="INSERT INTO person (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

Link to comment
https://forums.phpfreaks.com/topic/106553-solved-php-sql-syntax-error/
Share on other sites

I changed Id to id and that didnt work here is my code to the page that does it all pretty much. Please bash away!

 

[code=php:0]<html> 
<head> 
<title>Manage Contact Log</title> 
</head> 
<body> 
<?php 
/************************************************************************* 
               control code for application 
*************************************************************************/ 

//submit button was pressed so call the process form function 
if (isset($_POST['submit'])) 
{ 
  process_form(); 
  die(); 
}//end if 


//call the get_data function 
if (isset($_GET['id'])) 
{ 
  get_data(); 
}//endif 


//nothing chosen so list the dma's 
if ((empty($_POST))&&(empty($_GET))) 
{ 
  list_users(); 
  die(); 
}//end if 


//request to add a new contact so call the show_form function 
if ((isset($_GET['action']))&&($_GET['action']=='add')) 
{ 
  show_form(); 
}//endif 



/************************************************************************* 
               get the data for an individual contact 
*************************************************************************/ 

function get_data() 
{ 
    //validate the id has been passed at that it is a number 
    if ((empty($_GET['id']))||(is_nan($_GET['id']))) 
    { 
        //there was a problem so list the users again 
      list_users(); 
      //kill the script 
      die(); 
    }else{ 
      //all is ok and assign the data to a local variable 
      $id = $_GET['id']; 
    }//end if 
$sql = "select * from rfq where id = {$id} order by id;"; 
    $result = conn($sql); 
    if (mysql_num_rows($result)==1){ 
      //call the form and pass it the handle to the resultset 
      show_form($result); 
    }else{ 
      $msg = "No data found for FWA Form"; 
      confirm($msg); 
      //call the list users function 
      list_users(); 
    }//end if  
}//end function 


/************************************************************************* 
               show the input / edit form 
*************************************************************************/ 
function show_form($handle='',$data='') 
{ 
  //$handle is the link to the resultset, the ='' means that the handle can be empty / null so if nothing is picked it won't blow up 
  
  //set default values 
  $id  = ''; 
  $name  = ''; 
  $company  = ''; 
  $address  = ''; 
  $city  = ''; 
  $zip      = ''; 
  $email  = ''; 
  $phone  = ''; 
  $fax  = ''; 
  $state  = ''; 
  $typeii  = ''; 
  $type3      = ''; 
  $burnish  = ''; 
  $chromate  = ''; 
  $hex  = ''; 
  $impregnation  = ''; 
  $strip      = ''; 
  $partnumber  = ''; 
  $partdescription  = ''; 
  $alloy  = ''; 
  $quantity  = ''; 
  $specifications      = ''; 
  $color  = ''; 
  $repeat  = ''; 
  $internet  = ''; 
  $internetdirectory  = ''; 
  $referral      = ''; 
  $yellowpages  = ''; 
  $tradeshow  = ''; 
  $other  = ''; 
  $notes  = ''; 
  $value      = 'Add';  //submit button value 
  $action     = 'add';  //default form action is to add a new dma/station to db 

  //set the action based on what the user wants to do 
  if ($handle) 
  { 
    //set form values for button and action 
    $action = "edit"; 
    $value  = "Update"; 
    
    //get the values from the db resultset 
    $row = mysql_fetch_array($handle); 
    $id  = $row['id']; 
    $name  = $row['name']; 
    $company  = $row['company']; 
    $address  = $row['address']; 
    $city  = $row['city']; 
    $zip          = $row['zip']; 
    $email  = $row['email']; 
    $phone  = $row['phone']; 
    $fax  = $row['fax'];
    $state  = $row['state']; 
    $typeii  = $row['typeii']; 
    $type3  = $row['type3']; 
    $burnish = $row['burnish']; 
    $chromate  = $row['chromate']; 
    $hex  = $row['hex']; 
    $impregnation  = $row['impregnation']; 
    $strip  = $row['strip']; 
    $partnumber  = $row['partnumber']; 
    $partdescription   = $row['partdescription']; 
    $alloy  = $row['alloy']; 
    $quantity  = $row['quantity']; 
    $specifications  = $row['specifications']; 
    $color  = $row['color']; 
    $repeat  = $row['repeat']; 
    $internet          = $row['internet']; 
    $internetdirectory  = $row['internetdirectory']; 
    $referral  = $row['referral']; 
    $yellowpages  = $row['yellowpages']; 
    $tradeshow  = $row['tradeshow']; 
    $other  = $row['other']; 
    $notes          = $row['notes']; 
  }//end if 
  
  //error handling from the processing form function 
  if($data != '') 
  { 
    $elements = explode("|",$data); 
        $id     = $elements[0]; 
        $name     = $elements[1]; 
        $company     = $elements[2]; 
        $address     = $elements[3]; 
        $city     = $elements[4]; 
        $zip             = $elements[5]; 
        $email     = $elements[6]; 
        $phone     = $elements[7]; 
        $fax     = $elements[8]; 
        $state     = $elements[9]; 
        $typeii     = $elements[10]; 
        $type3     = $elements[11]; 
        $burnish             = $elements[12]; 
        $chromate     = $elements[13]; 
        $hex     = $elements[14]; 
        $impregnation     = $elements[15]; 
        $strip     = $elements[16]; 
        $partnumber     = $elements[17]; 
        $partdescription             = $elements[18]; 
        $alloy     = $elements[19]; 
        $quantity     = $elements[20]; 
        $specifications     = $elements[21]; 
        $color     = $elements[22]; 
        $repeat     = $elements[23]; 
        $internet             = $elements[24]; 
        $internetdirectory     = $elements[25]; 
        $referral     = $elements[26]; 
        $yellowpages     = $elements[27]; 
        $tradeshow     = $elements[28]; 
        $other     = $elements[29]; 
        $notes             = $elements[30]; 
  } 
?> 

<body> 

<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?action=<?php  echo $action?>"> 
  <table align="left">
    
    <tr valign="baseline">
      <td width="116" align="right" nowrap><input type="hidden" value="<?php echo $id?>" name="id"><div align="left">Name:</div></td>
      <td width="193"><input type="text" name="name" value="<?php echo $name ?>" size="32"></td>
      <td width="113"> </td>
      <td width="68" align="right" nowrap><div align="left">Company:</div></td>
      <td width="205"><input type="text" name="company" value="<?php echo $company ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap><div align="left">Address:</div></td>
      <td><input type="text" name="address" value="<?php echo $address ?>" size="32"></td>
      <td> </td>
      <td align="right" nowrap><div align="left">City:</div></td>
      <td><input type="text" name="city" value="<?php echo $city ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><div align="left"></div></td>
      <td> </td>
      <td> </td>
      <td align="right" nowrap><div align="left">Zip:</div></td>
      <td><input type="text" name="zip" value="<?php echo $zip ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap><div align="left">Email:</div></td>
      <td><input type="text" name="email" value="<?php echo $email ?>" size="32"></td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap><div align="left">Phone:</div></td>
      <td><input type="text" name="phone" value="<?php echo $phone ?>" size="32"></td>
      <td> </td>
      <td align="right" nowrap>Fax:</td>
      <td><input type="text" name="fax" value="<?php echo $fax ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap> </td>
      <td><select name="state" value="<?php echo $state ?>">
        <option value="alabama">Alabama</option>
        <option value="Alaska">Alaska</option>
        <option value="Arizona">Arizona</option>
        <option value="Arkansas">Arkansas</option>
        <option value="California">California</option>
        <option value="Colorado">Colorado</option>
        <option value="Connecticut">Connecticut</option>
        <option value="Delaware">Delaware</option>
        <option value="Florida">Florida</option>
        <option value="Georgia">Georgia</option>
        <option value="Hawaii">Hawaii</option>
        <option value="idaho">idaho</option>
        <option value="Illinois">Illinois</option>
        <option value="Indiana">Indiana</option>
        <option value="Iowa">Iowa</option>
        <option value="Kansas">Kansas</option>
        <option value="Kentucky">Kentucky</option>
        <option value="Louisiana">Louisiana</option>
        <option value="Maine">Maine</option>
        <option value="Maryland">Maryland</option>
        <option value="Massachusetts">Massachusetts</option>
        <option value="Michigan">Michigan</option>
        <option value="Minnesota">Minnesota</option>
        <option value="Mississippi">Mississippi</option>
        <option value="Missouri">Missouri</option>
        <option value="Montana">Montana</option>
        <option value="Nebraska">Nebraska</option>
        <option value="Nevada">Nevada</option>
        <option value="New Hampshire">New Hampshire</option>
        <option value="New Jersey">New Jersey</option>
        <option value="New Mexico">New Mexico</option>
        <option value="New York">New York</option>
        <option value="North Carolina">North Carolina</option>
        <option value="North Dakota">North Dakota</option>
        <option value="Ohio">Ohio</option>
        <option value="Oklahoma">Oklahoma</option>
        <option value="Oregon">Oregon</option>
        <option value="Pennsylvania">Pennsylvania</option>
        <option value="Rhode Island">Rhode Island</option>
        <option value="South Carolina">South Carolina</option>
        <option value="South Dakota">South Dakota</option>
        <option value="Tennessee">Tennessee</option>
        <option value="Texas">Texas</option>
        <option value="Utah">Utah</option>
        <option value="Vermont">Vermont</option>
        <option value="Virginia">Virginia</option>
        <option value="Washington">Washington</option>
        <option value="West Virginia">West Virginia</option>
        <option value="Wisconsin">Wisconsin</option>
        <option value="Wyoming">Wyoming</option>
      </select></td>
      <td> </td>
      <td align="right" nowrap> </td>
      <td> </td>
    </tr>
    <tr valign="baseline">
      <td colspan="5" align="right" nowrap><div align="left" class="style1">
        <div align="left">Process requested (please check all that apply):</div>
      </div></td>
    </tr>
    <tr valign="baseline">
      <td colspan="2" align="right" nowrap>
        
<?php 

if ($typeii != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$typeii = "NO";
}
else {
$typeii = "YES";
}

if ($type3 != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$type3 = "NO";
}
else {
$type3 = "YES";
}

if ($burnish != NULL) {  // if not empty meaning it's selected it will be YES if not it will be NO
$burnish = "NO";
}
else {
$burnish = "YES";
}

if ($chromate != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$chromate = "NO";
}
else {
$chromate = "YES";
}

if ($hex != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$hex = "NO";
}
else {
$hex = "YES";
}

if ($impregnation != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$impregnation = "NO";
}
else {
$impregnation = "YES";
}

if ($strip != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$strip = "NO";
}
else {
$strip = "YES";
}

if ($repeat != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$repeat = "NO";
}
else {
$repeat = "YES";
}

if ($internet != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$internet = "NO";
}
else {
$internet = "YES";
}

if ($yellowpages != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$yellowpages = "NO";
}
else {
$yellowpages = "YES";
}

?>


        <div align="left">
          <input type="checkbox" name="typeii" value="<?php echo $typeii ?>" id="checkbox">
      Type II (Conventional Anodize)</div></td>
      <td> </td>
      <td colspan="2" align="right" nowrap><div align="left">
        <input type="checkbox" name="type3" value="<?php echo $type3 ?>" id="checkbox3">
      Type III (Hard Coat Anodize)</div></td>
    </tr>
    <tr valign="baseline">
      <td colspan="2" align="right" nowrap>
        
        <div align="left">
          <input type="checkbox" name="burnish" value="<?php echo $burnish ?>" id="checkbox4">
      (Burnish, Deburr)</div></td>
      <td> </td>
      <td colspan="2" align="right" nowrap><div align="left">
        <input type="checkbox" name="chromate" value="<?php echo $chromate ?>" id="checkbox5">
      Chromate Conversion</div></td>
    </tr>
    <tr valign="baseline">
      <td colspan="2" align="right" nowrap>
        
        <div align="left">
          <input type="checkbox" name="hex" value="<?php echo $hex ?>" id="checkbox7">
      Chromate Conversion Hex-free</div></td>
      <td> </td>
      <td colspan="2" align="right" nowrap><div align="left">
        <input type="checkbox" name="impregnation" value="<?php echo $impregnation ?>" id="checkbox6">
      Impregnation</div></td>
    </tr>
    <tr valign="baseline">
      <td colspan="2" align="right" nowrap>
        
        <div align="left">
          <input type="checkbox" name="strip" value="<?php echo $strip ?>" id="checkbox8">
      Strip</div></td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr valign="baseline">
      <td colspan="2" align="right" nowrap> </td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><div align="left">Part Number</div></td>
      <td colspan="4"><input type="text" name="partnumber" value="<?php echo $partnumber ?>" size="100"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><div align="left">Part Description</div></td>
      <td colspan="4"><input type="text" name="partdescription" value="<?php echo $partdescription ?>" size="100"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap><div align="left">Alloy:</div></td>
      <td><input type="text" name="alloy" value="<?php echo $alloy ?>" size="32"></td>
      <td> </td>
      <td>Quantity</td>
      <td><input type="text" name="quantity" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><div align="left">Specifications</div></td>
      <td><input type="text" name="specifications" value="<?php echo $specifications ?>" size="32"></td>
      <td> </td>
      <td>Color</td>
      <td><input type="text" name="color" value="<?php echo $color ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"> </td>
      <td> </td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr valign="baseline">
      <td colspan="5" align="right" nowrap><div align="left" class="style1">
        <div align="left">How did you hear about us?</div>
      </div></td>
    </tr>
    <tr valign="baseline">
      <td colspan="5" align="right" nowrap><div align="left">
        <table width="100%" border="0" cellspacing="3" cellpadding="0">
          <tr>
            <td><input type="checkbox" name="repeat" value="<?php echo $repeat ?>" id="checkbox22">
              I am a repeat customer</td>
            <td><input type="checkbox" name="internet" value="<?php echo $internet ?>" id="checkbox9"></td>
            <td>Internet:</td>
            <td>Internet Directory:</td>
            <td><input type="text" name="internetdirectory" value="<?php echo $internetdirectory ?>" size="32"></td>
          </tr>
          <tr>
            <td>Referral:
              <input type="text" name="referral" value="" size="32"></td>
            <td><input type="checkbox" name="yellowpages" value="<?php echo $yellowpages ?>" id="checkbox10"></td>
            <td>Yellow Pages:</td>
            <td>Tradeshow:</td>
            <td><input type="text" name="tradeshow" value="<?php echo $tradeshow ?>" size="32"></td>
          </tr>
          <tr>
            <td> </td>
            <td> </td>
            <td> </td>
            <td> </td>
            <td> </td>
          </tr>
        </table>
      </div></td>
    </tr>
    <tr valign="baseline">
      <td colspan="5" align="right" nowrap><div align="left">Other:
          <textarea name="other" value="<?php echo $other ?>" cols="80"></textarea>
      </div></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><div align="left"></div></td>
      <td> </td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr valign="baseline">
      <td colspan="5" align="right" valign="middle" nowrap><div align="left"></div>        
        <div align="left">Notes/ Special Request
          <textarea name="notes" value="<?php echo $notes ?>" cols="80"></textarea>
      </div></td>
    </tr>
    
    <tr valign="baseline">
      <td nowrap align="right"> </td>
      <td><input name="submit" type="submit" value="<?php echo $value ?>"> <input name="reset" type="reset" value="Clear Form"></td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
  </table>
  <div align="left">
  </div>
</form>


<? 
}//end function 


/************************************************************************* 
               list all the DMA/Stations in the db 
*************************************************************************/ 
function list_users() 
{ 
    $y = 0; //counter 
    $sql = "select * from rfq order by id;";  
    $result = conn($sql); 

// include "smsinclude.php"; 


  echo "<table width=\"700\" cellpadding=\"0\" cellspacing=\"0\"> 
        	<tr><td style=\"font-size:18px; font-weight:bold;\">Manage Request for Quote</td></tr> 
        	<tr>
			<td valign=\"top\"><br><a href='".$_SERVER['PHP_SELF']."?action=add'>Add an additional Request</a><br></td>
		</tr>
	</table><br>
	<table width=\"800\" cellpadding=\"5\" cellspacing=\"0\">";
  
         
     if (mysql_num_rows($result)){ 
      //show a list of kids with name as a link to the prepopulated form with their data in it 
      while($rows = mysql_fetch_array($result)){ 
        
        //change row background color 
        (($y % 2) == 0) ? $bgcolor = "#F8F7F2" : $bgcolor=" #FFFFFF"; 
        
        //build strings to make life easier 

    $id  = $rows['id']; 
    $name  = $rows['name']; 
    $company  = $rows['company']; 
    $address  = $rows['address']; 
    $city  = $rows['city']; 
    $zip          = $rows['zip']; 
    $email  = $rows['email']; 
    $phone  = $rows['phone']; 
    $fax  = $rows['fax']; 
    $state  = $rows['state']; 
    $typeii  = $rows['typeii']; 
    $type3  = $rows['type3']; 
    $burnish = $rows['burnish']; 
    $chromate  = $rows['chromate']; 
    $hex  = $rows['hex']; 
    $impregnation  = $rows['impregnation']; 
    $strip  = $rows['strip']; 
    $partnumber  = $rows['partnumber']; 
    $partdescription   = $rows['partdescription']; 
    $alloy  = $rows['alloy']; 
    $quantity  = $rows['quantity']; 
    $specifications  = $rows['specifications']; 
    $color  = $rows['color']; 
    $repeat  = $rows['repeat']; 
    $internet          = $rows['internet']; 
    $internetdirectory  = $rows['internetdirectory']; 
    $referral  = $rows['referral']; 
    $yellowpages  = $rows['yellowpages']; 
    $tradeshow  = $rows['tradeshow']; 
    $other  = $rows['other']; 
    $notes          = $rows['notes']; 


        
        //pass the url to delete the correct table  NOT SURE if its RFQ or fwaform or....
  		$field_data = "rfq";	

        //convert status to readable string from 1 or 0  might need this for the checkboxes
        ($status == 0) ? $status = "Available to contact" : $status = "Do not contact at present."; 
        
        //echo out the row 
        echo "<tr style='background-color:$bgcolor;'>
			<td>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"800\" height=\"30\" valign=\"middle\"><b>Request For Quote #: $id</b></a></td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
						<td valign=\"top\" width=\"230\"><b>Name:</b> $name</td>
						<td valign=\"top\" width=\"250\"><b>Company:</b> $company</td>
						<td valign=\"top\" width=\"320\"><b>Address:</b> $address</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"230\"><b>City:</b> $city</td>
						<td valign=\"top\" width=\"250\"><b>State:</b> $state</td>
						<td valign=\"top\" width=\"320\"><b>Zip:</b> $zip</td>


					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"230\"><b>Email:</b> $email</td>
						<td valign=\"top\" width=\"250\"><b>Phone:</b> $phone</td>
						<td valign=\"top\" width=\"320\"><b>Fax:</b> $fax</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
						<td valign=\"top\" width=\"800\"><b>TypeII:</b> $typeii     <b>Type3:</b> $type3      <b>Burnish:</b> $burnish     <b>Chromate:</b> $chromate     <b>Hex:</b> $hex     <b>Impregnation:</b> $impregnation      <b>Strip:</b> $strip</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"250\"><b>Part Number:</b> $partnumber</td>
						<td valign=\"top\" width=\"380\"><b>Part Description:</b> $partdescription</td>
						<td valign=\"top\" width=\"170\"><b>Alloy:</b> $alloy</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"800\"><b>Specifications:</b> $specifications</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"230\"><b>Quantity:</b> $quantity</td>
						<td valign=\"top\" width=\"570\"><b>Color:</b> $color</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
						<td valign=\"top\" width=\"800\"><b>Repeat:</b> $repeat     <b>Internet:</b> $internet     <b>Internet Directory:</b> $internetdirectory     <b>Referral:</b> $referral     <b>Yellowpages:</b> $yellowpages     <b>Tradeshow:</b> $tradeshow</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"800\"><b>Other:</b> $other</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"800\"><b>Notes:</b> $notes</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td width=\"800\" valign=\"top\" height=\"30\" valign=\"middle\"><a href='delete_record.php?id=$id&field_data=$field_data'><b>Delete Request for Quote #$id</b></a></td>
					</tr>
				</table>
			</td></tr>";
   
    $y++;  //increment the counter 
      }//end while 
      echo "</table><br>"; 

  }else{ 
    //handle no results 
    echo "<tr><td colspan='20' align='center'><b>No data found.</b></td></tr>"; 
  }//endif 
} 


/************************************************************************* 
               add / update the contact's data 
*************************************************************************/ 
function process_form() 
{ 
  $id  = ''; 
  $name  = ''; 
  $company  = ''; 
  $address  = ''; 
  $city  = ''; 
  $zip  = ''; 
  $email  = ''; 
  $phone  = ''; 
  $fax  = ''; 
  $state  = ''; 
  $typeii     = ''; 
  $type3  = ''; 
  $burnish  = ''; 
  $chromate  = ''; 
  $hex  = ''; 
  $impregnation     = ''; 
  $strip  = ''; 
  $partnumber  = ''; 
  $partdescription  = ''; 
  $alloy  = ''; 
  $quantity     = ''; 
  $specifications  = ''; 
  $color  = ''; 
  $repeat  = ''; 
  $internet  = ''; 
  $internetdirectory     = ''; 
  $referral  = ''; 
  $yellowpages  = ''; 
  $tradeshow  = ''; 
  $other  = ''; 
  $notes  = ''; 
  $action = ''; 
  $status = 0;    //default value 

  $id  = @$_POST['id']; 
  $name  = @$_POST['name'];  
  $company  = @$_POST['company']; 
  $address  = @$_POST['address'];  
  $city  = @$_POST['city']; 
  $zip     = @$_POST['zip'];          
  $email  = @$_POST['email']; 
  $phone  = @$_POST['phone'];  
  $fax  = @$_POST['fax']; 
  $state  = @$_POST['state']; 
  $typeii  = @$_POST['typeii'];  
  $type3  = @$_POST['type3']; 
  $burnish     = @$_POST['burnish'];          
  $chromate  = @$_POST['chromate']; 
  $hex  = @$_POST['hex'];  
  $impregnation  = @$_POST['impregnation']; 
  $strip  = @$_POST['strip'];  
  $partnumber  = @$_POST['partnumber']; 
  $partdescription     = @$_POST['partdescription'];          
  $alloy  = @$_POST['alloy']; 
  $quantity  = @$_POST['quantity'];  
  $specifications  = @$_POST['specifications']; 
  $color  = @$_POST['color'];  
  $repeat  = @$_POST['repeat']; 
  $internet     = @$_POST['internet'];          
  $internetdirectory  = @$_POST['internetdirectory']; 
  $referral  = @$_POST['referral'];  
  $yellowpages  = @$_POST['yellowpages']; 
  $tradeshow  = @$_POST['tradeshow'];  
  $other  = @$_POST['other']; 
  $notes     = @$_POST['notes'];          
  $action = @$_GET['action']; 
  $status = @$_POST['status']; 
  
  //if no status is set, defaults to 0 (allow contact) 
  if ($status == ''){$status = 0; } 
    
  if (($name=='')||($company=='')||($address=='')||($city=='')||($zip=='')) 
  { 
    $msg = "Some data from the form was forgotten. Please fill in the entire form."; 
    confirm($msg); 
    $data = "$id|$name|$company|$address|$city|$zip|$email|$phone|$fax|$state|$typeii|$type3|$burnish|$chromate|$hex|$impregnation|$strip|$partnumber|$partdescription|$alloy|$quantity|$specifications|$color|$repeat|$internet|$internetdirectory|$referral|$yellowpages|$tradeshow|$other|$notes"; 
    show_form('',$data); 
    die(); 
  }//end if 
  
  //You could add some validation of the data ( I recommend it and its a great way to get your feet wet with php ) 

  if ($action == "add") 
  { 
    $sql = "insert into rfq (name, company, address, city, zip, email, phone, fax, state, typeii, type3, burnish, chromate, hex, impregnation, strip, partnumber, partdescription, alloy, quantity, specifications, color, repeat, internet, internetdirectory, referral, yellowpages, tradeshow, other, notes) values('{$name}','{$company}','{$address}','{$city}','{$zip}','{$email}','{$phone}','{$fax}','{$state}','{$typeii}','{$type3}','{$burnish}','{$chromate}','{$hex}','{$impregnation}','{$strip}','{$partnumber}','{$partdescription}','{$alloy}','{$quantity}','{$specifications}','{$color}','{$repeat}','{$internet}','{$internetdirectory}','{$referral}','{$yellowpages}','{$tradeshow}','{$other}','{$notes}');"; 
    $msg = "Record successfully added"; 
  }elseif($action=="edit"){ 
    $sql = "update rfq set name = '{$name}', company = '{$company}', address = '{$address}', city = '{$city}', zip = '{$zip}', email = '{$email}', phone = '{$phone}', fax = '{$fax}', state = '{$state}', typeii = '{$typeii}', type3 = '{$type3}', burnish = '{$burnish}', chromate = '{$chromate}', hex = '{$hex}', impregnation = '{$impregnation}', strip = '{$strip}', partnumber = '{$partnumber}', partdescription = '{$partdescription}', alloy = '{$alloy}', quantity = '{$quantity}', specifications = '{$specifications}', color = '{$color}', repeat = '{$repeat}', internet = '{$internet}', internetdirectory = '{$internetdirectory}', referral = '{$referral}', yellowpages = '{$yellowpages}', tradeshow = '{$tradeshow}', other = '{$other}', notes = '{$notes}' where id = {$id};"; 
    $msg = "Record successfully updated"; 
  } 
  $result = conn($sql); 
  if (mysql_errno()==0) 
  { 
    confirm($msg); 
    list_users(); 
  }else{ 
    $msg = "There was a problem adding the user to the database. Error is:".mysql_error(); 
    confirm($mag); 
  }//end if 
      
} 



/************************************************************************* 
               db connection function 
*************************************************************************/ 
function conn($sql) 
{    

//connection string was here but i moved it 


    //echo "commnecing connection to local db<br>"; 
    
    if (!($conn=mysql_connect($host, $user, $pass)))  { 
        printf("error connecting to DB by user = $user and pwd=$pass"); 
        exit; 
    } 
    $db3=mysql_select_db($db,$conn) or die("Unable to connect to local database"); 

    $result = mysql_query($sql) or die ("Can't run query because ". mysql_error()); 
    
    return $result; 
    
}//end function      

/************************************************************************* 
               alert box popup confimation message function 
*************************************************************************/ 
function confirm($msg) 
{ 
  echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>"; 
}//end function 

?>

[/code]

REPEAT is a MySQL reserved word.

 

http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

 

Avoid using reserved words for table names or field names.

 

Good solution = rename the field called repeat to something else.

 

Quick'n'dirty fix = use `backticks` around reserved words.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.