Forum Moderators: coopster

Message Too Old, No Replies

insert data problem

         

xbl01234

7:17 am on Aug 30, 2008 (gmt 0)

10+ Year Member



Hi:
i am trying to insert data into database, but it give me the following massage:

Error: No database selected

Could you help me, please.

i created a table


create table test(content varchar(1000),
id smallint auto_increment,
primary key(id))

and i have inserted 1 row data into the table by hand without problem. but i got prolem with inserting by the following code.

my code:


<?php

$con=mysql_connect("localhost", "#*$!", "#*$!x") or die(mysql_error());
mysql_select_db("#*$!", $con);

$mysql="INSERT INTO test (content) VALUES (\"hkhk\")";
$result=mysql_query($mysql, $con);

if(!$result)
die('Error: ' . mysql_error());

else
echo "data inserted";

?>

coopster

3:10 pm on Aug 30, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Add the "or die()" context to your mysql_select_db() statement during testing and you should be told why you are not able to select the database you intend.

xbl01234

10:34 pm on Aug 30, 2008 (gmt 0)

10+ Year Member



yes, you are right.problem are from there.