I tried to import a table intro a database and MySQL give me the next error message:

"MySQL said:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''table_ro2'

INSERT INTO 'table_ro2' VALUES ('text nr. 1', 'text nr. 2', 'text' at line 1 "


content of my file what I want to import is:
"CREATE TABLE 'table_ro2'

INSERT INTO 'table_ro2' VALUES ('text nr. 1', 'text nr. 2', 'text nr. 3', 'text nr. 4');"

What is the problem?????

Recommended Answers

All 16 Replies

You should use back ticks (`) instead of single quotes around table names e.g.

INSERT INTO `table_ro2` VALUES ('text nr. 1', 'text nr. 2', 'text nr. 3', 'text nr. 4');

Note the difference to back tick (`) and single quote (')

You should use back ticks (`) instead of single quotes around table names e.g.

INSERT INTO `table_ro2` VALUES ('text nr. 1', 'text nr. 2', 'text nr. 3', 'text nr. 4');

Note the difference to back tick (`) and single quote (')

thanks for answer, I tried and also don't work!

You have to separate statements by a semicolon.
Please show the file which does not upload.

You have to separate statements by a semicolon.
Please show the file which does not upload.

this are the file (this is all content of my file) :

CREATE TABLE `table_ro2`
INSERT INTO `table_ro2` VALUES ('text nr. 1', 'text nr. 2', 'text nr. 3', 'text nr. 4');

You have to separate statements by a semicolon.

I tried and also doesn't work.

Your CREATE TABLE syntax is wrong. The table definition is missing.

Your CREATE TABLE syntax is wrong. The table definition is missing.

please, can you show me how need to be my file? :)

Study the CREATE TABLE syntax here: http://dev.mysql.com/doc/refman/5.1/en/create-table.html
Which fields do you want your table to have?

I want from this MySQL database to take intro php a random text/sentence from these text for example(hello word or how are you or what do you do).

for this I need to import this file intro my database:

CREATE TABLE `table_ro2`
INSERT INTO `table_ro2` VALUES ('hello word', 'how are you?', 'what do you do?', 'text nr. 4');

and with this script in php every time when i will make refresh (F5) on my page, to from my table/database to take a random text/sentence.

this is code from php:

<?php

$mysql_host = 'localhost';
$mysql_db = 'database123';
$mysql_user = 'root';
$mysql_pass = 'password123';

mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($mysql_db);

$sel = SELECT * FROM table_ro2 ORDER BY RAND(), limit 1; 
printf($sel);

?>

what I make wrong?

Your table definition needs at least one field. And in the insert query each record (row) has to be in its own brackets. Try this:

CREATE TABLE `table_ro2` (theText text);
INSERT INTO `table_ro2` VALUES ('hello word'), ('how are you?'), ('what do you do?'), ('text nr. 4');

Your table definition needs at least one field. And in the insert query each record (row) has to be in its own brackets. Try this:

CREATE TABLE `table_ro2` (theText text);
INSERT INTO `table_ro2` VALUES ('hello word'), ('how are you?'), ('what do you do?'), ('text nr. 4');

Thanks, finally I imported this table in my database :).
Now, I have a problem with my php script (I think), because php don't want to "print" on my screen a random text/sentence from my table/database.

<?php
 $mysql_host = 'localhost';
$mysql_db = 'database123';
$mysql_user = 'root';
$mysql_pass = 'password123';
 
mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($mysql_db);
 
$result_db = mysql_query("SELECT * FROM table_ro2 ORDER BY RAND(), LIMIT 1");
echo $result_db;
?>

What can be the problem in this case?

Check the PHP manual how to print query results. And MySQL query should be

SELECT * FROM table_ro2 ORDER BY RAND() LIMIT 1

Check the PHP manual how to print query results. And MySQL query should be

SELECT * FROM table_ro2 ORDER BY RAND() LIMIT 1

I looked in manual and also don't work,

my php script is the next:

<?php
 $mysql_host = 'localhost';
$mysql_db = 'database123';
$mysql_user = 'root';
$mysql_pass = 'password123';
 
mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($mysql_db);
 
$query="SELECT * FROM table_ro2 ORDER BY RAND() LIMIT 1";
$result=mysql_query($query);
echo $result;
?>

and my php code show me the next result:
Resource id #4

why my phph code don't display from my database a random text??

Try this and see the PHP manual again for mysql_fetch_assoc()

<?php
 $mysql_host = 'localhost';
$mysql_db = 'database123';
$mysql_user = 'root';
$mysql_pass = 'password123';
 
mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($mysql_db);
 
$query="SELECT * FROM table_ro2 ORDER BY RAND() LIMIT 1";
$result=mysql_query($query);
$row = mysql_fetch_assoc($result);
echo $row["column1"]."<br>"; // replace column1 with real column name you want to print
echo $row["column2"]; // replace column2 with real column name you want to print
?>

Try this and see the PHP manual again for mysql_fetch_assoc()

<?php
 $mysql_host = 'localhost';
$mysql_db = 'database123';
$mysql_user = 'root';
$mysql_pass = 'password123';
 
mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($mysql_db);
 
$query="SELECT * FROM table_ro2 ORDER BY RAND() LIMIT 1";
$result=mysql_query($query);
$row = mysql_fetch_assoc($result);
echo $row["column1"]."<br>"; // replace column1 with real column name you want to print
echo $row["column2"]; // replace column2 with real column name you want to print
?>

thanks a lot!! now works, I just changed the "column1" with name of my field "theText".

You are welcome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.