Closed Thread Icon

Topic awaiting preservation: What's wrong with this query? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12256" title="Pages that link to Topic awaiting preservation: What&amp;#039;s wrong with this query? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: What&#039;s wrong with this query? <span class="small">(Page 1 of 1)</span>\

 
Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 06-10-2002 19:45
code:
$query_showPosts = "SELECT jugador FROM parados where jugador != '".$remote_userName."' limit 1";
$result_showPosts = mysql_query($query_showPosts, $link);
$num_posts = mysql_num_rows($result_showPosts);
while ($row = mysql_fetch_array($result_showPosts)) {
$query_juegos = "INSERT INTO match (jugador1,jugador2) VALUES ('".$row[0]."','".$remote_userName."')";
if (mysql_query($query_juegos, $link)) {
echo "<br>".$row[0]." vs ".$remote_userName."\n";
}
else{
echo "huh?";
}

}



It just returns the Huh? does not insert into the database or anything....

The conditions in the database are given for it to make the query.....

[This message has been edited by WarMage (edited 06-11-2002).]

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-11-2002 00:55

$query_showPosts = "SELECT jugador FROM parados WHERE jugador != $remote_userName LIMIT 1";

I don't see why you would need to use single quotes around your data.

Maybe you should, maybe you shouldn't.

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 06-11-2002 01:37

I already tried with quotes and without them...
weather with or without them doesn't work....

A sig should be here.....
But is not.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-11-2002 01:45

Well, let me do some more figuring. If you wouldn't mind posting the format of your DB as well I wouldn't mind using that as a jumping point.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-11-2002 01:59

I wanted to throw this code togeather for starters. Let you know what I am doing as I go through this. Maybe give you my train of thought.

The newer way that MySQL handles things is to keep the $db connection in memory, therefore you don't need to reference it every time you try to query it. Save a bit of code and a lot of confusion.

code:
<?php
$database = "your db";


$connection = mysql_connect("localhost","username","password") or die ("Could not connect.");
$db = mysql_select_db($database,$connection) or die ("Could not select Database.");


$query_showPosts = "SELECT jugador FROM parados where jugador != '" . $remote_userName . "' LIMIT 1";


$result_showPosts = mysql_query($query_showPosts) or die ("Could not query.");
$num_posts = mysql_num_rows($result_showPosts);


/* Don't know why you were needing a while loop if you are only affecting one row */
$row = mysql_fetch_row($result_showPosts));


$query_juegos = "INSERT INTO match (jugador1, jugador2) VALUES ('" . $row[0] . "','" . $remote_userName . "')";
$result_juegos = mysql_query($query_juegos) or die ("Could not query");
if ($result_juegos)
echo "<br>" . $row[0] . " vs " . $remote_userName . "\n";
else
echo "huh?";

?>



You might want to make note:

The query is FALSE if a column to be selected does not exist.
The query is FALSE if you don't have permission to access the table.

and from the developers mouth:

quote:
Only for SELECT,SHOW,EXPLAIN or DESCRIBE statements mysql_query() returns a resource identifier
or FALSE if the query was not executed correctly. For other type of SQL statements, mysql_query() returns
TRUE on success and FALSE on error. A non-FALSE return value means that the query was legal and could be
executed by the server. It does not indicate anything about the number of rows affected or returned. It is perfectly
possible for a query to succeed but affect no rows or return no rows.





[This message has been edited by WarMage (edited 06-11-2002).]

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 06-11-2002 10:02

Hey WarMage!
Thanks for your help, let's see:

That script that you gave me was very useful to detect where is the problem since each step with the database is monitored in some way, but the problem is still there:
Could not query

So, as I am a smart guy ( ), I deduced that the problem is on the 'select' query:
$query_showPosts = "SELECT * FROM parados where jugador != '" . $remote_userName . "' limit 1 ";

Right?
Well, my database format: (or just the 2 tables affecting)

Table Parados:
jugador

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 06-11-2002 10:06

Oh!! silly again!!
I have the 'insert' query, the problem could be there too!!
I'm checking.....

--------------------------------------
Edit:
Yes, the problem is in the insert query, but still dunno what is it:

$query_juegos = "INSERT INTO match (jugador1, jugador2) VALUES ('" . $row[0] . "','" . $remote_userName . "')";

[This message has been edited by Wakkos (edited 06-11-2002).]

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 06-11-2002 12:46

I fact, if I make this:

code:
$var = "WarMage";
$var2 = "Wakkos";
$database = "board";
$connection = mysql_connect("host","user","pass") or die ("Could not connect.");
$db = mysql_select_db($database,$connection) or die ("Could not select Database.");
$query_juegos = "INSERT INTO match (jugador1, jugador2) VALUE('" . $var . "','" . $var2 . "')";
$result_juegos = mysql_query($query_juegos) or die ("Could not query insert");
if ($result_juegos) {
echo "<br>".$var." vs ".$var2."\n";
}
else{
echo "Huh?";
}



It returns the ("Could not query insert"); message............

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 06-11-2002 14:59

I'm using MySQL to manage my database, and for some strage reason the table MATCH was damaged, I cannot even delete it, but I created another table and everything is OK now!

Thanks for helping!!!!!

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-11-2002 18:20

No problem, I am glad it worked out for you in the end.

« BackwardsOnwards »

Show Forum Drop Down Menu