Forum Moderators: coopster

Message Too Old, No Replies

Simple Data Extraction from DB ..

         

RCDriver

11:24 pm on Apr 28, 2005 (gmt 0)

10+ Year Member



Hey, sorry for the newb question. I looked around on the forums but I couldn't really understand most of it. I've successfully setup a little form that inputs data into a table on my DB. Now I want to be able to extract the data and display on a regular html page.

Here's what I have that works:

-----------------------------------------------
INPUT PAGE:

<HTML>
<HEAD>
<TITLE>Your Title</TITLE>
</head>
<body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<BR>
<?php
$host="----";
$user="---";
$password="----";
$database="----";

// connecting to the database
$Link_ID=mysql_pconnect($host, $user, $password);
if (!$Link_ID)
{
echo "Failed to connect to ".$host;
return 0;
}
if (!@mysql_select_db($database,$Link_ID))
{
echo "<br>Cannot use database=".$database;
}
?>

<center>
<form name="news" method="post" action="news2.php">
<BR>

News content: <textarea name="content" rows="6"></textarea><BR>

Your email: <input type="text" name="email"><BR>

<input name="submit" type="submit" value="Submit">
</form>
<BR><BR>
</center>
</body>
</html>

--------------------------------------

CONFIRMATION PAGE:


<HTML>
<HEAD>
<TITLE>Your Title</TITLE>
</head>
<body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<BR>
<?php
$host="----";
$user="---";
$password="---";
$database="----";

// connecting to the database
$Link_ID=mysql_pconnect($host, $user, $password);
if (!$Link_ID)
{
echo "Failed to connect to ".$host;
return 0;
}
if (!@mysql_select_db($database,$Link_ID))
{
echo "<br>Cannot use database=".$database;
}

// sets info from previous pages into variables
$date = date("M d Y");
$content = $_POST['content'];
$email = $_POST['email'];

// inserts info into the table news
$insert = "INSERT INTO news ( content, email )
values( '$content', '$email' )";

// displays error or success message
if (! mysql_query( $insert ) ) {
die( "Couldn't add data to the table. You are now being taken back to the main page." );
} else {
echo "Your data was added to the table. You are now being taken back to the main page.";
}

?>

<BR><BR>
</center>
</body>
</html>

-----------------------------------------------------

So what I need to do, is have the confirmation page redirect to a page that can display the contents on the table in the DB.

Thanks,
Ian

RCDriver

11:42 pm on Apr 28, 2005 (gmt 0)

10+ Year Member



I was told to use this code but I'm not sure where it goes:

<?=$res['news']?>

Maybe the code should be:

<?php
=$res['news']
?>

?

Any help is good.

Oh and one last thing. Is there any way to modify the INPUT code I have to send the info to an email address? (with simple small code)

coopster

12:32 am on May 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, RCDriver.

Have you had a look at the PHP Forum Library [webmasterworld.com]? There is a short little tutorial in there describing how the Basics of extracting data from MySQL [webmasterworld.com].