homepage Welcome to WebmasterWorld Guest from 54.226.213.228
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Inserting into datetime column with PHP
Works in PHPMyAdmin.. not through PHP page
wruk999




msg:1281141
 11:57 am on Mar 15, 2003 (gmt 0)

Hi all,

I have a column in a 'users' table with the following properties.

Type: datetime
Null: No
Deafult: 0000-00-00 00:00:00

When I want to add a record into the table through PHPMyAdmin, I click 'insert' and the current date & time appear in the text field, and it enters correctly, and the user works fine.

However, when I want to add a user via a PHP-web form (which is how it *needs* to be), it just enters in 0000-00-00 00:00:00 with no data, which means the user can't login :(

I have tried all sorts of different insert strings...none seem to work.
I have set it so that no value is entered, I have also tried having the current date/time passed to the php-processor page, and tried entering that as a value - still not working.

Any ideas? of how I can get this to work? Any help will be greatly appreciated.

Regards,
William.

 

Jocelyn




msg:1281142
 12:25 pm on Mar 15, 2003 (gmt 0)

Hi!
Send us the relevant part of the PHP code you're using, including your mySQL query.
So we can help you more easily.

Jocelyn

Allen




msg:1281143
 1:31 pm on Mar 15, 2003 (gmt 0)

You can either use MySQL's NOW() function, or PHP's date() function.
I think the syntax for using date is: date ("Y-m-d H:m:s");

Check the manuals.

Allen

wruk999




msg:1281144
 2:28 pm on Mar 15, 2003 (gmt 0)

Hi,

Thanks for the replies..I had tried the NOW() & Date feature..neither work!
Below is the part of my code which handles the adding:

} elseif ($action == adddealer) {
$newuser = addslashes($HTTP_GET_VARS['username']);
$newname = addslashes($HTTP_GET_VARS['name']);
$newemail = addslashes($HTTP_GET_VARS['email']);
$newpass = addslashes($HTTP_GET_VARS['password']);
$level = addslashes($HTTP_GET_VARS['level']);

$sql = "INSERT INTO users (id,username,password,email,lost_key,lost_date,level,dealer) ";
$sql = $sql . " VALUES ('','$newuser',MD5($newpass),'$newemail','0','NOW()','$level','$newname') ";
$result = mysql_query($sql);
print "Your request to add a user was successful";

Your thoughts would be greatly appreciated.

Regards,
William

Jocelyn




msg:1281145
 2:41 pm on Mar 15, 2003 (gmt 0)

Try that :
$sql = "INSERT INTO users (username,password,email,lost_key,lost_date,level,dealer) ";
$sql = $sql . " VALUES ('$newuser',MD5($newpass),'$newemail','0',NOW(),'$level','$newname') ";

The id field is probably set as autoincrement, so you don't need it in your query.
Notice that there must not be any quotes around NOW() in your query. Check with phpMyAdmin.
Also, to check for mysql errors in the PHP code, you can do so :
mysql_query($query) or die('Mysql error:' . mysql_error());

Sorry for the layout, I'm not familiar with BB code yet.

Jocelyn

wruk999




msg:1281146
 3:34 pm on Mar 15, 2003 (gmt 0)

Hi,

Thanks for the info - still no joy :(.
Here is the error that I receive:

ERROR: Unknown column 'test' in 'field list' INSERT INTO arctic_dealers (username, password, email, lost_key, lost_date, level, dealer) VALUES ('test',MD5(test),'test@email.com','0',NOW(),'1','Test')

I have realised that it is saying it can't find the column, called 'whatever I enter into the password box'.

Any ideas, how to stop this?

Regards,
William

wruk999




msg:1281147
 3:40 pm on Mar 15, 2003 (gmt 0)

Sorted!

I noticed that I was inserting: MD5($newpass), and I just changed it to MD5('$newpass') and it is working fine.

Thanks to all.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved