Jump to content

Bug in PHP or Invalid Query?


Lamez

Recommended Posts

I am making some changes to an existing website. I did not write the code, the code is horrid. Any who, I have this query:

 

$query = "INSERT INTO `games` (sport,hsid,homescore,vsid,visitorscore,type,`where`,location,date,time,found) VALUES ('$sport','$hq[id]','$homescore','$vq[id]','$visitorscore','$type','Here','$location','$date','$time','1')";
	mysql_query($query) or die(mysql_error());

 

It looks very odd to me, it has a WHERE and a HERE, why? Why not use a update query? Unless this does not update. I am not sure.

 

However, the ID that is inserted is this: 2147483647 (the highest prime number known so far: http://en.wikipedia.org/wiki/2147483647)

 

I am thinking it is this very odd insert query, if not I must dig a little deeper. Any Ideas?

 

Oops: I had a brain fart, the where is a column in the DB, and the here is the value! Man, I am dumb. Does any one have any idea why I get this as the ID?

Link to comment
https://forums.phpfreaks.com/topic/188352-bug-in-php-or-invalid-query/
Share on other sites

thanks, I will try that solution next.

I built this function:

 

<?php
function makeNum(){
		$q = mysql_query("SELECT id FROM games WHERE id = '$num'");
		$n = 1; //Starters.
		while($n != 0){
			if(!isset($_SESSION['dbNum'])){
				$_SESSION['dbNum'] = mysql_num_rows(mysql_query("SELECT id FROM games"));
			}
			$num = rand($_SESSION['dbNum'] , 2147483647); 
			$n = mysql_num_rows($q);
		}
		return $num;
	}
	echo makeNum();
?>

 

I think it might work, what do you think?

Is the ID current used in other database records ?

if it is then an update could be a pain, but i would probably create a function to run once to clean up the data, rather than a function to attempt to get around it, as it could cause problems later will affect performance from the start

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.