Help, I can't get the Current date into database!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Help, I can't get the Current date into database!!

Post by cap2cap10 »

Hello again, php technorati. Ok I can't seem to get my code to post the current date into mysql table.
here is the code:

Code: Select all

mysql_query("INSERT INTO agent_login (agentID, user_name, pass_word, company, F_name, M_name, L_name, email, my_indust, address,
suite, city, state, zipcode, country, C_phone_1, C_phone_2, C_phone_3, M_phone_1, M_phone_2, M_phone_3, Fax_1, Fax_2, Fax_3, Extension)
VALUES ('', '$user_name', '$pass_word', '$company', '$F_name', '$M_name', '$L_name', '$email', '$my_indust', '$address',
'$suite', '$city', '$state', '$zipcode', '$country', '$C_phone_1', '$C_phone_2', '$C_phone_3', '$M_phone_1', '$M_phone_2',
'$M_phone_3', '$Fax_1', '$Fax_2', '$Fax_3', '$Extension' ) ") or die(mysql_error());
 
 
 
$query = "UPDATE agent_login SET mem_since = CURDATE() WHERE agentID = '$agentID'";
mysql_query($query) or die(mysql_error());
:banghead:

Please show me the error of my ways.
Thanks in advance,


Batoe
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Help, I can't get the Current date into database!!

Post by social_experiment »

Code: Select all

<?php
 mysql_query("INSERT INTO agent_login (agentID, user_name, pass_word, company, F_name, M_name, L_name, email, my_indust, address,
 suite, city, state, zipcode, country, C_phone_1, C_phone_2, C_phone_3, M_phone_1, M_phone_2, M_phone_3, Fax_1, Fax_2, Fax_3, Extension)
 VALUES ('', '$user_name', '$pass_word', '$company', '$F_name', '$M_name', '$L_name', '$email', '$my_indust', '$address',
 '$suite', '$city', '$state', '$zipcode', '$country', '$C_phone_1', '$C_phone_2', '$C_phone_3', '$M_phone_1', '$M_phone_2',
 '$M_phone_3', '$Fax_1', '$Fax_2', '$Fax_3', '$Extension' ) ") or die(mysql_error());
?>
In this query you don't have a mem_since field? Im assuming this table (above) is where you want to update the date.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Help, I can't get the Current date into database!!

Post by AbraCadaver »

Yep, and the reason the second one isn't working is probably because $agentID isn't set:

Code: Select all

mysql_query("INSERT INTO agent_login (agentID, user_name, pass_word, company, F_name, M_name, L_name, email, my_indust, address,
suite, city, state, zipcode, country, C_phone_1, C_phone_2, C_phone_3, M_phone_1, M_phone_2, M_phone_3, Fax_1, Fax_2, Fax_3, Extension)
VALUES ('', '$user_name', '$pass_word', '$company', '$F_name', '$M_name', '$L_name', '$email', '$my_indust', '$address',
'$suite', '$city', '$state', '$zipcode', '$country', '$C_phone_1', '$C_phone_2', '$C_phone_3', '$M_phone_1', '$M_phone_2',
'$M_phone_3', '$Fax_1', '$Fax_2', '$Fax_3', '$Extension' ) ") or die(mysql_error());
 
 
// change $connection to whatever your link_indentifier is 
$query = "UPDATE agent_login SET mem_since = CURDATE() WHERE agentID = " . mysql_insert_id($connection);
mysql_query($query) or die(mysql_error());
But better is to do it in the original insert as social_experiment states.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply