Page 1 of 1

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

Posted: Wed Jan 27, 2010 3:25 pm
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

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

Posted: Wed Jan 27, 2010 4:21 pm
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.

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

Posted: Wed Jan 27, 2010 4:31 pm
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.