Jump to content

Form Help


blackdogupya

Recommended Posts

Hey Guys and Girls!

 

I'm a bit of a noob when it comes to PHP and MySQL, so I'm hoping you can help me!

 

I'm trying to create a form and parse the data to an MySQL database.

 

The form code I have is as follows:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

        <!-- jQuery -->
	<script type="text/javascript" src="js/jquery.js"></script>
        
        <!-- required plugins -->
	<script type="text/javascript" src="js/date.js"></script>
	<!--[if IE]><script type="text/javascript" src="scripts/jquery.bgiframe.min.js"></script><![endif]-->
        
        <!-- jquery.datePicker.js -->
	<script type="text/javascript" src="js/date_picker.js"></script>
        
<!-- datePicker required styles -->
<link rel="stylesheet" type="text/css" media="screen" href="css/default.css">

<script type="text/javascript" charset="utf-8">
            $(function()
            {
			$('.date-pick').datePicker().dpSetSelected(new Date().asString());
            });
	</script>



<title>POPLAF Database - Add Animal</title>
</head>

<body>


<form method="post" action="process.php"> 
Status:<br> <BR />
<input type="radio" name="status" value="lost" /> Lost<br /><BR />
<input type="radio" name="status" value="found" /> Found
<BR /> <BR />
Date: <br> 
<input name="date" id="date" class="date-pick" />
<br><br> 
<input type="submit" name="Submit" value="Submit"> 
</form>




</body>
</html>

 

This part is fine.  Here's the process.php code:

 

<?
// Database Connection.  Change if required.
$dbms = 'mysqli';
$hostname = 'localhost';
$db_user = '*******';
$database = '*******';
$db_password = '*******';
$load_extensions = '';

$db = mysql_connect($hostname, $db_user, $db_password); 
mysql_select_db($database,$db); 

if ($_SERVER['REQUEST_METHOD'] == "POST") { 

// the following 4 lines are needed if your server has register_globals set to Off
$status = $_POST['status'];
$date = $_POST['date'];

$sql = "INSERT INTO animal_info (status, date)
            VALUES ('$status','$date')";

//declare in the order variable
$result = mysql_query($sql);  //order executes
if($result){
    echo("<br>Input data is succeed");
} else{
echo "ERROR: ".mysql_error();
}
?>
<?
}
?>

 

This part also works okay!

 

My trouble is, with getting the date correct!  Whenever I submit the form, the database shows the date as 0000-00-00 and not the date entered.  I'm using jQuery for the calendar and date.

 

Any help would be appreciated!

 

Cheers,

 

Dave

Link to comment
https://forums.phpfreaks.com/topic/258437-form-help/
Share on other sites

  Quote

I'm no expert in jquery but it looks like you are not referencing the date id in your form.

<script type="text/javascript" charset="utf-8">
            $(function()
            {
			$('#date').datePicker().dpSetSelected(new Date().asString());
            });
	</script>

 

He is referencing the input field by it's class, which is fine.

What format is the date being passed in?

To be inserted into a DATE field, it needs to be YYYY-MM-DD

 

Link to comment
https://forums.phpfreaks.com/topic/258437-form-help/#findComment-1324831
Share on other sites

  Quote

  Quote

I'm no expert in jquery but it looks like you are not referencing the date id in your form.

<script type="text/javascript" charset="utf-8">
            $(function()
            {
			$('#date').datePicker().dpSetSelected(new Date().asString());
            });
	</script>

 

He is referencing the input field by it's class, which is fine.

What format is the date being passed in?

To be inserted into a DATE field, it needs to be YYYY-MM-DD

 

I changed the code to this, as suggested by the jQuery peeps:

 

<script type="text/javascript" charset="utf-8">
            $(function()
            {
			$('.date-pick').datePicker( "option", "dateFormat", "yyyy-mm-dd").dpSetSelected(new Date().asString());
            });
	</script>

 

But I might be barking up the wrong tree.

 

Cheers,

 

Dave

Link to comment
https://forums.phpfreaks.com/topic/258437-form-help/#findComment-1325034
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.