Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
database write and display issues
Old 11-29-2004, 05:00 AM database write and display issues
Junior Talker

Posts: 2
Trades: 0
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
pseudonym is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-29-2004, 07:26 AM
Ultra Talker

Posts: 377
Trades: 0
mysql_query function doesn't return a result of query, it returns it's id. To recieve result of query from $result you may use:
- mysql_result()
- mysql_fetch_array()
More info about these functions is here -htttp://www.php.net
__________________
andrews_john

Please login or register to view this content. Registration is FREE
andrews_john is offline
Reply With Quote
View Public Profile Visit andrews_john's homepage!
 
Old 11-29-2004, 08:11 AM
KCamel's Avatar
Average Talker

Posts: 16
Trades: 0
PHP Code:
<?php
$db 
mysql_connect("localhost""root","");
mysql_select_db("uqrcdb",$db);
$result mysql_query("SELECT main_text FROM mainpage" );

while(
$fetch mysql_fetch_array($result))
{
   echo 
$fetch[main_text];
}
?>
I hope this example will make it more clear to you
__________________
* KCamel Inc, Host it Simple!
* Different Support Methods! 24\7!
* For more information contact me on:
Moe J. Mughrabi

Please login or register to view this content. Registration is FREE

*
Please login or register to view this content. Registration is FREE
KCamel is offline
Reply With Quote
View Public Profile
 
Old 12-01-2004, 07:57 AM cheers guys
Junior Talker

Posts: 2
Trades: 0
hey thanks guys, been doing a bit of reading and I see now the error of my ways.

it works now BTW

thanks again

Colin
pseudonym is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to database write and display issues
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14146 seconds with 12 queries