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.

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.