hi all,
this is probably a dead set newbie problem (mostly because I am a dead set newbie I guess  ) but I am having great troubles writing a script to take form text input, write it to a database and retrieve it for display on my webpage.
I'm writing a website for my uni rockclimbing club and want to have the main body of text on each page editable via an external form (for ease of making announcements and the like). My thinking is to have a form textarea in which the new text is entered, on submit this text is sent to the database (think I have that much working). I'm then trying to grab this text from the database and display it on the webpage. here's my script so far
To write to the database:
HTML Code:
<form method="post" action="datain.php">
<textarea name="main_text" cols="100" rows="25"></textarea>
<input type="Submit" name="submit" value="submit">
</form>
where datain.php looks like this
PHP Code:
<?php
$db = mysql_connect("localhost", "root","");
mysql_select_db("uqrcdb",$db);
$sql = "INSERT INTO mainpage (main_text) VALUES ('$main_text')";
$result = mysql_query($sql);
echo "Thank you! Information entered.";
?>
I think this writes to the database ok, (but being a PHP/mySQL newb I may be wrong), my bigger issue comes when trying to display it. I have my display.php looking like this
PHP Code:
<?php
$db = mysql_connect("localhost", "root","");
mysql_select_db("uqrcdb",$db);
$result = mysql_query("SELECT main_text FROM mainpage" );
echo "$result";
?>
this returns Resource id #3, what the ?? I guess I've missed something. I've got mysql running with php on apache on my home machine if that matters any.
thanks guys.
Colin
|