Link to home
Start Free TrialLog in
Avatar of pingeyeg
pingeyeg

asked on

SQL is not retrieving the form data on certain fields.

Not sure why, but my sql statement is not retrieving what my form is sending out.  I have triple checked to make sure the variables are correct.  I'm not sure if it means anything, but the two that are not being retrieved are longtext strings in phpMyAdmin.

                   $strProviderservice = $_REQUEST['strProviderservice'];
            $strCompanyname = $_REQUEST['strCompanyname'];
            $strOwner = $_REQUEST['strOwner'];
            $strAddress = $_REQUEST['strAddress'];
            $strTown = $_REQUEST['strTown'];
            $strZipcode = $_REQUEST['strZipcode'];
            $strPhone = $_REQUEST['strPhone'];
            $str2ndphone = $_REQUEST['str2ndphone'];
            $strMobile = $_REQUEST['strMobile'];
            $strPager = $_REQUEST['strPager'];
            $strFax = $_REQUEST['strFax'];
            $strEmail = $_REQUEST['strEmail'];
            $strWebsite = $_REQUEST['strWebsite'];
            $strInbusiness_since = $_REQUEST['strInbusiness_since'];
            $strLicense = $_REQUEST['strLicense'];
            $strInsured = $_REQUEST['strInsured'];
            $strBonded = $_REQUEST['strBonded'];
            $strHours = $_REQUEST['strHours'];
            $str24houremerg = $_REQUEST['str24houremerg'];
            $strServicesoffered = $_REQUEST['strServicesoffered'];
            $strOtherservices = $_REQUEST['strOtherservices'];
            $strServicearea = $_REQUEST['strServicearea'];
            $strFreeestimate = $_REQUEST['strFreeestimate'];
            $strWorkguaranteed = $_REQUEST['strWorkguaranteed'];
            $strProvidertagline = $_REQUEST['strProvidertagline'];
            $strAd_size = $_REQUEST['strAd_size'];

$SQL = "INSERT INTO tblAdspace VALUES"
     . "("
     . "strProviderservice, strCompanyname, strOwner, strAddress, strTown, "
     . "strZipcode, strPhone, str2ndphone, "
     . "strMobile, strPager, strFax, "
     . "strEmail, strWebsite, strLicense, "
     . "strBonded, strHours, str24houremerg, strServicesoffered, "
     . "strOtherservices, strServicearea, strFreeestimate, strWorkguaranteed, strProvidertagline, strAd_size"
     . ") "
     . "VALUES("
     . "'" . $strProviderservice . "',"
     . "'" . $strCompanyname . "',"
     . "'" . $strOwner . "',"
     . "'" . $strAddress . "',"
     . "'" . $strTown . "',"
     . "'" . $strZipcode . "',"
     . "'" . $strPhone . "',"
     . "'" . $str2ndphone . "',"
     . "'" . $strMobile . "',"
     . "'" . $strPager . "',"
     . "'" . $strFax . "',"
     . "'" . $strEmail . "',"
     . "'" . $strWebsite . "',"
     . "'" . $strLicense . "',"
     . "'" . $strBonded . "',"
     . "'" . $strHours . "',"
     . "'" . $str24houremerg . "',"
     . "'" . str_replace("'", "''", $strOtherservices) . "',"
       . "'" . str_replace("'", "''", $strServicesoffered) . "', "
     . "'" . $strServicearea . "',"
     . "'" . $strFreeestimate . "',"
     . "'" . $strWorkguaranteed . "',"
     . "'" . str_replace("'", "''", $strProvidertagline) . "',"
     . "'" . $strAd_size . "'"
     . ") ";
      
       echo $SQL;
       die;
Avatar of pingeyeg
pingeyeg

ASKER

This is kind of bits and pieces of the whole page.  Didn't think you would need the entire page.
Have you tried changing the attribute type to VARCHAR() just to see if it is the data type that is causing an issue ?

Just out of curiosity, why are you concatinating all your attribute values into your DB ?
try doing this:
<?
print "<pre>";
print $SQL;
print "</pre>";
?>

at the end of your page and see if the variables are being passed correctly.

if they aren't, try this:

before assigning variables that use the $_REQUEST variable, assign the $_REQUEST variable yourself like this:

$_REQUEST = ( isset($_REQEST) && !empty($_REQUEST) ) ? $_REQUEST : array_merge($_GET, $_POST);
with further studying of your code, i've noticed something else. your sql is formatted incorrectly, and the syntax is wrong (line 1, char 24-29). this should be correct now:

$SQL = "INSERT INTO tblAdspace
     . "("
     . "strProviderservice, strCompanyname, strOwner, strAddress, strTown, "
     . "strZipcode, strPhone, str2ndphone, "
     . "strMobile, strPager, strFax, "
     . "strEmail, strWebsite, strLicense, "
     . "strBonded, strHours, str24houremerg, strServicesoffered, "
     . "strOtherservices, strServicearea, strFreeestimate, strWorkguaranteed, strProvidertagline, strAd_size"
     . ") "
     . "VALUES("
     . "'" . $strProviderservice . "',"
     . "'" . $strCompanyname . "',"
     . "'" . $strOwner . "',"
     . "'" . $strAddress . "',"
     . "'" . $strTown . "',"
     . "'" . $strZipcode . "',"
     . "'" . $strPhone . "',"
     . "'" . $str2ndphone . "',"
     . "'" . $strMobile . "',"
     . "'" . $strPager . "',"
     . "'" . $strFax . "',"
     . "'" . $strEmail . "',"
     . "'" . $strWebsite . "',"
     . "'" . $strLicense . "',"
     . "'" . $strBonded . "',"
     . "'" . $strHours . "',"
     . "'" . $str24houremerg . "',"
     . "'" . str_replace("'", "''", $strOtherservices) . "',"
       . "'" . str_replace("'", "''", $strServicesoffered) . "', "
     . "'" . $strServicearea . "',"
     . "'" . $strFreeestimate . "',"
     . "'" . $strWorkguaranteed . "',"
     . "'" . str_replace("'", "''", $strProvidertagline) . "',"
     . "'" . $strAd_size . "'"
     . ") ";
Oscurochu, with your code I am getting a parse error:  Line  . "("
Ok, Oscurochu, I found what was missing in your code, but it still isn't working.  I don't think the problem lies in the sql statement, I think the problem is in the $_REQUEST portion of the page, because most of the values are being brought in, only two aren't.  The two that aren't are formatted in phpMyAdmin as Longtext.
Tchuki, what do you mean by using the VARCHAR() ?
Why are you concatinating your vars into the DB ?

What are the column attribute names in your tblAdspace ?
I was told it would be easier to read the code towards troubleshooting.
SOLUTION
Avatar of Vel Eous
Vel Eous

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I tried making an update with field that is a regular text value and it works, but the two that are longtext aren't working.
Have you tried changing the fields to VARCHAR and seeing if any information is inserted ?!
Can you show me how to do that?  I don't know what VARCHAR is.
Go into phpMyAdmin, select your table and change the field type in there.
Ok, just out of curiosity, what would you change it to if the field needs to have 300 characters in it?
longtext should be the one you go for.

That said, try what I have suggested and see if the information is inserted.

We need to assertain if it is your PHP $_POST vars, SQL statement or DB itself that is having the issue.
RIght now the field type is already longtext for those two fields.
Yes, try changing it to VARCHAR and see if any information is collected that way ...
That didn't do the trick.
OK, which are the two fields that are not being inserted, what are their names ?
strServicesoffered and strOtherservices
Does strProvidertagline insert correctly ?
Apparently it does not.  Huh.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Still nothing.  What was that supposed to do anyway?
Isn't that funtion supposed to work like that?  When people add text to these boxes they will most certainly be using apostrophes on certain word.  How will he addslashes function change that?
Nevermind, that did work.  I saw one other thing that I had extra that was conflicting with your statement.  It now works.  I don't know why, but now all of a sudden I can't change anything in phpMyAdmin without it kicking me out again.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Woops

echo $str; // output: This string\'s been escaped

Should be:

echo $str; // output: This strings\' been escaped


Also with regards to you being kicked from phpMyAdmin, you probably need to refresh your cookie or something.  Try logging out, closing the browser completely and then going back to phpMyAdmin.