0

Hello,

I am using a java script to select a date from date picker.After selecting date from calender,it shown in the text box but it is not saved in the database.

In database takes this value 0000-00-00 for every date.

Please suggest me any idea for above.
Thanks

5
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by perfectweb
0

Hi,This is code

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="ihmjob"; // Database name
$tbl_name="ihm"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");

if(isset($_POST['submit']))//for email
{
	$subject=$_POST['subject'];
	$desc=$_POST['desc'];
    $category=$_POST["category"];
	$experience=$_POST['experience'];
	$location=$_POST['location'];
	$company=$_POST['company'];
	$dop=$_POST['dop'];
	
	
    if (empty($_POST['subject']) || empty($_POST['desc']) || empty($_POST['category']) || empty($_POST['experience'] ))
		  {
 			 	echo "<script type=\"text/javascript\">";
				echo "alert('Please Enter Mandatory Fields !!');";
				echo "</script>";	
				echo "<script type=\"text/javascript\">";
		  }	

	else
	{ 
		
        $result= mysql_query("INSERT INTO `ihm` (`subject`, `desc`, `category`, `experience`, `location` ,`company` ,`dop`) VALUES ('$subject', '$desc', '$category', '$experience', '$location' ,'$company' ,'CURDATE()');");
      
	}   




}

?>
0

I also used that code when we manually select date from datepicker.

$result= mysql_query("INSERT INTO `ihm` (`subject`, `desc`, `category`, `experience`, `location` ,`company` ,`dop`) VALUES ('$subject', '$desc', '$category', '$experience', '$location' ,'$company' ,'$dop');");
0

Hi,This is code

if(isset($_POST['submit']))//for email
{
	$subject=$_POST['subject'];
	$desc=$_POST['desc'];
    $category=$_POST["category"];
	$experience=$_POST['experience'];
	$location=$_POST['location'];
	$company=$_POST['company'];
	$dop=$_POST['dop'];

1. Go read this:http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php
2. Implement this: http://php.net/manual/en/function.mysql-real-escape-string.php
3. Never trust submitted values

if(isset($_POST['submit']))//for email
        $result= mysql_query("INSERT INTO `ihm` (`subject`, `desc`, `category`, `experience`, `location` ,`company` ,`dop`) VALUES ('$subject', '$desc', '$category', '$experience', '$location' ,'$company' ,'CURDATE()');");

Why have you got );"); at the end?
Correct structure for your query is:

mysql_query("INSERT INTO `...` (`...`, `...`, `...`) VALUES('...', '...', '...')");
0

Concerning your date issue, remove the single quotes around CURDATE(). This is a function, yet you insert it as a string.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.