SapAuthor Posted June 11, 2008 Share Posted June 11, 2008 I'm at a complete loss. I'm trying to make a simple prayer request program. There are 3 times inside the MySQL database. The Creation/modification time, the reminder time (current time + X amount of days), and the experation time (current time + X amount of days + 30 more days). Here's what I have: $mysqli = mysqli_connect('localhost', '*******', '*********', 'prayer_request'); $name = $_POST['request_name']; $email = $_POST['email_address']; $request = $_POST['the_request']; $password = $_POST['the_password']; $dayreminder = $_POST['reminder_days']; $experation = $dayreminder + 30; $sql = "INSERT INTO prayers (answered, date_time, date_remind, date_expire, name, email, request, password) VALUES ('n', now(), (CURRENT_DATE() + INTERVAL $dayreminder DAY), (DATE_ADD(NOW(), INTERVAL $experation DAY)), '$name', '$email', '$request', '$password')"; $res = mysqli_query($mysqli, $sql); if ($res === TRUE) {echo "The data was entered successfuly!";} else {printf("Could not insert record: %s\n", mysqli_error($mysqli));} Now i've tried a lot of things. from just "Now() + INTERVAL $dayreminder DAY" to "(NOW() + INTERVAL $dayreminder DAY" to DATE_ADD(CURDATE(), INTERVAL $dayreminder DAY)". NOTHING works. I either get the same date as now(), or i get 00:00:00. What am I doing wrong? How do i get it to output it correctly? --------- ----------- Next question. I could try to do this outside of MySQL and get things ready in PHP. I know i can just use Timestamp and add the certain amount of seconds, reput it in the right format and then plug in that variable for the query, but is there an easier way to do it? What i mean is, can i assign a simple Select Query that outputs one thing like the date to a php variable? Instead of: $thequery = "SELECT CURRENT_DATE() AS thevalue"; $res = mysqli_query($mysqli, $thequery); $newArray = mysqli_fetch_array($res, MYSQLI_ASSOC); echo $newArray['thevalue']; if there is a shorter way i would like to learn it because i'll be doing a lot of coding coming up...i'm still learning so sorry for the noobism, i couldn't find ANYTHING on google about this >.> Quote Link to comment Share on other sites More sharing options...
fenway Posted June 11, 2008 Share Posted June 11, 2008 Have you tried "Now() + INTERVAL 1 DAY"? Quote Link to comment Share on other sites More sharing options...
SapAuthor Posted June 11, 2008 Author Share Posted June 11, 2008 Oh...my...sweet...Jesus.... It just occured to me that I set "Time" instead of "date" as the column type, in my dilusionous sleep deprived 3am coding state of mind. This is most likely why it showed 00:00:00 when i added dates... *tested*...yeah...that was the problem...ugh... Sorry the people that viewed this and posted. ---------------- Also still, is there any shorter way to retrieve simple values from MySQL, such as the date, or the length of a string? or do you have to take the result of the mysqli_query() and put it through the mysqli_fetch_array? Quote Link to comment Share on other sites More sharing options...
fenway Posted June 12, 2008 Share Posted June 12, 2008 Also still, is there any shorter way to retrieve simple values from MySQL, such as the date, or the length of a string? How do you mean? Oh, maybe just a single column output? You can use mysql_result( $result, 0, 0 ) to get back, say, a COUNT(). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.