Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

failing sql query.

Status
Not open for further replies.

max2474

Programmer
May 10, 2012
40
GB
First, please see here as I originally thought this to be a php issue.

Am almost at the pulling hair out stage...lol. I have 5 dynamically chosen tables to write to depending on user input.

If plan1 is chosen, all info is updated in the database perfectly. If any other plan number is chosen the query fails.

To try and find the error, I have changed the query to this :

PHP:
		$test=	mysql_query("UPDATE $newplan SET $lnt = '$ltu', $lnn = '$lnu', plantot = '$ptu', plannew = '$pnu'
			WHERE userid = '$w' LIMIT 1");
		echo "newplan is ".$newplan.". lnt is ".$lnt.". ltu is ".$ltu.". lnn is ".$lnn.". lnu is ".$lnu.". plantot is ".plantot.". ptu is ".$ptu.". plannew is ".$plannew.". pnu is ".$pnu.". w is ".$w;
echo "<br /> testt is ".$test."<br />";

so with the whole loop, we have this :

PHP:
	$newplan="plan".$_SESSION[plan];
	$g=1;
	while ($g <= 9)
	{
		$w=$_SESSION[refs][$g-1];
		$lnt="lvl".$g."tot";
		$lnn="lvl".$g."new";
		$ltu=($_SESSION[rlvltot][$g-1])+1;
		$lnu=($_SESSION[rlvlnew][$g-1])+1;
		$ptu=($_SESSION[rplantot][$g-1])+1;
		$pnu=($_SESSION[rplannew][$g-1])+1;
		$test=	mysql_query("UPDATE $newplan SET $lnt = '$ltu', $lnn = '$lnu', plantot = '$ptu', plannew = '$pnu'
			WHERE userid = '$w' LIMIT 1");
		echo "newplan is ".$newplan.". lnt is ".$lnt.". ltu is ".$ltu.". lnn is ".$lnn.". lnu is ".$lnu.". plantot is ".plantot.". ptu is ".$ptu.". plannew is ".$plannew.". pnu is ".$pnu.". w is ".$w;
echo "<br /> test is ".$test."<br />";



		$g++;
	}

comparing outputs - choosing plan1 gives :
output said:
newplan is plan1. lnt is lvl1tot. ltu is 8. lnn is lvl1new. lnu is 8. plantot is plantot. ptu is 8. plannew is . pnu is 8. w is 11
test is 1
newplan is plan1. lnt is lvl2tot. ltu is 8. lnn is lvl2new. lnu is 8. plantot is plantot. ptu is 8. plannew is . pnu is 8. w is 10
test is 1
newplan is plan1. lnt is lvl3tot. ltu is 8. lnn is lvl3new. lnu is 8. plantot is plantot. ptu is 8. plannew is . pnu is 8. w is 7
test is 1
etc
etc

and choosing plan2 gives:
output said:
newplan is plan2. lnt is lvl1tot. ltu is 3. lnn is lvl1new. lnu is 3. plantot is plantot. ptu is 1. plannew is . pnu is 3. w is 11
test is
newplan is plan2. lnt is lvl2tot. ltu is 3. lnn is lvl2new. lnu is 3. plantot is plantot. ptu is 1. plannew is . pnu is 3. w is 10
test is
newplan is plan2. lnt is lvl3tot. ltu is 3. lnn is lvl3new. lnu is 3. plantot is plantot. ptu is 1. plannew is . pnu is 3. w is 7
test is
etc
etc
giving no value to "test", assumably the failed write.
Please note, the differing values 3 and 8 are just different numbers to write to the table.

I can see no difference that would explain why plan1 works and plan2 etc fail.

Any tips would be greatly appreciated.
 
Got some help on the original thread which solved this. Many thanks for looking :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top