Can you help error in fetching database

chapter 4 in point book (publishing mysql data on the web )and and iam in jokelist.php programme iam trying to fetch data from the datbase but when i fetched the data from database it appears like this the result:
0
0
0
0
even if i put a real sentence

please post part of your code so we can see what happening

I dont quite understand which book you are talking about? Can you show your code to fetch the data from database?

These are forums for general PHP programming, so a lot of us haven’t read the book you are having problems with.

So, first of all, is the data correct in the database? (PHPMyAdmin should show you)

If so, it’s a problem with the data output code, so could you post that here, in

 BBCode tags?

If the data isn't in the database correctly, its a data input problem, so can you post the php code behind the database insert?

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<title>Our List of Jokes</title>
<meta http-equiv=“content-type”
content=“text/html; charset=iso-8859-1” />
</head>
<body>
<?php
// Connect to the database server
$dbcnx = @mysql_connect(‘localhost’, --‘’, ‘–’);
if (!$dbcnx) {
exit(‘<p>Unable to connect to the ’ .
‘database server at this time.</p>’);
}
// Select the jokes database
if (!@mysql_select_db(‘ijdb’)) {
exit(’<p>Unable to locate the joke ’ .
‘database at this time.</p>’);
}
?>
<p>Here are all the jokes in our database:</p>
<blockquote>
<?php
// Request the text of all the jokes
$result = @mysql_query(‘SELECT joketext FROM joke’);
if (!$result) {
exit('<p>Error performing query: ’ . mysql_error() . ‘</p>’);
}
// Display the text of each joke in a paragraph
while ($row = mysql_fetch_array($result)) {
echo ‘<p>’ . $row[‘joketext’] . ‘</p>’;
}
?>
</blockquote>
</body>
</html>

The code itself seems okay though the code can be enhanced for better look and error reporting. Are you sure there is something in the field ‘joketext’ in the database? try to see the data from phpmyadmin or some other mysql client software if there is really some texts in that field. Not suppress the errors by putting @ in front of functions.


$result = mysql_query('SELECT joketext FROM joke') or die(mysql_error());

Which will give you a proper error if query has some errors in it.

Since it is displaying 0s four times as mentioned in the first post, i suspect there is some text in the field or not.

the problem actually when i insert data into my database it turned to zero the number zero i don’t know why. i discovered the problem my database accept just the INT how i edit this error should i create anew database or i can edit this

This is your lucky day, abeli , I’m going through the same book. It’s Build Your Own Database Driven Website by Kevin Yank (Chapter #6 A Content Management System). A summary of what this project is supposed to do: manage Joke text, joke authors and joke categories. The methods you used to access your database look fine. From that point on, I’m sorry to say, make no sense at all.

There are several different .php documents that are use together to make this project work. For the benefit of other forum members, they are as follows:

  • index.html
  • newjoke.php
  • newcat.php,
  • newauthor.php
  • joketables.php
  • jokes.php
  • jokelist.php
  • editjoke.php
  • editcat.php,
  • editauthor.php
  • deletejoke.php
  • deletecat.php,
  • deleteauthor.php
  • cats.php
  • authors.php

Before you can begin to play with these files and see how they work with your database, you need to be sure that the database tables have been created as the book instructs, then, before you can get any data from the database, something needs to be put into it.

You indicated in your post that you were working with the file “jokelist.php”. That file isn’t the one that adds data to the database. The correct file is “newjoke.php”.

The project collects data from HTML Forms, of which you did not show within your post. The fields on the Forms, of course, are all named. You need to put the values of these fields into PHP Strings by using, in this case, the $_post method; $joketext, $aid, and $cats all need values.

To close this post, don’t be in such a hurry to get through this chapter. It is very confusing in some sections. It took me a few tries to get it right. If you need more help, PM me.

Just alter your database table field ‘joketext’ type from INT to VARCHAR or TEXT (if long texts are to be stored) and insert then it will work as expected I guess.

So thank you very much and your answer is a great and it works