Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem reading data out of MySQL db, PHP variables

Dariusz
Guest
 
Posts: n/a
#1: Jul 17 '05
Below is part of a code I have for a database. While the database table is
created correctly (if it doesn't exist), and data is input correctly into
the database when executed, I have a problem when reading out the data into
the PHP variables / array.

It should be displaying the information out in the following way, using
the PHP array:

n_date, n_headline, n_summarytext, n_fulltext

But what actually gets displayed is the data for:

n_date, n_headline, n_summarytext

So the "n_fulltext" is not displayed, but the echo'ed text preceeding it
"Full text:" is displayed, but it is not reading the information out of the
variable. I have checked that there is information input in this field in
the db, and it is there.

A fresh pair of eyes looking over the code is appreciated.

Thanks

Dariusz



// loop through result to look for your table
if (mysql_tablename($AllTableList, $connection)!=$TableName)
{
// Add data to create the fields needed in the guestbook
mysql_query("CREATE TABLE $TableName(
n_date DATETIME NOT NULL PRIMARY KEY,
n_headline VARCHAR(60) NOT NULL,
n_summarytext VARCHAR(200) NOT NULL,
n_fulltext BLOB NOT NULL)");
}

// Enter the data into the guestbook database
// Note, the now() id is infact a MySQL date array type
$sql = ("INSERT INTO $TableName(n_date, n_headline, n_summarytext,
n_fulltext) VALUES(now(), '$_POST[headline]', '$_POST[summarytext]',
'$_POST[fulltext]')");

$result = @mysql_query($sql, $connection) or die("<B>Problem entering data
into database: </B>".mysql_error());

// Now read the information back out from the Database ready for printing
on screen
$sql = ("SELECT * FROM $TableName ORDER BY n_date DESC");

$readout = @mysql_query($sql, $connection) or die("<B>Problem reading data
from database: </B>".mysql_error());

// Build result array
$NewsItem = mysql_fetch_row($readout);
// Get the data from the result of the array positions and display them
$InputDate = $NewsItem[0];
echo "Submitted on: $InputDate<BR>";
$InputHeadline = $NewsItem[1];
echo "Headline: $InputHeadline<BR>";
$InputSummary = $NewsItem[2];
echo "Summary: $InputSummary<BR>";
$InputFulltext = $NewsItem[3];
echo "Full text: $InputFullText";

Jon Kraft
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Problem reading data out of MySQL db, PHP variables


ng@lycaus.plusYOURSHIT.com (Dariusz) wrote:
[color=blue]
> Below is part of a code I have for a database. While the database
> table is created correctly (if it doesn't exist), and data is input
> correctly into the database when executed, I have a problem when
> reading out the data into the PHP variables / array.[/color]
[color=blue]
> $InputFulltext = $NewsItem[3];
> echo "Full text: $InputFullText";[/color]

$InputFulltext != $InputFullText

HTH;
JOn
Dariusz
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Problem reading data out of MySQL db, PHP variables


In article <Xns94C47BC62BB1Bjonjonuxcouk@130.133.1.4>, Jon Kraft <jon@jonux.co.uk> wrote:[color=blue][color=green]
>> $InputFulltext = $NewsItem[3];
>> echo "Full text: $InputFullText";[/color]
>
>$InputFulltext != $InputFullText[/color]

You see, that's been driving me mad for two days - I failed to spot that
mistake. Thanks for that Jon :) . All works okay now.

Dariusz
Closed Thread