By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,843 Members | 864 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,843 IT Pros & Developers. It's quick & easy.

Input not saving.

P: 6
I have no clue why the data from the form isn't saving into the database. What am I doing wrong?

addAnnounce.php:

[HTML]<td align=top>
<form action="index2.php" method="post">Heading:<br /><textarea name="heading" cols="50" rows="10"></textarea><br /><br />Announcement:<br />
<textarea name="announce" cols="50" rows="10"></textarea>
<br /><br />Date:<br /><textarea name="date" cols="50" rows="10"></textarea><br /><br /><input type="submit" value="Post" /></form>
</td>
</table>
</body>
</html>[/HTML]

index2.php:
[HTML] <td valign="top"><br />
<a href="addAnnounce.php">Click Here</a> to enter an announcement. <br /><br />
<img src="images/announceheader.gif" /><br />[/HTML]
[PHP]<?
$heading = $_POST['heading'];
$announce = $_POST['announce'];
$date = $_POST['date'];

// connect to the mysql server
$link = mysql_connect($DBhost, $DBuser, $DBpass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($DBName)
or die ("Could not select database because ".mysql_error());

// insert data into database
$insert = mysql_query("insert into $table (heading, announce, date) values ('$heading', '$announce', '$date')", $link)
or die("Could not insert data because ".mysql_error());

// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM $table")
or die(mysql_error());

echo "<table border='0'>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td><font class='heading'>";
echo $row['heading'];
echo "</font></td></tr><tr><td>";
echo $row['announce'];
echo "</td></tr><tr><td><font class='date'>";
echo $row['date'];
echo "</font></td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
}

echo "</table>";

mysql_close();
?>[/PHP]
[HTML]</td>
</tr>
</table>
</body>
</html>
[/HTML]
Dec 1 '06 #1
Share this Question
Share on Google+
2 Replies


ronverdonk
Expert 2.5K+
P: 4,258
It is confusing. Could you please show the entire INDEX2.PHP script within a single set of PHP,code or html tags? So we can see the entire program in one go.

Ronald :cool:
Dec 1 '06 #2

P: 6
addAnnounce.php
<?php
include "header.php";
$DBhost = "localhost";
$DBuser = "E098575";
$DBpass = "177Jess#";
$DBName = "announcements";
$table = "main";
?>

<td align=top>
<form action="index2.php" method="post">Heading:<br /><textarea name="heading" cols="50" rows="10"></textarea><br /><br />Announcement:<br />
<textarea name="announce" cols="50" rows="10"></textarea>
<br /><br />Date:<br /><textarea name="date" cols="50" rows="10"></textarea><br /><br /><input type="submit" value="Post" /></form>
</td>
</table>
</body>
</html>


index2.php
<td valign="top"><br />
<a href="addAnnounce.php">Click Here</a> to enter an announcement. <br /><br />
<img src="images/announceheader.gif" /><br />
<?
$heading = $_POST['heading'];
$announce = $_POST['announce'];
$date = $_POST['date'];

// connect to the mysql server
$link = mysql_connect($DBhost, $DBuser, $DBpass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($DBName)
or die ("Could not select database because ".mysql_error());

// insert data into database
$insert = mysql_query("insert into $table (heading, announce, date) values ('$heading', '$announce', '$date')", $link)
or die("Could not insert data because ".mysql_error());

// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM $table")
or die(mysql_error());

echo "<table border='0'>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td><font class='heading'>";
echo $row['heading'];
echo "</font></td></tr><tr><td>";
echo $row['announce'];
echo "</td></tr><tr><td><font class='date'>";
echo $row['date'];
echo "</font></td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
}

echo "</table>";

mysql_close();
?>
</td>
</tr>
</table>
</body>
</html>

Jessdmiller: Before you post anything, Read the Posting Guidelines at the top of this forum!! Especially the part about enclosing posted code within php, code or html tags!!!
Ronald :cool:
Dec 1 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.