error in MySQL

Status
Not open for further replies.

saiman

New Member
Messages
10
Reaction score
0
Points
0
Good day for all, i have some question about MySQL database..

i have code
Code:
<? include "connect.php";?>
<?

 mysql_select_db ("$my_database");
   
$string=$_POST['string'];
if (!empty($string))
{

mysql_query("INSERT INTO test(phrase) VALUE('$string')");
}
?>             
                       
<?
$query = "SELECT phrase FROM test";
$result = mysql_query($query);
$i=0;
while ($row = mysql_fetch_array($result)) {
   $arr[$i]=$row['phrase'];
$i++;
}
$rand=rand(0,$i-1);
?>
<div align=center><img src="bigheart.gif"></div>
  <div style="position: absolute; top: 299px; left: 145px;right:145px; font-family: Arial; font-style: normal; font-variant: normal; font-weight: bold; font-size: 11px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none; color: rgb(0, 0, 0);"><?php echo "$arr[$rand]";?></div>
in "connect.php" i choose my host,pass,login and database...
$mysql_host="mysql-cossacks.x10hosting.com";

all right,but i have ERROR "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in "... i tested this code in local machine and it work :(

Somebody help me plz(
 

Gouri

Community Paragon
Community Support
Messages
4,565
Reaction score
245
Points
63
The mysql host should be localhost
$mysql_host="localhost";

the database name should be like cpanelusername_databasename
the database username should be like cpanelusername_databaseusername
 
Last edited:

priyaa161

New Member
Messages
553
Reaction score
24
Points
0
try to use "localhost" in place of "mysql-cossacks.x10hosting.com".
 

saiman

New Member
Messages
10
Reaction score
0
Points
0
i corrected connect.php
Code:
$mysql_host="localhost";
$mysql_login="saiman_root";
$mysql_password="************";
$my_database="saiman_test";

 $link = mysql_connect("$mysql_host", "$mysql_login", "$mysql_password")
   or die ("Could not connect to MySQL");
but all the same i see error =(
 

vishal

-::-X10 Guru-::-
Community Support
Messages
5,255
Reaction score
192
Points
63
i corrected connect.php
Code:
$mysql_host="localhost";
$mysql_login="saiman_root";
$mysql_password="************";
$my_database="saiman_test";

 $link = mysql_connect("$mysql_host", "$mysql_login", "$mysql_password")
   or die ("Could not connect to MySQL");
but all the same i see error =(

Check your database name and fields .Whether the character case are same or not.
 

Gouri

Community Paragon
Community Support
Messages
4,565
Reaction score
245
Points
63
Hi saiman,

change the query url to this so we can know where exactly the error is.
$result = mysql_query($query) or exit(mysql_error());
 

saiman

New Member
Messages
10
Reaction score
0
Points
0
Hi saiman,

change the query url to this so we can know where exactly the error is.

ohh,i see error No database selected
it's mean what i selected incorrect name database...
why i can't come into phpmyadmin?(
 

priyaa161

New Member
Messages
553
Reaction score
24
Points
0
ohh,i see error No database selected
it's mean what i selected incorrect name database...
why i can't come into phpmyadmin?(

You have not selected any of the database. You need to add this line:

Code:
mysql_select_db($dbname);
 

Gouri

Community Paragon
Community Support
Messages
4,565
Reaction score
245
Points
63
You have not selected any of the database. You need to add this line:

Code:
mysql_select_db($dbname);

He used but he has to keep it with in the connect.php

@ priyaa161 check the first post code.
 
Last edited:

saiman

New Member
Messages
10
Reaction score
0
Points
0
ohh..i have new error :)
Code:
<?
$dbname="saiman_test";
 mysql_select_db ("$dbname") or exit(mysql_error());   //Access denied for user 'saiman_root'@'74.63.233.5' to database 'saiman_test'
   
$string=$_POST['string'];
if (!empty($string))
{

mysql_query("INSERT INTO test(phrase) VALUE('$string')");
}
?>
What does it mean?
 

Anna

I am just me
Staff member
Messages
11,752
Reaction score
582
Points
113
In cPanel, under mysql database, you need to assign the user to the database and give it all available privileges.
 
Status
Not open for further replies.
Top