Nov 21, 2009

Can't Make This Query Working.

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Can't Make This Query Working.

Feelay
Hi again.

I am trying to make a new Register script. But now, there is only one thing that is not working.. I can't make the following query work.

CODE
mysql_query("INSERT INTO members(username, password, email, register_date) VALUES ('$user','$pass','$email', '$reg_date')") or die("Failed to register.<br> Error:".mysql_error());



this is the current date variable, that is causing the error. (if I remove it from the query, it works just fine)
CODE
$reg_date=date("Y/m/d");


this is the error I am getting:

QUOTE
Error:Data truncated for column 'register_date' at row 1



in the database I gave it the data type int, because the date is only made out of numbers.

Thanks for your help //Feelay

 

 

 


Comment/Reply (w/o sign-up)

TavoxPeru
Your query don't work because your variable stores a string like "2008/06/13", the "/" character cause this error to happen.

To fix it simply change your variable's date format to:

CODE
<?php
$reg_date=date("Ymd");
?>

But this can lead to get problems with the register_date field, i'm not sure about this.

A better solution is to change the data type of the register_date field to date and change the sql query to:

CODE
<?php
mysql_query("INSERT INTO members(username, password, email, register_date) VALUES ('$user','$pass','$email', NOW())") or die("Failed to register.<br> Error:".mysql_error());
?>

Best regards,

Comment/Reply (w/o sign-up)

Feelay
Thanks ^.^

lol tongue.gif I forgot that "/" was in the variable tongue.gif
Anyways.. it is working now =)

Thank you //Feelay

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : make, query, working,

  1. Making A Link = Mysql_query
    (8)
  2. Installed A PR Checker Script - But Not Working Correctly
    (6)
    I'm new to PHP and still have much to learn. I came across a free script to check google PR.
    You place a file called pagerank.php and then have an includes. So I did this: CODE ?>
    Then I have my HTML (the page header and so forth), and added a form where they can input their URL.
    The form action is CODE " method="post" name="checkpr" id="checkpr"> First of all ... I
    seem to be missing something completely basic. My page isn't displaying at ALL as I expected.
    No graphic header and no form. It's actually showing all my HTML code in....
  3. Php Wget
    Its not working!!! (3)
    A while ago I posted a thread asking if anyone knew anything about wget, and I was given the code
    below: CODE $foo = system('wget http://www.whatever.com/file.html ~',$output); ?>
    Which has been working fine, since the panda server failure a while ago. Since then, whenever I try
    to use it , it comes up with QUOTE $foo = system('wget
    http://www.gallifreyone.com/forum/customav...avatar646_8.gif ~',$output); ?> Has this been
    disabled by the administrators, or is there a way I can sort it out?....
  4. Mail() Not Working
    (4)
    I'm trying to use the mail() function in a script. But it doesnt work. It keeps returning false.
    It's a premade script The code is: CODE function SendPassword($userName) { global
    $db,$db_tables;//config.php     // set password for username to a random value     // return the new
    password or false on failure     $new_password = mt_rand();     $qry = "UPDATE $db_tables SET
    password=password('$new_password') WHERE user_name='$userName'";
        $db->db_query($qry);     // send notification email     $from = "From: $from_email\r\n";
        $msg = "....
  5. A Php Gallery Commenting Script Question...
    i am working on a php script... (2)
    Hi all, i am working on a Gallery commenting script for myself and i got stuck at a part of it. I
    would like each new comment added to an image to be a number as the text file name like 1, 2, 3.
    everytime they add a comment the next file name is incremented (+1) and so on for example; if there
    was a text file names '1' then the next would be named '2'. I know how to create
    the file and the rest of it, but i would like to know how to do this. I should probably store the
    last file name somehow and then add 1 to it to create the next file but i do not know....
  6. Php Problem - Unique Counter
    my script isn't working correctly (4)
    alright here's what I want to do: I made a counter to count unique visitors without a mysql. But
    the problem is that the '.dat' file I'm writing on (unique.dat) tends to become too big
    when I have too many visitors. Thus, I tried to add an if/then statement. Kay, now here's the
    problem: even though this code successfully runs, it's not a hundred-percent accurate. Sometimes
    it rewrites a user's IP even though it is already on the '.dat' file. Even though it
    doesn't actually affect the $hits, I'd still like to know what I did w....
  7. Php Problem Error Message
    I'm working from a book (9)
    I get this error message when I try to view a small webpage. QUOTE Parse error: parse error,
    unexpected T_STRING, expecting ',' or ';' in
    /home/nilsc/public_html/bobs/processorder.php on line 27 Line 27 is in this php part: CODE
        echo ' Order processed. ';     echo $tireqty. ' tires ';     echo $oilqty. '
    bottles of oil ';     echo $sparkqty. ' spark plugs ';          $totalqty = 0;
        $totalqty = $tireqty + $oilqty + $spakqty;     echo 'Items ordered: ' .$totalqty.' ;
             $totalamount = 0.....

    1. Looking for make, query, working,

See Also,

*SIMILAR VIDEOS*
Searching Video's for make, query, working,
advertisement



Can't Make This Query Working.

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com