Hello,
I've a form that adds data to the mysql database. It is working perfect. Now i want to add a checkbox in that....so that if it is checked then the record will be displayed in the homepage otherwise it shouldn't be displayed in the home page. I don't know how to do it. Pls help.
Here is the code:
<?php
include('dbconn.php');
?>
<html>
<head>
</head>
<body>
<script language="Javascript">
function checkForm(form1)
{
if(form1.headline.value=="")
{
alert("Please enter Headline!!");
form1.headline.focus();
return(false);
}
if(form1.date.value=="")
{
alert("Please enter Date!!");
form1.date.focus();
return(false);
}
}
</script>
<form name="form1" action="adddb.php" method="POST" onSubmit="return checkForm(this)">
<table border='0'>
<tr>
<td>
Headline* : <br>
<input type="text" name="headline" value="<?php print($headline);?>" />
</td>
</tr>
<tr>
<td>
Date: <br>
<input type="text" name="date" value="<?php print($date);?>" />
</td>
</tr>
<tr>
<td>
Content: <br>
<TEXTAREA name="body" class="body"><?php print($body);?></TEXTAREA></td>
</td>
</tr>
</table>
<input type="checkbox" name="frontpage" value="1" checked/>Display on Front Page
<br>
<br>
<input type="submit" value="Add" id="submit" name="submit" />
</form>
</body>
</html>
<?php
include('dbconn.php');
function es($val) {
return mysql_real_escape_string($val);
}
$sql = sprintf("INSERT INTO newsevents(headline,date,body)
VALUES
('$_POST[headline]','$_POST[date]','$_POST[body]')");
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
?>
<?php
include('dbconn.php');
$sql = "SELECT * FROM newsevents";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Click on the titles below to update News/Event details.";
echo "<br/>";
echo "<br/>";
$result = mysql_query("SELECT * FROM newsevents");
$num=mysql_num_rows($result);
mysql_close();
$i=0;
while ($i < $num) {
$news_id=mysql_result($result,$i,"news_id");
$headline=mysql_result($result,$i,"headline");
$date=mysql_result($result,$i,"date");
$body=mysql_result($result,$i,"body");
echo "<b><a href=\"edit.php?news_id=$news_id\">$headline</a> $date<br><br>";
$i++;
}
echo "Total No. of News Items = $num";
if(!$result)
{
echo "No data.";
}
mysql_free_result($result);
echo "<br>";
echo "<br>";
echo "<a href=\"add.php\">Add News Item";
?>