Jump to content

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

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.

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