Lamez Posted March 5, 2008 Share Posted March 5, 2008 Alright I have a question, when I put to update querys together, only the points update, but if I move the other query, it only updates. Why? Here is the code: This one adds a 1 to the r1 field, but does not update points. if ($a1 != ("emp")){ if ($ck['r1'] = ("0")){ if ($a1 = ($pick['a1'])){ $total = $value + $total; $rnd1 = $value + $rnd1; mysql_query("UPDATE `userpoints` SET `total`='$total', `rnd1`='$rnd1' WHERE `username`='$user'")or die(mysql_error()); } } mysql_query("UPDATE `check1` SET `r1`='1' WHERE `id`='1'"); } This one updates the userpoints, but does not update a 1 into the r1 field if ($a1 != ("emp")){ if ($ck['r1'] = ("0")){ if ($a1 = ($pick['a1'])){ $total = $value + $total; $rnd1 = $value + $rnd1; mysql_query("UPDATE `userpoints` SET `total`='$total', `rnd1`='$rnd1' WHERE `username`='$user'")or die(mysql_error()); mysql_query("UPDATE `check1` SET `r1`='1' WHERE `id`='1'"); } } } How do I get them it to update both tables? Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted March 5, 2008 Share Posted March 5, 2008 try if ($a1 != ("emp")){ if ($ck['r1'] = ("0")){ if ($a1 = ($pick['a1'])){ $total = $value + $total; $rnd1 = $value + $rnd1; mysql_query("UPDATE `userpoints` SET `total`='$total', `rnd1`='$rnd1' WHERE `username`='$user'")or die(mysql_error()); mysql_query("UPDATE `check1` SET `r1`='1' WHERE `id`='1'")or die(mysql_error()); } } } Quote Link to comment Share on other sites More sharing options...
Lamez Posted March 5, 2008 Author Share Posted March 5, 2008 what did you change? It looks the same as my code post before Quote Link to comment Share on other sites More sharing options...
peranha Posted March 5, 2008 Share Posted March 5, 2008 Added the die statement at the end of the 2nd query to see if there is an error in that one. Quote Link to comment Share on other sites More sharing options...
Lamez Posted March 5, 2008 Author Share Posted March 5, 2008 nothing has returned, but still nothing in the check1 table Quote Link to comment Share on other sites More sharing options...
black_box Posted March 5, 2008 Share Posted March 5, 2008 Could u plz give the structure of two tables with PK and FK mentioned if any. Quote Link to comment Share on other sites More sharing options...
Lamez Posted March 5, 2008 Author Share Posted March 5, 2008 check1 (table) r1-r32 userpoints (table) rnd1, rnd2, rnd3, rnd4, rnd5, champ Quote Link to comment Share on other sites More sharing options...
Lamez Posted March 5, 2008 Author Share Posted March 5, 2008 oh wait they are like this: check1 (table) r1-r32 userpoints (table) total, rnd1, rnd2, rnd3, rnd4, rnd5, rnd6 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 5, 2008 Share Posted March 5, 2008 This if statement is incorrect: <?php if ($a1 = ($pick['a1'])) ?> since it uses the assignment operator "=", not the comparison operator "==". Try <?php if ($a1 == ($pick['a1'])) ?> Ken Quote Link to comment Share on other sites More sharing options...
Lamez Posted March 5, 2008 Author Share Posted March 5, 2008 wow I did not know that, would it be incorrect to use "===" Quote Link to comment Share on other sites More sharing options...
teng84 Posted March 6, 2008 Share Posted March 6, 2008 using === means identical meaning it should be the same datatype and value eg.. 1===1 true 1==='1' false 1=='1' true true === true true true === 'true' false true =='true' true Quote Link to comment Share on other sites More sharing options...
Lamez Posted March 6, 2008 Author Share Posted March 6, 2008 Thank you very much for clarifying that for me. I have decided to go a different route on the script. This way I have planed it out should work. Quote Link to comment Share on other sites More sharing options...
Lamez Posted March 6, 2008 Author Share Posted March 6, 2008 so could I do this: <?php $value = "cat"; if ($value !== ("dog")){ echo "animal is a cat"; }else{ echo "animal is a dog"; } ?> The output of the code above it "animal is a cat" (w/o " of course) Quote Link to comment Share on other sites More sharing options...
Lamez Posted March 6, 2008 Author Share Posted March 6, 2008 omg, after weeks of frustration, I have finally figured out a solution. if anyone is wondering, here is my full code: <?php include ("../../../style/include/session.php"); include ("../../../style/include/cons/head_3.php"); if($session->isAdmin()){ $a1 = $_POST['a1']; $a2 = $_POST['a8']; $a3 = $_POST['a5']; $a4 = $_POST['a4']; $a5 = $_POST['a6']; $a6 = $_POST['a3']; $a7 = $_POST['a7']; $a8 = $_POST['a2']; $b9 = $_POST['b1']; $b10 = $_POST['b8']; $b11 = $_POST['b5']; $b12 = $_POST['b4']; $b13 = $_POST['b6']; $b14 = $_POST['b3']; $b15 = $_POST['b7']; $b16 = $_POST['b2']; $c17 = $_POST['c1']; $c18 = $_POST['c8']; $c19 = $_POST['c5']; $c20 = $_POST['c4']; $c21 = $_POST['c6']; $c22 = $_POST['c3']; $c23 = $_POST['c7']; $c24 = $_POST['c2']; $d25 = $_POST['d1']; $d26 = $_POST['d8']; $d27 = $_POST['d5']; $d28 = $_POST['d4']; $d29 = $_POST['d6']; $d30 = $_POST['d3']; $d31 = $_POST['d7']; $d32 = $_POST['d2']; $result=mysql_query('SELECT * FROM userpoints'); while($row = mysql_fetch_array($result)){ $user = $row['username']; /*Pull Winners for Round 1*/ $q = mysql_query("Select * from `rnd1_win`"); $win=mysql_fetch_array($q); /*Pull User Picks for Round 1*/ $q = mysql_query("Select * from `rnd1` where `username` = '$user'"); $pick=mysql_fetch_array($q); /*Pull Point Values for Round 1*/ $q = mysql_query("Select rnd1 from `points`"); $point=mysql_fetch_array($q); $value = $point['rnd1']; /*Pull User Points for Round 1*/ $q = mysql_query("Select `username`, `total`, `rnd1` from `userpoints` Where `username` = '$user'"); $usrpoint=mysql_fetch_array($q); $total = $usrpoint['total']; $rnd1 = $usrpoint['rnd1']; #A's if ($a1 !== ("emp")){ if ($win['1'] == ("emp")){ if ($a1 == ($pick['a1'])){ $total = $value + $total; $rnd1 = $value + $rnd1; mysql_query("UPDATE `userpoints` SET `total`='$total', `rnd1`='$rnd1' WHERE `username`='$user'")or die(mysql_error()); } } } } $q = "UPDATE `rnd1_win` SET `1` = '$a1', `2` = '$a2', `3` = '$a3', `4` = '$a4', `5` = '$a5', `6` = '$a6', `7` = '$a7', `8` = '$a8', `9` = '$b9', `10` = '$b10', `11` = '$b11', `12` = '$b12', `13` = '$b13', `14` = '$b14', `15` = '$b15', `16` = '$b16', `17` = '$c17', `18` = '$c18', `19` = '$c19', `20` = '$c20', `21` = '$c21', `22` = '$c22', `23` = '$c23', `24` = '$c24', `25` = '$d25', `26` = '$d26', `27` = '$d27', `28` = '$d28', `29` = '$d29', `30` = '$d30', `31` = '$d31', `32` = '$d32' WHERE `id` = '1'"; mysql_query($q) or die(mysql_error()); print '<div class="box"><h2>Winners Updated</h2>'; print '<p>Winners Updated for Round 2<br><br>'; print '<a href="slcwin_1.php">Round 2</a></p>'; print '</div>'; }else{ header("Location: ../../../index.php"); } include ("../../../style/include/cons/foot.php"); ?> It works how I want it to Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.