473,388 Members | 1,385 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Will this work

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
1 1608
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Antoon Pardon | last post by:
I have had a look at the signal module and the example and came to the conclusion that the example wont work if you try to do this in a thread. So is there a chance similar code will work in a...
7
by: jason | last post by:
I am getting twisted by the possibility that my virtual includes which currently work great on non-domain remote IP will crash if I purchase a domain and point it to one of my designated...
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
3
by: Zheng Da | last post by:
Will the following class work well? If it can not work correctly in some situation, could you help me to fix it? Thank you. //the class will work like the reference in java //when you create a...
5
by: Ralph2 | last post by:
Hello The person responsible for installing software at work believes in installing the bare minimum., which does not include the option to split a data base into a front and back end. So, rather...
7
by: Peter Steele | last post by:
I have code to add a domain user to a local group but I'm not sure if it will work with NT domains or whether it will only work with Active Directory based systems. Here's the code: public void...
0
by: palomine1234 | last post by:
PAYPAL MAGIC!!! TURN $5 INTO $15,000 IN ONLY 30 DAYS...HERES HOW! This is a Money Scheme and Not, I repeat... This is Not a Scam!!!
48
by: meyer | last post by:
Hi everyone, which compiler will Python 2.5 on Windows (Intel) be built with? I notice that Python 2.4 apparently has been built with the VS2003 toolkit compiler, and I read a post from Scott...
1
by: Ryan Liu | last post by:
So for a UtpClient to JoinMulticastGroup, there must be a router in the network and with multicast enabled? That is, for a small LAN with a few computers connected by a hub or siwtch, it won't...
1
by: Brendan Miller | last post by:
I need a portable way to tell what subprocess.Popen will call. For instance on unix systems, Popen will work for files flagged with the executable bit, whereas on windows Popen will work on files...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.