Jump to content

Requesting help with inserting and reading TEXT data type in MySQL


R8kit

Recommended Posts

Hello everyone,

 

I am new to MySQL and I am trying to insert the data type TEXT into the database but it isn't working out for me.

 

I created an SQL file with the following code:

 

CREATE DATABASE books;

USE books;

CREATE TABLE authors (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR (255),
info TEXT
);

INSERT INTO authors (name, info) values('Vivek', '
asdfkljasdkl;fjasd
fasdl;kfjaskl;dfjasd
fasdkl;fjasd;lkfjasdf
asdl;fkajsd;lfkjasd;fsd
fkl;asdjfaskl;djfsd
sdakl;jasdl;kfjasdkl;fjasd
asdkl;fjasdl;fkjasl;kfj
');

 

I created an PHP page with the following code:

<?php
mysql_connect("localhost","root","passwd");

mysql_select_db("books");

$result=mysql_query("SELECT * FROM authors");

$row=mysql_fetch_array($result);

while ($row=mysql_fetch_array($result)) {
echo 'Name: '.$row{'name'}.'<br />';
echo 'Info: '.$row{'info'}.'<br />';
}
?>

 

Can anyone help me insert and read the TEXT data type the proper way?

 

Thanks in advance.

Each call to mysql_fetch_array() moves the data pointer to the next record. Since you (presumably) have only one record in the database, the first call to mysql_fetch_array() discards the data from the only record returned.

 

Remove this line, and you should have a result echoed.

$row=mysql_fetch_array($result);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.