Jump to content

Problem inserting date in database


Lassie

Recommended Posts

I have form which allows a user to select a date as part of the form.

On submitting i am getting no update to the database and no error message.

To try and test it i created a shorter version which sets up the variables except the date.This gives the same result.ie no update.

The date prints out correctly as a variable.

What else can i do to find the error?

 


<?php #register property

// Include the configuration file for error management and such.
require_once ('./includes/config.inc.php');


// Set the page title and include the HTML header.
$page_title = 'Register a Property';

session_start();
include ('./includes/header.html');
require_once ('./mysql_connect2.php'); // Connect to the database.

// Handle the form.
	if (isset($_POST['submitted'])) 
{ 




		//Check availability for sale.
if($_POST['month'])
{
	$m= escape_data($_POST['month']);
}
else{
	$m = FALSE;
	echo '<p><font color="red" size="+1">Please enter month!</font></p>';
}
//Check availability for sale.
if($_POST['day'])
{
	$dy= escape_data($_POST['day']);
}
else{
	$dy = FALSE;
	echo '<p><font color="red" size="+1">Please enter day of month!</font></p>';
}
//Check availability for sale.

if($_POST['year'])
{
	$y= escape_data($_POST['year']);
}
else{
	$y = FALSE;
	echo '<p><font color="red" size="+1">Please enter year!</font></p>';
}
if (!checkdate($m,$dy,$y)) {
    $error = 'You have used an invalid date';
    }
  else {
    $dy = $dy < 10 ? '0'.$dy : $dy;
    $mysqlFormat = "$y-$m-$dy";
    $av=$mysqlFormat;
}	

}else{
		echo "Your Property could not be registered due to a system error.Please contact admin@homeownersdirect";

		}


//set the variables



		$v= 12;
		$rc=456;
		$rn="stockies resort";
		$ct="Spain";
		$rg="Almeria";
		$tp="T1";
		$un=23;
		$ft="ground";
		$ow="floating";
		$cl="red";
		$oc=12;
		$bk="yes";
		$p=3000;
		$o="yes";
		$t="hutchinson";
		$d="fhfgfhf";


		echo "<br />";
		echo "$v<br />";
		echo "$rc<br />";
		echo "$rn<br />";
		echo "$ct<br />";
		echo "$rg<br />";
		echo "$tp<br />";
		echo "$un<br />";
		echo "$ft<br />";
		echo "$ow<br />";
		echo "$cl<br />";
		echo "$oc<br />";
		echo "$bk<br />";
		echo "$av<br />";

		echo "$p<br />";
		echo "$o<br />";
		echo "$t<br />";
		echo "$d<br />";

			//add the property

	$query = "INSERT INTO property (v_id,rci_ref,resort_name,country,region,unit_desc,unit_num,floor_type,ownership,floating,
	occ_wk ,booked,price,available,offers,trustees,description)
	VALUES
	('$v','$rc','$rn','$ct','$rg','$tp','$un','$ft','$ow','$cl','$oc','$bk','$av','$p','$o','$t','$d')";

		$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());

//set date
		?>
		<h1>Select Date available</h1>
		<form action="db_test" method="post">
		<fieldset>
		<legend>Select Date</legend>
		<?php 
		// This script makes three pull-down menus for an HTML form: months, days, years.

		// Make the months array.
			$month = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

		// Make the months pull-down menu.
		echo '<select name="month">';
		foreach ($month as $key => $value) {
		echo "<option value=\"$key\">$value</option>\n";
		}
		echo '</select>';

		// Make the days pull-down menu.
		echo '<select name="day">';
		for ($day = 1; $day <= 31; $day++) {
		echo "<option value=\"$day\">$day</option>\n";
		}
		echo '</select>';

		// Make the years pull-down menu.
			echo '<select name="year">';
			$year = 2007;
		while ($year <= 2015) {
		echo "<option value=\"$year\">$year</option>\n";
		$year++;
		}
		echo '</select>';
		?>
		</fieldset>
		<div align="center"><input type="submit" name="submit" value="submit" /></div>
		<input type="hidden" name="submitted" value="TRUE" />

		</form>



Link to comment
https://forums.phpfreaks.com/topic/70153-problem-inserting-date-in-database/
Share on other sites

try this,

<?php #register property

// Include the configuration file for error management and such.
require_once ('./includes/config.inc.php');


// Set the page title and include the HTML header.
$page_title = 'Register a Property';

session_start();
include ('./includes/header.html');
require_once ('./mysql_connect2.php'); // Connect to the database.

//set the variables
$v= 12;
$rc=456;
$rn="stockies resort";
$ct="Spain";
$rg="Almeria";
$tp="T1";
$un=23;
$ft="ground";
$ow="floating";
$cl="red";
$oc=12;
$bk="yes";
$p=3000;
$o="yes";
$t="hutchinson";
$d="fhfgfhf";


echo "<br />";
echo "$v<br />";
echo "$rc<br />";
echo "$rn<br />";
echo "$ct<br />";
echo "$rg<br />";
echo "$tp<br />";
echo "$un<br />";
echo "$ft<br />";
echo "$ow<br />";
echo "$cl<br />";
echo "$oc<br />";
echo "$bk<br />";
echo "$av<br />";

echo "$p<br />";
echo "$o<br />";
echo "$t<br />";
echo "$d<br />";

//add the property

$query = "INSERT INTO property (v_id,rci_ref,resort_name,country,region,unit_desc,unit_num,floor_type,ownership,floating,
	occ_wk ,booked,price,available,offers,trustees,description)
	VALUES
('$v','$rc','$rn','$ct','$rg','$tp','$un','$ft','$ow','$cl','$oc','$bk','$av','$p','$o','$t','$d')";

#$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
$result = mysql_query ($query) or die("Query: $query\n<br />MySQL Error: " . mysql_error());
?>

 

whats the error?

Thanks for your reply.

I inserted your code line and ran it but I get no errors and no db update.

As I said this is part of the whole form and I have condensed it to try and get he insert to work.

There are other columns in the table and I have had the error 'Column count doenst match value count at row 1' in the main program. I thought maybe the date was the problem. The column count and value count are equal so I am a little lost.

Any thoughts?

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.