Jump to content

Bug in PHP or Invalid Query?


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
Share on other sites

thanks, I will try that solution next.

I built this function:


function makeNum(){
		$q = mysql_query("SELECT id FROM games WHERE id = '$num'");
		$n = 1; //Starters.
		while($n != 0){
				$_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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.