R8kit Posted October 25, 2011 Share Posted October 25, 2011 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. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 25, 2011 Share Posted October 25, 2011 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); Quote Link to comment Share on other sites More sharing options...
R8kit Posted October 25, 2011 Author Share Posted October 25, 2011 Thank you very much. I inserted more data in the database and the code is working now. Thanks again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.