Will this work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Curwe Support

    #1

    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(strtolo wer($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(strto lower($firstnam e));',
    'ucwords(strtol ower($variable1 ));', '$zipcode', '$email',
    '$month--$day-$year', '$entrydate', '$termsagree')" );

    etc etc.

    or do i have to do

    $fixed_variable 1=ucwords(strto lower($variable 1));
    $fixed_variable 2=ucwords(strto lower($variable 2));

    mysql_query ("INSERT INTO 10m (firstname, lastname, zipcode, email, 10mdate,
    entrydate, termsagree)
    VALUES ('$fixed_firstn ame', '$fixed_lastnam e', '$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


  • Jon Kraft

    #2
    Re: Will this work

    Curwe Support <support-nntp@curwe.com> wrote:
    [color=blue]
    > 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(strto lower($firstnam e));',
    > 'ucwords(strtol ower($variable1 ));', '$zipcode', '$email',
    > '$month--$day-$year', '$entrydate', '$termsagree')" );[/color]

    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(str tolower($firstn ame))."', " .
    "'".ucwords(str tolower($variab le1))."', " .
    "'".$zipcode."' , " .
    "'".$email. "', " .
    "'".$month. "-".$day."-".$year."', " .
    "'".$entrydate. "', " .
    "'".$termsagree ."')";

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

    HTH;
    JOn

    Comment

    Working...