Forum Moderators: coopster
Take a look at the code, you should be able to figure out what is going on.
Also, make sure your web host has enabled PHP in your account. Sometimes you have to request this even though you have already had the database setup. They don't automatically assume you are going to use PHP.
This is my first post here, so I'm not sure how the code below is going to turn out. If it doesn't work you can e-mail me and I will send it to you.
//save this file as formconnect.php and upload it to your server.
<?php
function doDB() {
global $conn;
//connect to server and select database - You will get this info from your hosting company.
$conn = mysql_connect("www.yoursite.com", "uname", "password")
or die(mysql_error());
mysql_select_db("dbname",$conn) or die(mysql_error());
}
//connect to database
doDB();
?>
<html>
<head>
<title>Your Page Title</title>
</head>
<body>
<?php
if($sendit == 1){
mysql_query("UPDATE h1bnews set newsitem = '$_POST[h1bmessage]', postdate = now() WHERE id = 1",$conn) or die(mysql_error());
$result = mysql_query("SELECT newsitem, postdate FROM h1bnews WHERE id = 1",$conn) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
echo '<center>Below is what you have submitted. <a href="formconnect.php">Click Here</a> to make additional changes.</center><br><br>';
echo '<br><b>'.$row[postdate].'</b><br><br>';
echo $row[newsitem];
}
$sendit = 0;
}else{
$result2 = mysql_query("SELECT newsitem, postdate FROM h1bnews WHERE id = 1",$conn) or die(mysql_error());
$row = mysql_fetch_array($result2);
echo '<br>';
echo '<center><b>Updating H1B News In Database</b></center>';
echo '<br>';
echo '<center>';
echo '<form method="POST" action="'.$_SERVER[PHP_SELF].'">';
echo '<input type="hidden" value="1" name="sendit">';
echo '<table border="0" bordercolor="black" bgcolor="#FFDC7C">';
echo '<tr>';
echo '<td valign="top"><b>Your H1B Message:</b></td><td><textarea name="h1bmessage" rows="40" cols="95">'.$row[newsitem].'</textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan="2"><center><input type="submit" value="Update H1B News Now"></center></td>';
echo '</tr>';
echo '</table>';
echo '</center>';
}
?>
</body>
</html>