RE: [PHP] how to concatenate php variables in mysql query

From: Date: Wed, 22 Sep 2004 14:18:14 +0000
Subject: RE: [PHP] how to concatenate php variables in mysql query
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-197572@lists.php.net to get a copy of this message
Luke, MySQL has a built in CONCAT function. This will concat two strings togther. In your example it would look like telephone_number = CONCAT('$telcode', '$telnumber') ... See the MySQL manual for more info on the concat function. Of course using this function will force the data to be a string. Yoed -----Original Message----- From: luke@lukem.co.uk [mailto:luke@lukem.co.uk] Sent: Wednesday, September 22, 2004 7:47 AM To: Jay Blanchard; php-general@lists.php.net Subject: Re: [PHP] how to concatenate php variables in mysql query here is the whole query: $query = "INSERT INTO inmarsat_comp SET date_added=NOW(), prefix='$prefix', firstname='$firstname', lastname='$lastname', job_title='$jobtitle', company_name='$company', no_of_employees='$employees',address_1='$address1',address_2='$address2', address_3='$address3', town='$town', county ='$county', postcode='$postcode', country ='$country', telephone_number='$telcode.$telnumber', fax_number='$faxcode.$faxnumber', email='$email', enterprise='$enterprises', optin_thirdparty='$distribute', optin_news='$market'"; only the telcode gets inserted. many thanks, luke m "Jay Blanchard" <jay.blanchard@niicommunications.com> wrote: > [snip] > telphone number =$telcode.$telnumber' > > but only the telcode gets written to the database. > [/snip] > > There is not enough here to know for sure (I am betting this is part > of a query), but if your code looks like the above you are missing a > single quote after the =. Now, if you enclose the variables in the > single quotes without other manipulation it will probably not work as > expected. Can we see the whole query? > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#197572) next »