FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


mysql syntax problem





alalex
hi, i have a mysql code that yesterday was working perfectly, but today it says that its wrong! here is the code:
Code:
$conexion = mysql_connect($host,$user,$pass);
                  
if(!$conexion){
echo '<p style="font-size:large;">Conexión fallida</p>';
}else{
mysql_select_db('test');
$query = 'SELECT id, titulo, contenido, autor, fecha FROM avisos WHERE 1=id';
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
$titulo = $row['titulo'];
$contenido = $row['contenido'];
$autor = $row['autor'];
}
}
mysql_close();

and the error:
Code:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/alalex/domains/webot.frih.net/public_html/pumarin/avisos.php on line 123

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/alalex/domains/webot.frih.net/public_html/pumarin/avisos.php on line 128

Sad
ncwdavid
alalex wrote:
hi, i have a mysql code that yesterday was working perfectly, but today it says that its wrong! here is the code:
Code:

$query = 'SELECT id, titulo, contenido, autor, fecha FROM avisos WHERE 1=id';

Sad

Try and use this for the query:
Code:

$query = "SELECT id, titulo, contenido, autor, fecha FROM avisos WHERE 1='id'";

Plus check to see if everything is spelled correctly.
alalex
it keeps on saying:
Code:
mysql_num_rows: supplied argument is not a valid MySQL result resource
hexkid
Code:
$result = mysql_query($query);
### add these lines after the mysql_query() call
if (!$result) {
  echo '<p style="font-size:large;">Query fallida.</p>';
  echo '<p style="font-size:large;">Query: <tt>', $query, '</tt></p>';
  echo '<p style="font-size:large;">Razón: <tt>', mysql_error(), '</tt></p>';
}
alalex
it says that the table doesnt exist?? Sad Question
i will check with phpMyAdmin, but i created it two days ago...

I just checked, and there is no table! Exclamation Shocked
well, then i guess its all done.
and by the way, do you know how can i check for the number of rows in a table?
mathiaus
alalex wrote:
I just checked, and there is no table! Exclamation Shocked

The database 'test' is not a normal database like your others. It is shared all other users and is automatically reset at certain intervals (days or hours or something). Create a new database in Direct Admin and use that instead.
ncwdavid
alalex wrote:

and by the way, do you know how can i check for the number of rows in a table?


Code:

$sql = "SELECT * FROM TABLENAME";
$resource = mysql_query($sql):
$num = mysql_num_rows($resource);

//Then to see how many there is:
echo $num;
hexkid
ncwdavid wrote:
Code:
$sql = "SELECT * FROM TABLENAME";
$resource = mysql_query($sql):
$num = mysql_num_rows($resource);

//Then to see how many there is:
echo $num;


That's like buying the entire annual production of a computer manufacturing company when all you want is a mouse.
ncwdavid
hexkid wrote:
ncwdavid wrote:
Code:
$sql = "SELECT * FROM TABLENAME";
$resource = mysql_query($sql):
$num = mysql_num_rows($resource);

//Then to see how many there is:
echo $num;


That's like buying the entire annual production of a computer manufacturing company when all you want is a mouse.


Yeah but it works. I know you can do: Count(*) but i just thought of the other way then.
alalex
ok, i was using mysql_num_rows before, but it said it wasnt valid! it was because there was no mysql table! i think i have a problem in my phpMyAdmin because everytime i create a table it dissapears in about a day Sad
alalex
ooo, i know why it was! it was because i was using the database test! and it got reset every day! Confused thanks anyways Very Happy
garionw
alalex wrote:
ooo, i know why it was! it was because i was using the database test! and it got reset every day! Confused thanks anyways Very Happy


mathiaus wrote:
alalex wrote:
I just checked, and there is no table! Exclamation Shocked

The database 'test' is not a normal database like your others. It is shared all other users and is automatically reset at certain intervals (days or hours or something). Create a new database in Direct Admin and use that instead.
Related topics
have problem on my sql
Mysql database problem
MySQL
phpbb install 'critical error'
PHP/MySQL: Apostrophe problem
SquirrelUpload - Skrypt uploadu zdjec.
insert data to mySQL database problem
Delete data from MySQL database problem!!
mysql syntax error I can't find why
Error 127 from PHPbb
a site where i can learn mysql syntax
help me please with my problem
MySQL privileges Problem
Trying to Understand MySQL Syntax
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.