By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,165 Members | 849 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,165 IT Pros & Developers. It's quick & easy.

Problem reading data out of MySQL db, PHP variables

P: n/a
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";
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ng@lycaus.plusYOURSHIT.com (Dariusz) wrote:
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. $InputFulltext = $NewsItem[3];
echo "Full text: $InputFullText";


$InputFulltext != $InputFullText

HTH;
JOn
Jul 17 '05 #2

P: n/a
In article <Xn**************************@130.133.1.4>, Jon Kraft <jo*@jonux.co.uk> wrote:
$InputFulltext = $NewsItem[3];
echo "Full text: $InputFullText";


$InputFulltext != $InputFullText


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
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.