textarea to mysql - Page 2 - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Programming > PHP Development

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-09-2010, 05:26 PM   #11 (permalink)
Junior Member
 
Join Date: Mar 2010
Posts: 1
Thumbs up Re: textarea to mysql

I got this code to work, but after 4 days of frustration! I created 3 pages instead of the two he has here because that makes it work-with a couple of lines of code inserted.

The first page is the form:
//hands of the post values to a handler
<form name="news" method="post" action="textareatexthandler.php">
<textarea name="comment" cols="90" rows="25" wrap="hard"></textarea><br />
<input type="submit" value="Submit" />

//The handler page only contains the insert function instead of the insert and select function
<?php
$host="serverName";
$username="rainhider";
$password="yeah_right";

$conn = mysql_connect($host, $username, $password) or
die('Error connecting to mysql ' . mysql_error());


$selected = mysql_select_db("rainhid_test", $conn)or
die("Could not select db rainhid_test");


$mysql = array(); // create array of mysql escaped values
$mysql['comment'] = mysql_real_escape_string( $_POST['comment'] );
$sql = "INSERT INTO comments ( comment_text ) VALUES ( '{$mysql['comment']}' )"; //insert your comment to db
mysql_query( $sql );

//I needed to retrieve the last mysql id inserted to the database and this code //retrieves the id number of the last insert and then stores it in the session array so that I can retrieve it on the third page.

session_start();
$_SESSION['$sqlID'] = mysql_insert_id(); // store last id in session array
echo $_SESSION['$sqlID']; //just to make sure it got the number


echo "Success! Your newsletter has been saved and posted!"
?>


//The third page retrieves the last inserted comment(by the last id) and displays it

$host="serverName";
$username="rainhider";
$password="yeah_right";

$conn = mysql_connect($host, $username, $password) or
die('Error connecting to mysql ' . mysql_error());


$selected = mysql_select_db("rainhid_test", $conn)or
die("Could not select db rainhid_test");


session_start();
$sqlID = $_SESSION['$sqlID'];
$sql = "SELECT * FROM comments where comment_id='$sqlID'";
$result = mysql_query( $sql );
while( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ) {
$html = array(); //create an array of html formated values.
$html['comment'] = nl2br( stripslashes( htmlentities( $row['comment_text'], ENT_QUOTES, 'UTF-8' ) ) );
echo "<br />{$html['comment']}<hr />";
}
?>

TaDa!
rainhider is offline   Reply With Quote
Sponsored Links
Old 01-09-2011, 02:50 AM   #12 (permalink)
Junior Member
 
Join Date: Jan 2011
Posts: 1
Smile Re: textarea to mysql

Worked like a charm. Thank you for help with this code
eplumbers is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 08:43 AM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting