Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old February 11th, 2004, 04:09 AM
codebear codebear is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Seattle
Posts: 102 codebear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Need Help With DATE Function

I've created a MySQL table that I can preview on a webpage with PHP. It seems to be generally OK, but there are a few problems I need to fix. One regards the date.

The dates that are already logged in - like 1888-24-10 - work just fine. But if I try to add a row with an input form I created (with the help of a Codewalkers tutorial), the date field records 0000-00-00, regardless of what I type in. I can type in 1969-24-15 or MyName, and I get the same result.

I can think of two possible problems. Until I get a better handle on this stuff, I have to use two programs to create my tables - phpMyAdmin and EMS MySQL Manager. More precisely, I create the table with EMS, then modify it in phpMyAdmin.

I won't go into all the details. I described it more thoroughly at
http://geowebworks.geobop.org/test/phpmyadmin/index.php
(Scroll down to #3).

But I thought that, whatever the problem is, I could probably fix it with phpMyAdmin. Any tips?

Thanks.

Reply With Quote
  #2  
Old February 11th, 2004, 04:27 AM
nawlej nawlej is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Dallas, Tx. USA
Posts: 2,008 nawlej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 7 m 51 sec
Reputation Power: 4
RE: Need Help With DATE Function

what happens if you set it to not null?

Reply With Quote
  #3  
Old February 11th, 2004, 06:55 AM
codebear codebear is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Seattle
Posts: 102 codebear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: RE: Need Help With DATE Function


Quote:
what happens if you set it to not null?


Aha - you nailed it! I just entered my first valid date.

It looks like, there may have been two or three problems, as I suspected, because the input form still isn't working as it should.

I still haven't really figured out the parameters, but it seems to choke on too many characters, and it gets "stuck" if one row gets screwed up.

For example, I might be able to type some words and numbers into the fields and create a new row, but I can't create a second row unless I do something stupid - like type xx into every single cell. Then it works, with the date defaulting to 0000-00-00.

I can sometimes create another row by typing a name into the first cell. The new row features the name and default date (0000-00-00), but every other cell is blank, of course. If I try typing words into the first TWO cells of another row, nothing happens.

But I'm getting closer. Thanks for your help.

Reply With Quote
  #4  
Old February 11th, 2004, 07:04 AM
DoctorK DoctorK is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: USA
Posts: 43 DoctorK User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Need Help With DATE Function

i had the same problem today...

if you can post your code we could help you more...

php Code:
Original - php Code
  1. $input = "INSERT INTO $tablename (username, website, timestamp, message) VALUES ('$user', '$site', NOW(), '$text')"; // set input query
  2.  


that is my basic input... make sure your time value is: NOW() and not: 'NOW()'

not sure if thats right, but thats what i did to fix my error.

Reply With Quote
  #5  
Old February 11th, 2004, 07:09 AM
nawlej nawlej is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Dallas, Tx. USA
Posts: 2,008 nawlej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 7 m 51 sec
Reputation Power: 4
RE: Need Help With DATE Function

What he is trying to do is not a timestamp. He is inserting a birthday in the form of a mysql date, manually typing it in.

Edit: Try echoing the output of the query string without having it query the database, so we can check the query syntax.

Reply With Quote
  #6  
Old February 11th, 2004, 07:19 AM
codebear codebear is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Seattle
Posts: 102 codebear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: RE: Need Help With DATE Function

"Edit: Try echoing the output of the query string without having it query the database, so we can check the query syntax."

Hmmmm... This is still Greek to me; I don't know how to identify a "query string," echo its output or detaching it from the database.

I've so far managed to create two input forms, one of which just yields a URL, like this:
http://localhost/geowebworks/php/input.php?Name=South+Dakota&Capital=Pierre&Birthday=1888-13-12&Rank=37&Origin=Dakota+Territory&Code=SD&Country=U.S.&submit=+Enter+information

But it sounds like you're asking me to do something with the other input form, presumably by changing the code:

php Code:
Original - php Code
  1.  
  2. <html>
  3. <?php
  4. if( $_POST['submit'])
  5. {
  6.     $db = mysql_connect("localhost", "USERNAME","PASSWORD");
  7.     mysql_select_db("test",$db);
  8.  
  9.     /* you really should do some input validation here */
  10.  
  11. $sql = "INSERT INTO states (Name, Capital, Birthday, Rank, Origin, Code, Country)
  12.               VALUES ('".$_POST['Name']."', '".$_POST['Capital']."', '".$_POST['Birthday']."', '".$_POST['Rank']."', '".$_POST['Origin']."', '".$_POST['Code']."', '".$_POST['Country']."')";
  13.     $result = mysql_query($sql);
  14.     echo "Thank you! Information entered.n";
  15. }
  16. else
  17. {
  18. ?>
  19. <form method="post" action="input.php">
  20. Name:<input type="Text" name="Name"><br>
  21. Capital:<input type="Text" name="Capital"><br>
  22. Birthday:<input type="Text" name="Birthday"><br>
  23. Rank:<input type="Text" name="Rank"><br>
  24. Origin:<input type="Text" name="Origin"><br>
  25. Postal Code:<input type="Text" name="Code"><br>
  26. Country:<input type="Text" name="Country"><br>
  27. <input type="Submit"name="submit" value=" Enter information"></form>
  28. <?
  29. }
  30. ?>
  31. </html>

Reply With Quote
  #7  
Old February 11th, 2004, 07:23 AM
nawlej nawlej is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Dallas, Tx. USA
Posts: 2,008 nawlej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 7 m 51 sec
Reputation Power: 4
RE: Need Help With DATE Function

When we ask you to echo your query string this is what we mean:

You have built an SQL statement, in this case $sql

It is this:

$sql = "INSERT INTO states (Name, Capital, Birthday, Rank, Origin, Code, Country)
VALUES ('".$_POST['Name']."', '".$_POST['Capital']."', '".$_POST['Birthday']."', '".$_POST['Rank']."', '".$_POST['Origin']."', '".$_POST['Code']."', '".$_POST['Country']."')";



When we say to echo the statement, we want you to place:
echo $sql; after the variable to put it under test. Modify your code like this temporarily to make this happen:
php Code:
Original - php Code
  1.  
  2. $sql = "INSERT INTO states (Name, Capital, Birthday, Rank, Origin, Code, Country)
  3.               VALUES ('".$_POST['Name']."', '".$_POST['Capital']."', '".$_POST['Birthday']."', '".$_POST['Rank']."', '".$_POST['Origin']."', '".$_POST['Code']."', '".$_POST['Country']."')";
  4. echo $sql;
  5. /*    $result = mysql_query($sql);
  6.     echo "Thank you! Information entered.n";*/


This is part of the debugging process so we can see what the query looks like that is going into the database. Please post what the echo returns.

Reply With Quote
  #8  
Old February 11th, 2004, 07:32 AM
DoctorK DoctorK is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: USA
Posts: 43 DoctorK User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Need Help With DATE Function

oh ok... i was confused.. but that helps me out too for future databases


Reply With Quote
  #9  
Old February 11th, 2004, 07:50 AM
codebear codebear is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Seattle
Posts: 102 codebear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Need Help With DATE Function

I probably butchered it, but this is what I ended up with:

php Code:
Original - php Code
  1.  
  2. <html>
  3. <?php
  4. if( $_POST['submit'])
  5. {
  6.     $db = mysql_connect("localhost", "USERNAME","PASSWORD");
  7.     mysql_select_db("test",$db);
  8.  
  9.     /* you really should do some input validation here */
  10. $sql = "INSERT INTO states (Name, Capital, Birthday, Rank, Origin, Code, Country)
  11.               VALUES ('".$_POST['Name']."', '".$_POST['Capital']."', '".$_POST['Birthday']."', '".$_POST['Rank']."', '".$_POST['Origin']."', '".$_POST['Code']."', '".$_POST['Country']."')";
  12. echo $sql;
  13. /*    $result = mysql_query($sql);
  14.     echo "Thank you! Information entered.n";*/
  15. ?>
  16. </html>


When I preview it, I get the error message "
Parse error: parse error, unexpected $end in C:sitesgeowebworksphpinput.php on line 15"

Reply With Quote
  #10  
Old February 11th, 2004, 07:55 AM
nawlej nawlej is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Dallas, Tx. USA
Posts: 2,008 nawlej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 7 m 51 sec
Reputation Power: 4
RE: Need Help With DATE Function

just make those changes I showed you. Dont take anything off of the current script. This is exaclty what you should have:

php Code:
Original - php Code
  1.  
  2. <html>
  3. <?php
  4. if( $_POST['submit'])
  5. {
  6.     $db = mysql_connect("localhost", "USERNAME","PASSWORD");
  7.     mysql_select_db("test",$db);
  8.  
  9.     /* you really should do some input validation here */
  10.  
  11. $sql = "INSERT INTO states (Name, Capital, Birthday, Rank, Origin, Code, Country)
  12.               VALUES ('".$_POST['Name']."', '".$_POST['Capital']."', '".$_POST['Birthday']."', '".$_POST['Rank']."', '".$_POST['Origin']."', '".$_POST['Code']."', '".$_POST['Country']."')";
  13.  
  14. echo $sql;
  15. /*    $result = mysql_query($sql);
  16.     echo "Thank you! Information entered.n";*/
  17. }
  18. else
  19. {
  20. ?>
  21. <form method="post" action="input.php">
  22. Name:<input type="Text" name="Name"><br>
  23. Capital:<input type="Text" name="Capital"><br>
  24. Birthday:<input type="Text" name="Birthday"><br>
  25. Rank:<input type="Text" name="Rank"><br>