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> </td></tr>";
}
echo "</table>";
mysql_close();
?>[/PHP]
[HTML]</td>
</tr>
</table>
</body>
</html>
[/HTML]
2 2200
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:
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> </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:
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bill H |
last post by:
I'm really new to Internet apps and such sorry, if this is a "duh"
question.
What is the standard approach to saving input from a form if on submit
the database connection fails?
I'm thinking...
|
by: Susan Cranford |
last post by:
Please forgive, I have looked at so much info I can't figure out how to
put it together even though I know it must be fairly simple.
I have an array of input text boxes (txtDOBn) where n is...
|
by: Greg |
last post by:
I'm fairly new to access (using 2002) and am setting up a DB for work.
along with each record the user also needs to make a flow diagram
(previously, these reports were composed in word and they...
|
by: Amjad |
last post by:
Hi,
I'm trying to create dynamic default values in TextBoxes
that reflect the last user's input value.
How can I save the user's input in a textbox control so
that the user can see his last...
|
by: hrpreet |
last post by:
Hi All,
I need the file chooser in the jsp, just for brosing and saving the
file path in the database, so i have used the following code.I dont
need to read the file content. I have to make it...
|
by: mtgrizzly52 |
last post by:
First thing, because of you all and this web site, I am building a first class time saving database for my fellow workers to use.
My really dumb questions is this.
I have a control in a subform...
|
by: Diogenes |
last post by:
Hi All;
I, like others, have been frustrated with designing
forms that look and flow the same in both IE and Firefox.
They simply did not scale the same.
I have discovered, to my chagrin,...
|
by: John Williams |
last post by:
I'm writing a stagenography program to experiment with how it works.
The algorithm I'm using appears to be producing the correct
result...however I'm struggling with the file input. I never...
|
by: JPhilS |
last post by:
Hi to all Webmaster!
I have discover this problem when I inserted the scores of the students i a centain subject.
I am making a school project with regards to saving students' record.
first, I...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |