Re: how to concatenate php variables in mysql query

From: Date: Wed, 22 Sep 2004 13:15:54 +0000
Subject: Re: how to concatenate php variables in mysql query
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-197563@lists.php.net to get a copy of this message
From: <luke@lukem.co.uk>
$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.
Are you -sure- $telnumber has a value? With that query, you will see both the $telcode and the $telnumber in your database, but because of the way you're doing it, you'll see the literal period you have in the string, too. Now, if "telephone_number" is a numeric column, everything after the non-numeric period character will be truncated (but then why do you have quotes). So, solution is to join the two outside of the query: $telnum = $telcode . $telnumber $query = " ... telephone_number = '$telnum' ... "; or escape out of the string to join them in the query... $query = " ... = '$country', telephone_number = '" . $telcode . $telnumber . "', fax_number ... "; ---John Holmes...

« previous php.general (#197563) next »