HTML/Javascript

SES by business degree online promotion team.

Philippine Airlines International Flight schedules

Philippine Airlines International Flight schedules
Philippine Airlines International Flight schedules

Search This Blog

Thursday, October 7, 2010

PHP FOR NEWS LETTER

code to paste:

newsentry.php


<table align="center" border="0">
<form method="post" action="addnews.php">
<tr>
<td align="right"><font face="tahoma" size="2"><b>News Title</b></font></td>
<td align="left"><input type="text" name="newstitle"></td>
</tr>
<tr>
<td align="right"><font face="tahoma" size="2"><b>Message</b></font></td>
<td align="left">
<textarea rows="10" cols="30" wrap="physical" name="message">
Enter Comments Here
</textarea>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="submit">
<input type="reset" value="reset">
</td>
</td>
</form>
</table>


sample output:




Then insert/save data to mysql database. See below.

addnews.php

<html>
<body>
<?php
$con = mysql_connect("localhost","root","yourpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("newsletter", $con);

$newstitle=$_REQUEST['newstitle'];
$message=$_REQUEST['message'];

$sql="INSERT INTO news (newstitle, message)
VALUES
('$newstitle','$message')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";


mysql_close($con)
?>


Then dipslay newsletter.

latestnews.php


<?php
$con = mysql_connect("localhost","root","youpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("newsletter", $con);

$result = mysql_query("SELECT * FROM news order by newsid DESC");

echo "<table border='0' width='500' align='center'>
<tr>
<td align='center'><font color='#2E57A5' size='5'><b>Latest News</b></font></td>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "</tr>";
echo "<tr>";
echo "<td><b><font face='tahoma' size='2'>" . $row['newstitle'] . "</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='justify'><font face='tahoma' size='2'>" . $row['message'] . "</font></td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>

note: this is only DUMMY sample , try to add date for the newsletter.

output:

No comments:

Post a Comment