Jump to content

Date value to Mysql


echocpt

Recommended Posts

Hi i have got this php script that inserts info added from a user into a database and it all work excepet for the date. I was wondering if anyone could help me get it working? The date should upload to the DB in a yyyy-mm-dd format and then redisplay itself but atm wont add.

 

The "article.php" code:

<?php 
// Include the database connection file.
include("connection.php");
// Check if a person has clicked on submit.
if(isset($_POST['submit'])) { 
// Check if a person has filled every form.
if(empty($_POST['title']) || empty($_POST['content']) || empty($_POST['page'])) {
	header("Location: admin.php?h=true"); // Redirect to the form.
	exit; // Stop the code to prevent the code running after redirecting.
}
// Create variables from each $_POST.
$title = $_POST['title'];
$content = $_POST['content'];
$page = $_POST['page'];
$day = $_POST['day1'];
$month = $_POST['month1'];
$year = $_POST['year1'];
$full = $year . $month . $day;
}
// Create a variable containing the SQL query.
$query = "INSERT INTO 'content' (title, content, page, date) VALUES ('$title', '$content', '$page', '$full')";
// Perform the SQL query on the database.
$result = mysql_query($query);
// If the query failed, display an error.
if(!$result) { 
	echo "Your query failed. " . mysql_error(); // The dot seperates PHP code and plain text.
} else {
	// Display a success message!
	header("Location: admin.php?d=true");
}

?>

 

This is the HTML from code:

					  <form id="form1" name="form1" method="post" action="article.php">
						<table width="638" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="190" height="28" valign="top">
								<strong>Add a new article:</strong></td>
								<td width="448"><label></label></td>
							</tr>
							<tr>
								<td height="28">Title:</td>
								<td>
								<input name="title" type="text" class="area" id="title" /></td>
							</tr>
							<tr>
								<td height="33">Date:<br />
								(day/month/year) format</td>
								<td><label>
								  <select name="day1" size="" id="day1">
								    <option>01</option>
								    <option>02</option>
								    <option>03</option>
                                        <option>04</option>
                                        <option>05</option>
                                        <option>06</option>
                                        <option>07</option>
                                        <option>08</option>
                                        <option>09</option>
                                        <option>10</option>
                                        <option>11</option>
                                        <option>12</option>
                                        <option>13</option>
                                        <option>14</option>
                                        <option>15</option>
                                        <option>16</option>
                                        <option>17</option>
                                        <option>18</option>
                                        <option>19</option>
                                        <option>20</option>
                                        <option>21</option>
                                        <option>22</option>
                                        <option>23</option>
                                        <option>24</option>
                                        <option>25</option>
                                        <option>26</option>
                                        <option>27</option>
                                        <option>28</option>
                                        <option>29</option>
                                        <option>30</option>
                                        <option>31</option>
							      </select>
								  <select name="month1" id="month1">
								    <option>01</option>
								    <option>02</option>
								    <option>03</option>
								    <option>04</option>
								    <option>05</option>
								    <option>06</option>
								    <option>07</option>
								    <option>08</option>
								    <option>09</option>
								    <option>10</option>
								    <option>11</option>
								    <option>12</option>
							      </select>
								  <select name="year1" id="year1">
								    <option>2008</option>
                                        <option>2009</option>
                                        <option>2010</option>
                                        <option>2011</option>
                                        <option>2012</option>
                                        <option>2013</option>
                                        <option>2014</option>
                                        <option>2015</option>
                                        <option>2016</option>
                                        <option>2017</option>
                                        <option>2018</option>
                                        <option>2019</option>
                                        <option>2020</option>
                                        <option>2021</option>
                                        <option>2022</option>
                                        <option>2023</option>
                                        <option>2024</option>
                                        <option>2025</option>
							      </select>
								</label></td>
							</tr>
							<tr>
								<td height="141">Content:</td>
								<td><label></label><label>
								<textarea name="content" cols="50" rows="8" class="box" id="content"></textarea>
								</label></td>
							</tr>
							<tr>
								<td height="33">Add to:</td>
								<input name="groupid" type="hidden" value="<?php echo $_GET['id']; ?>" />
								<td><select name="page" id="page">
								<option>Home</option>
								<option>News</option>
								</select></td>
							</tr>
							<tr>
								<td height="34"> </td>
								<td><label>
								<input type="submit" name="button" id="button" value="  Post  " /></form>

Link to comment
https://forums.phpfreaks.com/topic/123127-date-value-to-mysql/
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.