I'm currently learning how to insert data in MySQL database and fetching data from MySQL database.
I have learned how to insert, but displaying the result from MySQL is giving me some problems.
This is the command to create the tables. I'm confused with the id structure and I guess thats the main root of the error I'm getting at the output.
Now the php code to fetch the data from the mysql db is this
and whenever I go like preview.php?id=1 or ..?id=2 to ..?id=4, the results are as I wanted. But whenever I put preview.php?id=5 or preview.php?id=6 I get this error
Also, this is the exact data in my mysql database displayed by a PHP script.
Remember I just have 5 rows filled. The row with ID 1 is deleted by me as a part testing the script. I don't think that it'd be a problem.
I have learned how to insert, but displaying the result from MySQL is giving me some problems.
This is the command to create the tables. I'm confused with the id structure and I guess thats the main root of the error I'm getting at the output.
PHP:
$query="CREATE TABLE post (id int NOT NULL auto_increment,title text(300) NOT NULL,cover text NOT NULL,info text NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))";
Now the php code to fetch the data from the mysql db is this
PHP:
$db = mysql_connect($hostname,$username,$password);
if(!$db){
echo 'Failed to connect to database. Check your info';
}
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM post";
/*$result = mysql_query($query);*/
$result = mysql_query($query) or die(mysql_error());
mysql_close();
$id = $_GET['id'];
$title=mysql_result($result,$id,"title");
echo 'ID='.$id.' - Title='.$title.'';
and whenever I go like preview.php?id=1 or ..?id=2 to ..?id=4, the results are as I wanted. But whenever I put preview.php?id=5 or preview.php?id=6 I get this error
PHP:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 5 on MySQL result index 5 in C:\xampp\htdocs\post\preview.php on line 87
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 5 on MySQL result index 5 in C:\xampp\htdocs\post\preview.php on line 88
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 5 on MySQL result index 5 in C:\xampp\htdocs\post\preview.php on line 89
ID=5Title=
Also, this is the exact data in my mysql database displayed by a PHP script.
Code:
ID Title Delete
2 This Is Title Delete Preview
3 This Is Title Delete Preview
4 This Is Title Delete Preview
5 This Is Title Delete Preview
6 This Is Title Delete Preview
Remember I just have 5 rows filled. The row with ID 1 is deleted by me as a part testing the script. I don't think that it'd be a problem.