Jump to content

insert db help


jeppers

Recommended Posts

<li>
	<input type="submit" name="submit" value="Send My Posting" />
</li>
<?php
echo $date;
if ($_POST['submit']){
 include ('mysql_connect.php');

$sql = "insert into date (dates) 
		values ('$date')";
	$result = @mysql_query($sql) or die (mysql_error()); //run query
}
else {
}

 

i am struggling with this error. i have created a dummy database which all i am trying to do is enter the date. which has been selected from pull down menu's i have concatenated them and stored them in a variable call $date.

 

i run the query and i get this as an error message

 

2010 01 1 Incorrect date value: '2010 01 1' for column 'dates' at row 1

 

has anyone got any idea on what i am doing wrong. hear is the full code i am using

 


<form action="pulldown.php" method="post">
<label for="date">Date</label>
<?php	
//make the months array 
$months = array (1 => '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');

//make the days and years array 
$days = range (1, 31);
$years = range (2010, 2012);

//make the days pull down menu 
echo '<select name="days">';
foreach ($days as $key => $value) {
echo "<option value=\"$value\">$value</option>\n";
}
echo '</select>';

//make that months pull down menus
echo '<select name="months">';
foreach ($months as $key => $value) {
echo "<option value=\"$value\">$value</option>\n";
}
echo '</select>';



//make the year pull down menu 
echo '<select name="years">';
foreach ($years as $key => $value) {
echo "<option value=\"$value\">$value</option>\n";
}
echo '</select>';

$days = strtolower($_POST['days']);
$months = strtolower($_POST['months']);
$years = strtolower($_POST['years']);


//create a date variable 
$date = $years .' '. $months .' '. $days;

?>

<li>
	<input type="submit" name="submit" value="Send My Posting" />
</li>
<?php
echo $date;
if ($_POST['submit']){
 include ('mysql_connect.php');

$sql = "insert into date (dates) 
		values ('$date')";
	$result = @mysql_query($sql) or die (mysql_error()); //run query
}
else {
}

?>

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.