Jump to content

php syntax


natalieG

Recommended Posts

Hi Folks-
We cannot seem to insert rows into a mysql table. Thje table create definition is below.
immediately below that is the Insert query. Below that is the html form drivineg the iINSERT
code. Below that is the code assigneing the insert values And finally, in the last block is the mysql error message.[in RED]; We filled in all fields in the form and the SHOW COLUMNS for $COMPANYTABLE shows every column can have a NULL value. We then ran a small cgi utility we wrote to show the fields names and values and they are all correct.

Hope this isn;t too much data to describe the problem, but we are getting exasperated
and want to document clearly
-------------------------------------------------------------------------------------------------------
[!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]$COMPANYS_QUERY="CREATE TABLE IF NOT EXISTS $COMPANYSTABLE(
COMPANY_INDEX INTEGER AUTO_INCREMENT,
COMPANY_NAME VARCHAR($FIELD_LENGTH),
COMPANY_REP VARCHAR(25),
COMPANY_ADDRESS1 VARCHAR($FIELD_LENGTH),
COMPANY_ADDRESS2 VARCHAR($FIELD_LENGTH),
COMPANY_CITY VARCHAR($FIELD_LENGTH),
COMPANY_STATE VARCHAR(10),
COMPANY_ZIPCODE VARCHAR(12),
COMPANY_PHONE VARCHAR(20),
COMPANY_ADMIN VARCHAR($FIELD_LENGTH),
COMPANY_EMAIL VARCHAR($FIELD_LENGTH),
COMPANY_WEBSITE VARCHAR($FIELD_LENGTH),
COMPANY_DATE VARCHAR(30),
COMPANY_ENTRYDATE TIMESTAMP($TIME_FORMAT),
PRIMARY KEY (COMPANY_INDEX))";[!--colorc--][/span][!--/colorc--]
------------------------------------------------------------------------------------------------------
[!--coloro:#3366FF--][span style=\"color:#3366FF\"][!--/coloro--]$COMPANYADDQUERY="INSERT INTO ATMELPIM_COMPANYS(
COMPANY_INDEX,
COMPANY_NAME,
COMPANY_REP,
COMPANY_ADDRESS1,
COMPANY_ADDRESS2,
COMPANY_CITY,
COMPANY_STATE,
COMPANY_ZIPCODE,
COMPANY_PHONE,
COMPANY_ADMIN,
COMPANY_EMAIL,
COMPANY_WEBSITE,
COMPANY_DATE,
COMPANY_ENTRYDATE)VALUES(
NULL,
$COMPANY_NAME,
$COMPANY_REP,
$COMPANY_ADDRESS1,
$COMPANY_ADDRESS2,
$COMPANY_CITY,
$COMPANY_STATE,
$COMPANY_ZIPCODE,
$COMPANY_PHONE,
$COMPANY_ADMIN,
$COMPANY_EMAIL,
$COMPANY_WEBSITE,
$DATESTR,
$NOWDATETIME)";[!--colorc--][/span][!--/colorc--]-
----------------------------------------------------------------------------------------------------------------
$COMPANY_REP=$REQUEST['COMPANY_REP'];
$COMPANY_NAME=$_REQUEST['COMPANY_NAME'];
$COMPANY_ADDRESS1=$_REQUEST['COMPANY_ADDRESS1'];
if (isset($_REQUEST['COMPANY_ADDRESS2']))
{$COMPANY_ADDRESS2=$_REQUEST['COMPANY_ADDRESS2'];}
ELSE {$COMPANY_ADDRESSS2='';}
$COMPANY_CITY=$_REQUEST['COMPANY_CITY'];
$COMPANY_STATE=$_REQUEST['COMPANY_STATE'];
$COMPANY_ZIPCODE=$_REQUEST['COMPANY_ZIPCODE'];
$COMPANY_PHONE=$_REQUEST['COMPANY_PHONE'];
$COMPANY_ADMIN=$_REQUEST['COMPANY_ADMIN'];
$COMPANY_EMAIL=$_REQUEST['COMPANY_EMAIL'];
$COMPANY_WEBSITE=$_REQUEST['COMPANY_WEBSITE'];
$DATESTR=strftime('%A,%B %d');
$NOWDATETIME=time();
-------------------------------------------------------------------------------------------
<form action="http://msdsimaging.com/atmelpim/addcompany.php" method="get" name="addcompany">
<table width="590" border="0" cellspacing="=" cellpadding="1" bgcolor="#DDDDDD">
<tr><td colspan="2" align="center" width="588">
<div class="headerclass">ADD COMPANY TO PIM</div>
</td></tr>
<tr><td width="165">
<div class="firstclass">NAME</div></td>
<td width="421"><input type="text" name="COMPANY_NAME" size="50" maxlength="50"order="0">
</td></tr>
<tr><td width="165"><div class="firstclass">REP COMPANY</div></td>
<td width="421"><input type="text" name="COMPANY_REP" size="50" maxlength="200" border="0"></td></tr>
<tr><td width="165">
<div class="firstclass">ADDRESS-1</div></td>
<td width="421"><input type="text" name="COMPANY_ADDRESS1" size="50" maxlength="100" border="0"></td></tr>
<tr><td width="165"><div class="firstclass">ADDRESS-2</div></td>
<td width="421"><input type="text" name="COMPANY_ADDRESS2" size="50" border="0" maxlength="100"></td></tr>
<tr><td width="165"><div class="firstclass">CITY</div></td>
<td width="421"><input type="text" name="COMPANY_CITY" size="40" border="0">
</td></tr>
<td width="165"><div class="firstclass">STATE</div> </td>
<td width="421"><input type="text" name="COMPANY_STATE" size="10" maxlength="10" border="0"></td></tr>
<tr><td width="165"><div class="firstclass">ZIPCODE</div></td>
<td> width="421"><input type="text" name="COMPANY_ZIPCODE" size="10" maxlength="10" border="0"></td>
</tr><tr><td width="165"><div class="firstclass">PHONE</div></td>
<td width="421"><input type="text" name="COMPANY_PHONE" size="20" maxlength="20" border="0"></td></tr>
<tr><td width="165"><div class="firstclass">ADMIN</div></td>
<td width="421"><input type="text" name="COMPANY_ADMIN" size="50" maxlength="50" border="0"></td></tr>
<tr><td width="165"> <div class="firstclass">EMAIL</div></td>
<td width="421"><input type="text" name="COMPANY_EMAIL" size="50" maxlength="100" border="0"></td></tr>
<tr><td width="165"> <div class="firstclass">WEBSITE</div></td>
<td width="421"><input type="text" name="COMPANY_WEBSITE" size="50" maxlength="100" border="0"></td></tr>
<tr><td colspan="2" align="center" width="588"><input type="submit" name="submitButtonName" border="0" value="Add"><input type="reset" border="0"></td></tr>
</table></form>
------================================================================
[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]Cannot Insert Into COMPANY TableYou have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ' address1, address2, dallas, tx, 75080, 972-437-999[!--colorc--][/span][!--/colorc--]
Link to comment
Share on other sites

Strings in a query need to be delimited by single quotes:
[code]<?php
$COMPANYADDQUERY="INSERT INTO ATMELPIM_COMPANYS(
COMPANY_INDEX,
COMPANY_NAME,
COMPANY_REP,
COMPANY_ADDRESS1,
COMPANY_ADDRESS2,
COMPANY_CITY,
COMPANY_STATE,
COMPANY_ZIPCODE,
COMPANY_PHONE,
COMPANY_ADMIN,
COMPANY_EMAIL,
COMPANY_WEBSITE,
COMPANY_DATE,
COMPANY_ENTRYDATE)VALUES(
NULL,
'$COMPANY_NAME',
'$COMPANY_REP',
'$COMPANY_ADDRESS1',
'$COMPANY_ADDRESS2',
'$COMPANY_CITY',
'$COMPANY_STATE',
'$COMPANY_ZIPCODE',
'$COMPANY_PHONE',
'$COMPANY_ADMIN',
'$COMPANY_EMAIL',
'$COMPANY_WEBSITE',
'$DATESTR',
'$NOWDATETIME')"; ?>[/code]

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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