By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,826 Members | 1,333 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,826 IT Pros & Developers. It's quick & easy.

Will this work

P: n/a
Hi all,

I was wondering if it is possible to format variables from within the VALUES
section of a mysql INSERT string.

I have some variables that are passalong from a script and get deposited to
a mysql db.

since end users can submit in all uppercase or lower case, i was looking for
some data normalization.

so I am going to apply ucwords(strtolower($variable1));

but in the name of keeping the script as small and sweet as possible can i
do

mysql_query ("INSERT INTO 10m (firstname, lastname, zipcode, email, 10mdate,
entrydate, termsagree)
VALUES ('ucwords(strtolower($firstname));',
'ucwords(strtolower($variable1));', '$zipcode', '$email',
'$month--$day-$year', '$entrydate', '$termsagree')");

etc etc.

or do i have to do

$fixed_variable1=ucwords(strtolower($variable1));
$fixed_variable2=ucwords(strtolower($variable2));

mysql_query ("INSERT INTO 10m (firstname, lastname, zipcode, email, 10mdate,
entrydate, termsagree)
VALUES ('$fixed_firstname', '$fixed_lastname', '$zipcode',
'$email', '$month--$day-$year', '$entrydate', '$termsagree')");

i think you get the idea.

i would prefer the former vs the latter since there are about 10 variables
to rewrite....

Cheers,

Gary
Curwe.com
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Curwe Support <su**********@curwe.com> wrote:
I was wondering if it is possible to format variables from within the
VALUES section of a mysql INSERT string.

mysql_query ("INSERT INTO 10m (firstname, lastname, zipcode, email,
10mdate, entrydate, termsagree)
VALUES ('ucwords(strtolower($firstname));',
'ucwords(strtolower($variable1));', '$zipcode', '$email',
'$month--$day-$year', '$entrydate', '$termsagree')");


Hi Gary,

Not quite in this form, but there is a solution. I suggest though you
construct the statement string beforehand. Gives a much cleaner code layout
and more control. And in case you use an editor with highlighting you'll
see another benefit.

$SQL = "INSERT INTO 10m (firstname, lastname, zipcode, email, " .
"10mdate, entrydate, termsagree) VALUES (" .
"'".ucwords(strtolower($firstname))."', " .
"'".ucwords(strtolower($variable1))."', " .
"'".$zipcode."', " .
"'".$email."', " .
"'".$month."-".$day."-".$year."', " .
"'".$entrydate."', " .
"'".$termsagree."')";

mysql_query($SQL) or die (mysql_error()."<br />".$SQL);

HTH;
JOn
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.