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
Share on other sites

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>

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.