Problem reading data out of MySQL db, PHP variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dariusz

    Problem reading data out of MySQL db, PHP variables

    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_tablenam e($AllTableList , $connection)!=$ TableName)
    {
    // Add data to create the fields needed in the guestbook
    mysql_query("CR EATE 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_da te, n_headline, n_summarytext,
    n_fulltext) VALUES(now(), '$_POST[headline]', '$_POST[summarytext]',
    '$_POST[fulltext]')");

    $result = @mysql_query($s ql, $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($s ql, $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<B R>";
    $InputFulltext = $NewsItem[3];
    echo "Full text: $InputFullText" ;
  • Jon Kraft

    #2
    Re: Problem reading data out of MySQL db, PHP variables

    ng@lycaus.plusY OURSHIT.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

    Comment

    • Dariusz

      #3
      Re: Problem reading data out of MySQL db, PHP variables

      In article <Xns94C47BC62BB 1Bjonjonuxcouk@ 130.133.1.4>, Jon Kraft <jon@jonux.co.u k> wrote:[color=blue][color=green]
      >> $InputFulltext = $NewsItem[3];
      >> echo "Full text: $InputFullText" ;[/color]
      >
      >$InputFullte xt != $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

      Comment

      Working...