0

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?????

3
Contributors
16
Replies
18
Views
6 Years
Discussion Span
Last Post by mwasif
0

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 (')

0

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!

0

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

You have to separate statements by a semicolon.

I tried and also doesn't work.

0

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

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

0

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?

0

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

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?

0

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??

0

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
?>
0

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".

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.