jrphplover Posted July 6, 2013 Share Posted July 6, 2013 please see what im doing wrong and how do i insert date into datetime field in database? $qry = "INSERT INTO leads ('agentID, customerName, customerAddress, homePhone, altPhone, loanAmount, monthlyPayment, paymentPeriod, ssn, dl, sid, monthlyIncome, lastPayday, nextPayday, dob, transferNumber, applicationNumber, comments, date_time) VALUES ('".$agentID."', '".$customerName."', '".$customerAddress."', '".$homePhone."', '".$altPhone."', '".$loanAmount."', '".$monthlyPayment."', '".$repaymentPeriod."', '".$ssn."', '".$dl."', '".$sid."', '".$monthlyIncome."', '".$lastPayday."', '".$nextPayday."', '".$dob."', '".$transferNumber."', '".$applicationNumber."', '".$comments."', 'CURRENT_TIMESTAMP')"; $result = @mysql_query($qry); print_r($qry); //Check whether the query was successful or not if($result) { header("location: record-success.php"); exit(); }else { die("Query failed"); Quote Link to comment Share on other sites More sharing options...
boompa Posted July 6, 2013 Share Posted July 6, 2013 HINT: There's another function in the PHP mysql (deprecated, BTW) library. It's called mysql_error(), and it prints out the last error mysql encountered. Might come in handy here, as well as not suppressing errors/warnings with the @ sign. Quote Link to comment Share on other sites More sharing options...
jrphplover Posted July 6, 2013 Author Share Posted July 6, 2013 i get5 that but when i print i see all data in values but it just do not insert Quote Link to comment Share on other sites More sharing options...
boompa Posted July 6, 2013 Share Posted July 6, 2013 INSERT INTO leads ('agentID What's that ' doing in there? Quote Link to comment Share on other sites More sharing options...
thara Posted July 6, 2013 Share Posted July 6, 2013 If you want to insert current date and time to database, you can use mysql NOW() fuction with your insert query. Try this. $qry = "INSERT INTO leads ( agentID, customerName, customerAddress, homePhone, altPhone, loanAmount, monthlyPayment, paymentPeriod, ssn, dl, sid, monthlyIncome, lastPayday, nextPayday, dob, transferNumber, applicationNumber, comments, date_time ) VALUES ('$agentID', '$customerName', '$customerAddress', '$homePhone', '$altPhone', '$loanAmount', '$monthlyPayment', '$repaymentPeriod', '$ssn', '$dl', '$sid', '$monthlyIncome', '$lastPayday', '$nextPayday', '$dob', '$transferNumber', '$applicationNumber', '$comments', now())"; Side note: Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated, read this . Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. Quote Link to comment Share on other sites More sharing options...
jrphplover Posted July 7, 2013 Author Share Posted July 7, 2013 still its not inserting eh what is wrong here? here is the entire coding <?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $agent = clean($_SESSION['SESS_LOGIN_NAME']); $customerName = clean($_POST['customerName']); $customerAddress = clean($_POST['customerAddress']); $homePhone = clean($_POST['homePhone']); $altPhone = clean($_POST['altPhone']); $loanAmount = clean($_POST['loanAmount']); $monthlyPayment = clean($_POST['monthlyPayment']); $repaymentPeriod = clean($_POST['repaymentPeriod']); $ssn = clean($_POST['ssn']); $dl = clean($_POST['dl']); $sid = clean($_POST['sid']); $monthlyIncome = clean($_POST['monthlyIncome']); $lastPayday = clean($_POST['lastPayday']); $nextPayday = clean($_POST['nextPayday']); $dob = clean($_POST['dob']); $transferNumber = clean($_POST['transferNumber']); $applicationNumber = clean($_POST['applicationNumber']); $comments = clean($_POST['comments']); //Input Validations if($customerName == '') { $errmsg_arr[] = 'Customer name is missing'; $errflag = true; } if($customerAddress == '') { $errmsg_arr[] = 'Customer address is missing'; $errflag = true; } if($loanAmount == '') { $errmsg_arr[] = 'Loan amount is missing'; $errflag = true; } //Check for duplicate login ID if($homePhone != '') { $qry = "SELECT * FROM leads WHERE homePhone='$homePhone'"; $result = mysql_query($qry); if($result) { if(mysql_num_rows($result) > 0) { $errmsg_arr[] = 'Customer with this number already exist'; $errflag = true; } @mysql_free_result($result); } else { die("Query failed"); } } //If there are input validations, redirect back to the registration form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: add-record.php"); exit(); } //Create INSERT query $qry = "INSERT INTO leads ( agent, customerName, customerAddress, homePhone, altPhone, loanAmount, monthlyPayment, paymentPeriod, ssn, dl, sid, monthlyIncome, lastPayday, nextPayday, dob, transferNumber, applicationNumber, comments, date_time ) VALUES ('$agent', '$customerName', '$customerAddress', '$homePhone', '$altPhone', '$loanAmount', '$monthlyPayment', '$repaymentPeriod', '$ssn', '$dl', '$sid', '$monthlyIncome', '$lastPayday', '$nextPayday', '$dob', '$transferNumber', '$applicationNumber', '$comments', now())"; $result = @mysql_query($qry); print_r($qry); //Check whether the query was successful or not if($result) { header("location: record-success.php"); exit(); }else { die("Query failed"); } ?> Quote Link to comment Share on other sites More sharing options...
thara Posted July 7, 2013 Share Posted July 7, 2013 if it is not inserting what is the error message ? Quote Link to comment Share on other sites More sharing options...
jcbones Posted July 7, 2013 Share Posted July 7, 2013 Change this line: $result = @mysql_query($qry); To: $result = mysql_query($qry) or trigger_error(mysql_error()); Make sure your error reporting is on, if it isn't then use: $result = mysql_query($qry) or exit(mysql_error()); Quote Link to comment Share on other sites More sharing options...
jrphplover Posted July 7, 2013 Author Share Posted July 7, 2013 thanks all soo much for your precious time well i fixed it :-) its was a simple spelling mistake for which it was not inserting. paymentPeriod should have been repaymentPeriod :-D 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.