Hi i have this form but it wont insert the date into the database how do i format it i tried CURDATE() but its not working what i’m i doing wrong help please?? its a two fields form
<?php
mysql_connect("localhost","root","");
mysql_select_db("eurico_edy") or
die (mysql_errno().":<b> ".mysql_error()."</b>");
// Each time there's an error, add an error message to the error array
// using the field name as the key.
$insert_query = 'insert into news (
news_id,
subject,
news_date,
news_artical
)
values
(
"' . $_POST[''] . '",
"' . $_POST['subject'] . '",
"' . $_POST["CURDATE()"] . '",
"' . $_POST['news_artical'] . '"
)';
mysql_query($insert_query);
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<div id="news">
<form name="newsadmin" action="newsadmin.php" method="post">
<p><strong>Artical:</strong><br />Please enter subject</p>
<p><input type="text" name="subject"</p>
<p>Please enter your news</p>
<p><input type="text" name="news_artical"</p>
<p><input type="submit" name="submit" value="Create News" class="submit"></p>
</form>
</div>
</body>
</html>
Hi i must be missing something why on an update form the date is only showing the month if i delete %m it shows it will show the nect carachter which is day why is not showing all 3 day month day and year??
$query = "SELECT *, DATE_FORMAT(news_date, ‘%m/ %d/ %Y’) as new_date FROM news WHERE news_id = ‘$news_id’ ";
<?php
define('ROOT_DIR', './');
define('THIS_SCRIPT', 'news');
define('PROPER', TRUE);
/**
* include common files
*/
include_once(ROOT_DIR. 'includes/common.inc.php');
?>
<?php
// query to get records
$news_id = $_GET['news_id'] ;
// create query to delete record
$query = "SELECT *, DATE_FORMAT(news_date, '%m/ %d/ %Y') as new_date FROM news WHERE news_id = '$news_id' ";
//Run the query
$result = mysql_query($query);
//see if any rows were returned
if (mysql_num_rows($result) > 0) { // yes - Display Form
$row = mysql_fetch_array($result); //Fetch the row
//Display the form with original values
?>
<form action = 'modifynewsaction.php' method="GET" enctype="multipart/form-data">
<p>ID: <input readonly="yes" name="id" type="text" value=<?php print $row["news_id"] ?> size="3" >
This has been made 'readonly' as cannot amend key field </p>
<p>Date: <input type="text" name="new_date" value=<?php print $row["new_date"] ?> ></p>
<p>Subject: <input type="text" name="subject" value=<?php print $row["subject"] ?> ></p>
<p>Artical: <input type="text" name="news_artical" value=<?php print $row["news_artical"] ?> ></p>
<p><input type="submit" value="Submit" name="Update" > </p>
</form>
<?php
} //End if rows returned
//No rows returned
else print "No records were found";
?>
</body>
</html>
I use the [fphp]substr[/fphp] function to shuffle things around and get the pieces of the date I need in the right order. There are other solutions but IMO using substr is the easiest option
PS. I hope this is code from a dev machine where root doesn’t have a password, or you removed the password from the code when you posted it here? Having no password for root on a production machine is a Bad Idea ™
PPS. Please have a look at data sanitizing, more specifically at [fphp]mysql_real_escape_string/fphp to prevent SQL Injection.
help please i tried modify like this still did not work gave error
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\rookierods\modifynews.php on line 37
$result = mysql_query("select *,date_format(news_date, '%M %d %Y') as date_string FROM news") or die(mysql_error());
$result = mysql_query($query);
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes so print them one after another
echo "<table cellpadding=10 border=1>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>".$row["news_id"]."</td>";
echo "<td>".$row["subject"]."</td>";
echo "<td>" .$row["date_string"]."</td>";
echo "<td>".$row["news_artical"]."</td>";
echo "<td><a href=delete2.php?id=".$row["id"].">Delete</a></td>";
echo "<td><a href=modifyform.php?id=".$row["id"].">Modify</a></td>";
echo "<td><a href=add.php?id=".$row["id"].">Add Row</a></td>";
echo "</tr>";
} //End While
echo "</table>";
} //End if rows
Can I kindly ask you to please read my answers? I never proposed you do such a thing … I did state that the syntax you’re using right there is meant to be in a query and if you want to do it in PHP you should have a look at the [fphp]substr[/fphp] function …
So in your case you either need to change the query in the first line ($query = "SELECT * FROM news";) or correctly reconstruct the date using [fphp]substr[/fphp] in this line echo "<td>" .$row["news_date[s], %d %m %y[/s]"]."</td>";