Closed Thread Icon

Topic awaiting preservation: making php messageboard mysql help (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12020" title="Pages that link to Topic awaiting preservation: making php messageboard mysql help (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: making php messageboard mysql help <span class="small">(Page 1 of 1)</span>\

 
maninacan
Paranoid (IV) Inmate

From: Seattle, WA, USA
Insane since: Oct 2001

posted posted 01-27-2002 05:58

ok so i'm making a messageboard of my own in php. I've got the login and signup parts done, so now it's on to the actual message part of the messageboard I'm storing all my stuff in a mysql database, and i noticed that a normal varchar has a maximum of 255 characters which would quite frequently be to small for people's posts, so i looked around and the only other option i found was making a blob (are there any others that I missed?) so i made my blob and made a test message and of course it doesn't work in the browser with the following code:
SELECT message FROM message WHERE messageid='$messageid'
so I wanted to know how I get the thing to display the message, any ideas (sorry if i didn't make myself clear, please ask me any questions that could help clear up my needs)?

http://www.maninacan.com

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 01-27-2002 10:22

You should use 'TEXT' field type instead...


maninacan
Paranoid (IV) Inmate

From: Seattle, WA, USA
Insane since: Oct 2001

posted posted 01-27-2002 18:57

but the whole reason i didn't use 'text', or 'varchar' as the type is because it limits each one to 255 characters.

Gynot
Bipolar (III) Inmate

From: Brooklyn, NY
Insane since: Jan 2002

posted posted 01-27-2002 19:15

You can create indexes on the first 255 characters of a text column, but it can hold 16,777,215 characters

~Peace~
Gary
My PHP/MySQL Test Page

DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 01-27-2002 21:06

Hi there maninacan

On the display message part, what you've got there is an SQL-statement which in itself is correct if you want to grab one specific message from a table called mesage (it would be good for you to use different names on the table and the collumn).

However, placing this line in your php-code won't display the message on the page as you have already found out.
In short, what you have to write code for is this:
1. Connect to the database
2. Create the query
3. Pass the query to the database using the connection
4. Collect the answer from the db
5. loop through the answer and for each print the actual result to the page

This could look some thing like this:

code:
<?php
/*config connection to database*/
$host = 'localhost';
$user = '';
$password = '';
$db = 'message';

/*connect to the database*/
$connection = mysql_connect($host,$user,$password);

/*select database */
mysql_select_db($db,$connection);

/* make query */
$query = "SELECT message FROM message WHERE messageid='$messageid'";

/*do query to the database */
$result = mysql_query($query,$connection);

/* collect result in an array and loop the array and print to page */
/* I'm thinking you have two collumns in there, messageid and message */

while ($row = mysql_fetch_row($result)){
$messageid = $row[0];
$message = $row[1];
print("<p>$message</p>");
}
?>



This is very simple and not tested, but it should work if your database looks like that and you provide the user & pwd it shohould print the message enclosed with <p></p> tags.

There is a tutorial up at the gurusnetwork that might help you through this if you don't get it working from this.

Hope it helps.
/Dan


-{ a vibration is a movement that doesn't know which way to go }-

maninacan
Paranoid (IV) Inmate

From: Seattle, WA, USA
Insane since: Oct 2001

posted posted 01-27-2002 21:32

ok, so i switched the type from 'blob' to 'text' and I do the following stuff after I connect to the database:

$query = "select message from message where messageid='$messageid'";

$result = mysql_query("$query",$db);
if($row = mysql_fetch_row($result)){
...

and it says that "Supplied argument is not a valid MySQL result resource" for the line:
if($row = mysql_fetch_row($result)){

and i can't figure out what's wrong someone help

http://www.maninacan.com

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 01-27-2002 23:09

im not sure, but since your query returns exactly one value and not a set (array) you dont need to fetch it.
try echoing the $result and see what you get.
if you get array, you might try mysql_fetch_array()

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 01-28-2002 00:00

echoing a My SQL result set will not echo the what the query returns (even if it's just 1) you'll usually get something like "MySQL result set" or something like that. you do need yoo use one of the mysql result methods applied to it to get some sort of usable data

I don't see anyhting jumping out at me. Is this the only error?

You may want to just check that $result is not returning false which would indicate a problem with the SQL syntax



:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

maninacan
Paranoid (IV) Inmate

From: Seattle, WA, USA
Insane since: Oct 2001

posted posted 01-28-2002 00:02

nevermind!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I was having problems in two areas neither of which i could figure out, and then after my dad came and looked at it for about 45 minutes he finally figured out the problem, I was trying to connect to a database called mesageboard, when the actual name was messageboard. It's always the little things that really screw you up.

http://www.maninacan.com

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 01-28-2002 00:04

hehe

therefore you should always check the query for errors too, like:

if (!$result = mysql_query("$query",$db)) echo mysql_error();

« BackwardsOnwards »

Show Forum Drop Down Menu