HELP - PHP not writing 2 specific fields to MYSQL DB??

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
camarosource
Forum Commoner
Posts: 77
Joined: Sat Aug 03, 2002 10:43 pm

HELP - PHP not writing 2 specific fields to MYSQL DB??

Post by camarosource »

I'm doing a php script that writes the results of a filled out html form to a database and emails me a brief summary of what was written. I have a strange problem where it writes all the info to the DB except 2 of the MYSQL Fields are empty yet the rest carry on being filled out.

For example: If you fill out all the fields in http://www.camarosource.ca/2006_calenda ... s_2006.htm and submit, it writes the info to the DB, but leaves out the ICQ, and CITY are both BLANK.YET the brief summary emailed to me shows it in fact saved the ICQ and CITY in it's correct variables so this means it's not WRITTING them to the DB..

Code: Select all

<?php

// create connection
$conn = mysql_connect("localhost","&#1111;PRIVATE]","&#1111;PRIVATE]")
or die(mysql_error());

// select database
$db = mysql_select_db("&#1111;PRIVATE]", $conn) or die(mysql_error());

// Set entered fields in Request Field as assigned variables

$NAME = $_POST&#1111;'FULL_NAME'];
$EMAIL = $_POST&#1111;'EMAIL'];
$URL = $_POST&#1111;'URL'];
$ICQ = $_POST&#1111;'ICQ'];
$MSN = $_POST&#1111;'MSN'];
$AIM = $_POST&#1111;'AIM'];
$YAHOO = $_POST&#1111;'YAHOO'];
$ADDRESS = $_POST&#1111;'ADDRESS'];
$CITY = $_POST&#1111;'CITY'];
$PROVINCE_STATE = $_POST&#1111;'PROVINCE_STATE'];
$COUNTRY = $_POST&#1111;'COUNTRY'];
$POSTAL_ZIP = $_POST&#1111;'POSTAL_ZIP'];
$YEAR = $_POST&#1111;'CAMARO_YEAR'];
$MODEL = $_POST&#1111;'CAMARO_MODEL'];
$PREFERRED_MONTH = $_POST&#1111;'PREFERRED_MONTH'];
$SAID_TO_PURCHASE = $_POST&#1111;'SAID_TO_PURCHASE'];
$SPECIAL_DATE = $_POST&#1111;'SPECIAL_DATE'];
$CUSTOM_TITLE = $_POST&#1111;'CUSTOM_TITLE'];
$PERSONALIZED_INFO = $_POST&#1111;'PERSONALIZED_INFO'];

$MISSING = false;



//Start IF fields were blank
if ($NAME == "") &#123;
   $MISSING = true;
   echo "<p><font color="#FF0000" size="4"><b>Please enter your FULL NAME</b></font></p>";
&#125;

if ($EMAIL == "") &#123;
   $MISSING = true;
   echo "<p><font color="#FF0000" size="4"><b>Please enter your EMAIL Address</b></font></p>";
&#125;

if ($ADDRESS == "") &#123;
   $MISSING = true;
   echo "<p><font color="#FF0000" size="4"><b>Please enter your ADDRESS</b></font></p>";
&#125;

if ($CITY == "") &#123;
   $MISSING = true;
   echo "<p><font color="#FF0000" size="4"><b>Please enter your CITY</b></font></p>";
&#125;

if ($PROVINCE_STATE == "") &#123;
   $MISSING = true;
   echo "<p><font color="#FF0000" size="4"><b>Please enter your PROVINCE / STATE</b></font></p>";
&#125;

if ($COUNTRY == "--- Please Select ---") &#123;
   $MISSING = true;
   echo "<p><font color="#FF0000" size="4"><b>Please select your COUNTRY</b></font></p>";
&#125;

if ($POSTAL_ZIP == "") &#123;
   $MISSING = true;
   echo "<p><font color="#FF0000" size="4"><b>Please enter your ZIP / POSTAL CODE</b></font></p>";
&#125;

if ($YEAR == "") &#123;
   $MISSING = true;
   echo "<p><font color="#FF0000" size="4"><b>Please enter the YEAR of your Camaro</b></font></p>";
&#125;

if ($MODEL == "") &#123;
   $MISSING = true;
   echo "<p><font color="#FF0000" size="4"><b>Please enter the MODEL of your Camaro</b></font></p>";
&#125;

if ($SAID_TO_PURCHASE == "--- Please Select ---") &#123;
   $MISSING = true;
   echo "<p><font color="#FF0000" size="4"><b>For Reference Purposes - Please specify how many calendars you would be interested in.</b></font></p>";
&#125;

if ($PERSONALIZED_INFO == "") &#123;
   $MISSING = true;
   echo "<p><font color="#FF0000" size="4"><b>Please enter your PERSONALIZED INFO.. This is what you want to have said in your Camaro Info bubble. Ie. Car specs, Mods, etc</b></font></p>";
&#125;

 if ($MISSING) exit;


// ------------------- Processing submitted data

 // build our query 
   $query = "INSERT INTO user_submissions(FULL_NAME, EMAIL, URL, ICQ, MSN, AIM, YAHOO, ADDRESS, CITY, PROVINCE_STATE, COUNTRY, POSTAL_ZIP,
   CAMARO_YEAR, CAMARO_MODEL, PREFERRED_MONTH, SAID_TO_PURCHASE, SPECIAL_DATE, CUSTOM_TITLE, PERSONALIZED_INFO, COMMENTS)
   VALUES ('$NAME', '$EMAIL', '$URL', '$ICQ', '$MSN', '$AIM', '$YAHOO', '$ADDRESS', '$CITY', '$PROVINCE_STATE', '$COUNTRY', '$POSTAL_ZIP', '$CAMARO_YEAR',
   '$CAMARO_MODEL', '$PREFERRED_MONTH', '$SAID_TO_PURCHASE', '$SPECIAL_DATE', '$CUSTOM_TITLE', '$PERSONALIZED_INFO', '$COMMENTS')";
    
   // execute the query 
   mysql_query($query, $conn) or die (mysql_error()); 






submit() ;

 // ------------------------------ &#1111; Start compiling Application email to be sent to ME ] -----------------------------
function submit() &#123;

$msg = "The following Person is interested in being in the 2006 Camarosource.ca Camaro Calendar. CHECK THE DATABASE\n\n";
$msg .= "Real Full Name : \t$_POST&#1111;FULL_NAME]\n";
$msg .= "Email Address : \t$_POST&#1111;EMAIL]\n";
$msg .= "Webpage URL : \t$_POST&#1111;URL]\n";
$msg .= "ICQ : \t$_POST&#1111;ICQ]\n";
$msg .= "CITY : \t$_POST&#1111;CITY]\n";
$msg .= "MSN : \t$_POST&#1111;MSN]\n";
$msg .= "AIM : \t$_POST&#1111;AIM]\n";
$msg .= "Yahoo! : \t$_POST&#1111;YAHOO]\n";

$msg .= "Comments : \t$_POST&#1111;COMMENTS]\n";

$mailheaders = "From: \t$_POST&#1111;EMAIL]\n";
$mailheaders .= "Reply-To: \t$_POST&#1111;EMAIL]\n\n";
mail("PRIVATE","&#1111;PRIVATE]: 2006 Camaro Calendar Submission - INFO", $msg, $mailheaders);

&#125;

?>
I checked and the field for the ICQ and CITY ARE in fact "ICQ" "CITY" and the MYSQL database fields are also "ICQ" and "CITY".. I don't understand why it's skipping over those 2 fields and continuing to write to the rest like normally. It's like 3 fields filled in correctly, then BLANK ICQ , then 4 fields filled in correctly, then BLANK CITY, and the last 11 fields filled out correctly..
mrmachoman
Forum Newbie
Posts: 5
Joined: Sat Jan 22, 2005 6:36 pm

Post by mrmachoman »

Tested your code and it works fine (with a few non-critical changes). Normally when I ran into this problem it was a case-sensitivity issue from the POSTing screen. Checked your webpage. Looks good. Sorry, works fine on my box.

If your still having problems I would suggest some echo statements to ensure data is coming from POST screen correctly. Also maybe echo $query to its seeing data correct.
camarosource
Forum Commoner
Posts: 77
Joined: Sat Aug 03, 2002 10:43 pm

Post by camarosource »

mrmachoman wrote:Tested your code and it works fine (with a few non-critical changes). Normally when I ran into this problem it was a case-sensitivity issue from the POSTing screen. Checked your webpage. Looks good. Sorry, works fine on my box.

If your still having problems I would suggest some echo statements to ensure data is coming from POST screen correctly. Also maybe echo $query to its seeing data correct.
Nothing is wrong with the PHP, it now seems to be something wrong with MYSQL.

I am getting SOOO fustrated with this!!! I have now spent over 8 HOURS on this bloody thing!!

I DELETED the entire table and started over. STILL doing it.

So I then realized I didn't have a Primary ID field so the rows contained the same exact info. So I added a "SUBMISSIONS_ID" and it auto-increments.

however NOW, the the fields that are blank have been moved 1 to the LEFT. !! So NOW ICQ works, but URL that is to the LEFT of it is now the one blank, and the CITY works but NOW the one to the LEFT of that which is ADDRESS is now BLANK..

What the ????

I have DELETED the table and re-created it and it STILL doesn't work??? If I added 1 more field to the beginning, it would move the blank fields 1 MORE to the LEFT and the one that were not working before will work and the one to the LEFT of that will now be the ones blank...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

can you post the SQL call that created the table structure? I need to see the whole sql call, not just the types and junk..

Moved to Databases.
camarosource
Forum Commoner
Posts: 77
Joined: Sat Aug 03, 2002 10:43 pm

Post by camarosource »

feyd wrote:can you post the SQL call that created the table structure? I need to see the whole sql call, not just the types and junk..

Moved to Databases.
CREATE TABLE `user_submissions` (
`SUBMISSION_ID` int(5) NOT NULL auto_increment,
`FULL_NAME` varchar(50) NOT NULL default '',
`EMAIL` varchar(50) NOT NULL default '',
`URL` varchar(45) NOT NULL default '',
`ICQ` varchar(45) NOT NULL default '',
`MSN` varchar(40) NOT NULL default '',
`AIM` varchar(40) NOT NULL default '',
`YAHOO` varchar(40) NOT NULL default '',
`ADDRESS` varchar(50) NOT NULL default '',
`CITY` varchar(50) NOT NULL default '',
`PROVINCE_STATE` varchar(40) NOT NULL default '',
`COUNTRY` varchar(50) NOT NULL default '',
`POSTAL_ZIP` varchar(50) NOT NULL default '',
`CAMARO_YEAR` varchar(50) NOT NULL default '',
`CAMARO_MODEL` varchar(50) NOT NULL default '',
`PREFERRED_MONTH` varchar(40) NOT NULL default '',
`SAID_TO_PURCHASE` varchar(40) NOT NULL default '',
`SPECIAL_DATE` varchar(40) NOT NULL default '',
`CUSTOM_TITLE` varchar(40) NOT NULL default '',
`PERSONALIZED_INFO` varchar(40) NOT NULL default '',
`COMMENTS` varchar(40) NOT NULL default '',
`PICS_UPLOADED` varchar(40) NOT NULL default '',
`PICS_NUM_UPLOADED` varchar(40) NOT NULL default '',
`PICS_QUALITY_RATING` varchar(40) NOT NULL default '',
`43` varchar(40) NOT NULL default '',
`32` varchar(40) NOT NULL default '',
`67` varchar(40) NOT NULL default '',
`8` varchar(40) NOT NULL default '',
`234` varchar(40) NOT NULL default '',
`3` varchar(40) NOT NULL default '',
`57` varchar(40) NOT NULL default '',
`ADMIN_COMMENTS` varchar(40) NOT NULL default '',
PRIMARY KEY (`SUBMISSION_ID`)
) TYPE=MyISAM AUTO_INCREMENT=37 ;

Everything is VARCHAR just for experimenting I will obviously fix this.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

okay.. can you post now an example of a "real" sql insert you're doing? i.e. echo the sql some place (make sure to copy it from the source and not the browser please.
camarosource
Forum Commoner
Posts: 77
Joined: Sat Aug 03, 2002 10:43 pm

Post by camarosource »

feyd wrote:okay.. can you post now an example of a "real" sql insert you're doing? i.e. echo the sql some place (make sure to copy it from the source and not the browser please.
INSERT INTO user_submissions SET FULL_NAME = 'Paul Lodge22', EMAIL = 'camaro92@telus.net', URL = 'http://www.camarosource.ca', ICQ = '6705249', MSN = 'camaro92@telus.net', AIM = 'camarosource', YAHOO = 'camarosource', ADDRESS = '777 Fyr Street', CITY = 'Burnaby', PROVINCE_STATE = 'BC', COUNTRY = 'Canada', POSTAL_ZIP = 'V7G7A7', CAMARO_YEAR = '1992', CAMARO_MODEL = 'Z28', PREFERRED_MONTH = 'June', SAID_TO_PURCHASE = '10', SPECIAL_DATE = 'special', CUSTOM_TITLE = 'custom', PERSONALIZED_INFO = 'lalalaladfdsafds', COMMENTS = 'sfdsdfsaf99'
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

interesting.. that fails for me as well.. I'll play around with it and see what comes up..
camarosource
Forum Commoner
Posts: 77
Joined: Sat Aug 03, 2002 10:43 pm

Post by camarosource »

feyd wrote:interesting.. that fails for me as well.. I'll play around with it and see what comes up..
If I post that DIRECTLY into the SQL Query in PhpMyAdmin, it creates the row but AGAIN those two (now URL and ADDRESS since adding the "SUBMISSIONS_ID" to the beginning now moved everything 1 to the right causing the problem to move 1 to the left.) are still blank.
camarosource
Forum Commoner
Posts: 77
Joined: Sat Aug 03, 2002 10:43 pm

Post by camarosource »

when you say it fails for you too.. What exactly is happening and what are you doing?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the numbered field names are clearing the values... you must be using mysql_fetch_row or mysql_fetch_array in your select and only using the numbered indexes, I'd bet. That's why phpMyAdmin screws up.

Congrats, you found a bug in phpMyAdmin. :)
Last edited by feyd on Sat Jan 22, 2005 9:06 pm, edited 1 time in total.
camarosource
Forum Commoner
Posts: 77
Joined: Sat Aug 03, 2002 10:43 pm

Post by camarosource »

feyd wrote:the numbered field names are clearing the values... you must be using mysql_fetch_row or mysql_fetch_array in your select and only using the numbered indexes, I'd bet. That's why phpMyAdmin screws up.
YOu GOT IT!! I deleted the numbered fields and they works!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The bug report can be found here for it: http://sourceforge.net/tracker/index.ph ... tid=377408

too bad you didn't find a new bug ;)
Post Reply