Jump to content

Help: Wrong Calling


Yugiohwiz

Recommended Posts

ok I have a script that calls ids. It calls the right ids but the wrong info.I have id1 and id2.I click the link for id1 and I get id2s info. I click id2 and I get id2s info. I type in id3 which does not exist and I get id2s info.

// edits challengesfunction editChallenges($user) {global $bordercolor1, $tablebg1, $submit, $cid, $decline, $idc, $matchdate, $matchreplay, $mapused, $personwon, $deletethis;echo "<table align='center' border='1' cellspacing='0' cellpadding='0' bordercolor='$bordercolor1' width='500'><tr><td background='$tablebg1' class='main' align='center'><b>Edit Challenges</b></td></tr>";if($decline) {echo "<script language='javascript'>if(!confirm('Do really want to decline? You won\'t be able to edit this \\n\ challenge after you decline.')){window.location = 'console.php?p=EditChallenges&cid=$idc'}</script>";$query = "UPDATE challanges SET declined = '$user' WHERE id = '$idc'";$result = mysql_query($query)	or die(mysql_error());echo "<script language=\"Javascript\">alert(\"Success!\");window.location.href = 'console.php'; </script>";}if($submit) {$query = "UPDATE challanges SET date = '$matchdate', replay = '$matchreplay', map = '$mapused', winner = '$personwon' WHERE id = '$idc'";$result = mysql_query($query)	or die(mysql_error());echo "<script language=\"Javascript\">alert(\"Success!\");window.location.href = 'console.php'; </script>";}if($deletethis) {deleteStuff("challanges", $idc, 112188);}if($cid == "") {echo "<tr><td class='small'><br><blockquote>This is where you can edit your challenges.  If no challenges are shown that means no one has challenged you <b>OR</b> you have declined from a challange making you unable to now edit it.<br><br>";$query = "SELECT * FROM challanges WHERE (challanger = '$user' OR challanged = '$user') AND declined != '$user' ORDER BY id DESC";$result = mysql_query($query)	or die(mysql_error());while($row = mysql_fetch_array($result)) {extract($row);echo "<a href='console.php?p=EditChallenges&cid=$id'>$challanger vs. $challanged</a> - $date<br>";}echo "</blockquote></td></tr>";}if($cid != "") {$query = "SELECT * FROM challanges WHERE (challanger = '$user' OR challanged = '$user') AND declined != '$user' ORDER BY id DESC";$result = mysql_query($query)	or die(mysql_error());$row = mysql_fetch_array($result);extract($row);if($declined == "") { $wannadecline = "<center><input type='submit' name='decline' value='Decline' class='lp'></center><br>"; }if($declined != "") { $wannadelete = "<center><input type='submit' name='deletethis' value='Delete' class='lp'></center><br>"; }echo "<tr><td class='small'><form action='console.php?p=EditChallenges&cid=$id' method='post'><blockquote><br><center><b>$challanger</b> vs. <b>$challanged</b></center><br><br><input type='hidden' name='idc' value='$id'><b>Date:</b> <input type='text' name='matchdate' value='$date' class='textarea'><br><b>Map:</b> <input type='text' name='mapused' value='$map' class='textarea'><br><b>Winner:</b> <input type='text' name='personwon' value='$winner' class='textarea'><br><b>Replay:</b> <input type='text' name='matchreplay' value='$replay' class='textarea'><br><br>$wannadelete$wannadecline<center><input type='submit' name='submit' value='Submit' class='lp'></center></form></td></tr>";}echo "</table>";} // end editChallenges

Edited by Jonas
Link to comment
Share on other sites

What you have:

$query = "SELECT * FROM challanges WHERE (challanger = '$user' OR challanged = '$user') AND declined != '$user' ORDER BY id DESC";$result = mysql_query($query)or die(mysql_error());while($row = mysql_fetch_array($result)) {extract($row);echo "<a href='console.php?p=EditChallenges&cid=$id'>$challanger vs. $challanged</a> - $date<br>";}

When you make the query, and start the while loop, you are using mysql_fetch_array, which results in $row[0], $row[1], $row[2], etc. If you want $row['id'], $row['challanger'] (btw, it's "challenger") you need to use mysql_fetch_assoc instead. Try this:

$query = "SELECT * FROM challanges WHERE (challanger = '$user' OR challanged = '$user') AND declined != '$user' ORDER BY id DESC";$result = mysql_query($query)  or die(mysql_error());while($row = mysql_fetch_assoc($result)) {  extract($row);  echo "<a href=\"console.php?p=EditChallenges&cid={$id}\">{$challanger} vs. {$challanged}</a> - {$date}<br>";}

You can also do this:

$query = "SELECT * FROM challanges WHERE (challanger = '$user' OR challanged = '$user') AND declined != '$user' ORDER BY id DESC";$result = mysql_query($query)  or die(mysql_error());while($row = mysql_fetch_assoc($result)) {  echo "<a href=\"console.php?p=EditChallenges&cid={$row['id']}\">{$row['challanger']} vs. {$row['challanged']}</a> - {$row['date']}<br>";}

Link to comment
Share on other sites

I need more info, what happens when you try it? What do you mean it doesn't work.This is an easy problem, it's not complex. You want to click on a link with an ID in the querystring, and load some information about the ID on the next page. There 3 parts to this problem.The first one is the database. You need an ID column that is unique (I assume you have that set up correctly).The second one is the page to output all of the items, where you click. That's like this:

$result = mysql_query("SELECT id, name FROM items ORDER BY id ASC");while ($row = mysql_fetch_assoc($result)){  echo "<a href=\"page.php?id={$row['id']}\">{$row['name']}</a><br>";}

The third one is the lookup page that receives the ID and displays the item. That's like this:

$id = $_GET['id'];$row = mysql_fetch_assoc(mysql_query("SELECT * FROM items WHERE id={$id}"));echo $row['name'] . " " . $row['info'] . "<br>"; //etc

Your original problem stated that you always get the info for id2, meaning that you are either outputting id2 for all links, or you always set the id to id2 before you get the info.Post what code you are using now, and detail what the problem is (and any error messages) and I'll do what I can.

Link to comment
Share on other sites

Part of the HTML:

<tr><td class='small'><br><blockquote>This is where you can edit your challenges.  If no challenges are shown that means no one has challenged you <b>OR</b> you have declined from a challange making you unable to now edit it.<br><br><a href='console.php?p=EditChallenges&cid=13'>Webmaster vs. Yugiohwiz(HK)</a> - <br><a href='console.php?p=EditChallenges&cid=12'>Webmaster vs. Tradro(HK)</a> - <br></blockquote></td></tr></table>

Link to comment
Share on other sites

Well, the CID is unique. The code you originally gave doesn't get the CID though, it is using a global variable. Post the console.php or whichever section gets the CID, it might be overwritten by something else, or it might not be getting retrieved correctly in the first place.

Link to comment
Share on other sites

Everything to do with the challenges is below

// displays the Challenges pagefunction dispChallenge() {global $tablebg1, $bordercolor1;echo "<table align='center' border='1' cellspacing='0' cellpadding='0' bordercolor='black' width='600'><tr><td align='center'><img src='images/challenges.gif'></td></tr><tr><td class='small'><br><br>";$query = "SELECT * FROM challanges ORDER BY id DESC";$result = mysql_query($query)     or die("dispChallenge");while($row = mysql_fetch_array($result)){extract($row);$crank = getRank($challanger, "num");$crank1 = getRank($challanged, "num");$fullrank = getRank($challanger, "full");$fullrank1 = getRank($challanged, "full");$personwon = ""; $decliner = "";$showreplay = "";if($winner != "None") { $personwon = "{ <b>Winner:</b> $winner }"; }if($declined != "") { $decliner = "{ <font color='red'>DECLINED BY $declined</font> }"; }if($replay != "None") { $showreplay = "<a href='$replay'>VIEW REPLAY</a>"; }echo "<table align='center' width='575' border='0' cellspacing='0' cellpadding='0'><tr><td colspan='3' class='small'>    { <b>Date:</b> $date } { <b>Map:</b> $map } $personwon</td></tr><tr><td colspan='3'><hr width='550' color='$bordercolor1' size='1'></td></tr><tr><td><center><img src='images/bigranks/$crank.gif'></center></td><td rowspan='2'><center><h1>VS.</h1></center></td><td><center><img src='images/bigranks/$crank1.gif'></center></td></tr><tr><td align='center'><b><h3><a href='index.php?p=Profile&user=$challanger'>$challanger</a></h3></b></td><td align='center'><b><h3><a href='index.php?p=Profile&user=$challanged'>$challanged</a></h3></b></td></tr><tr><td colspan='3' class='main' align='center'><b>$showreplay</b></td></tr><tr><td colspan='3'><br><hr width='550' color='$bordercolor1' size='1'><br></td></tr></table>";}echo "</td></tr></table>";} // end of dispChallenge

// challenges a clan memberfunction challengeMember($user) {global $tablebg1, $bordercolor1, $submit, $member, $map, $challangedate, $datesmall;if($submit) {$query = "SELECT * FROM members WHERE username = '$user'";$result = mysql_query($query)     or die(mysql_error());$row = mysql_fetch_array($result);extract($row);$fullrank = turnRank($rank);$query = "INSERT INTO challanges (challanger, challanged, date, map) VALUES ('$user', '$member', '$challangedate', '$map')";$result = mysql_query($query)	or die("Error: challengeMember INSERT");$message = "$fullrank $user has challenged you to a 1v1.  The date of the challenge is $challangedate and the map being played on is $map.";$query = "INSERT INTO pm (sender, reciever, subject, date1, message) VALUES ('$fullrank $user', '$member', 'Challange', '$datesmall', '$message')";$result = mysql_query($query)	or die("Error: challangeMember");echo "<script language=\"Javascript\">alert(\"Success!\");window.location.href = 'console.php'; </script>";}$query = "SELECT * FROM members WHERE username != '$user' and disable = '0' ORDER BY rank DESC";$result = mysql_query($query)	or die(mysql_error());while($row = mysql_fetch_array($result)) {extract($row);$fullrank = turnRank($rank);$options .= "<option value='$username'>$fullrank $username</option>";}echo "<table align='center' border='1' cellspacing='0' cellpadding='0' bordercolor='$bordercolor1' width='500'><tr><td background='$tablebg1' class='main' align='center'><b>Challenge a Member</b></td></tr><tr><td class='small'><form action='console.php?p=Challenge' method='post'><blockquote><br>This is where you can challenge another clan member and prove to everyone that you own... or ######.  Fill out the form and they will be PM'd.  It will also be posted on the Challenge page of the site<br><br><b>Member:</b> <select name='member' class='textarea'>$options</select><br><b>Date:</b> <input type='text' name='challangedate' class='form'><br><b>Map:</b> <input type='text' name='map' class='form'><br><br><center><input type='submit' name='submit' value='Submit' class='lp'></center></form></blockquote></td></tr></table>";}  // end challangeMember

// edits challengesfunction editChallenges($user) {global $bordercolor1, $tablebg1, $submit, $cid, $decline, $idc, $matchdate, $matchreplay, $mapused, $personwon, $deletethis;echo "<table align='center' border='1' cellspacing='0' cellpadding='0' bordercolor='$bordercolor1' width='500'><tr><td background='$tablebg1' class='main' align='center'><b>Edit Challenges</b></td></tr>";if($decline) {echo "<script language='javascript'>if(!confirm('Do really want to decline? You won\'t be able to edit this \\n\ challenge after you decline.')){window.location = 'console.php?p=EditChallenges&cid=$idc'}</script>";$query = "UPDATE challanges SET declined = '$user' WHERE id = '$idc'";$result = mysql_query($query)	or die(mysql_error());echo "<script language=\"Javascript\">alert(\"Success!\");window.location.href = 'console.php'; </script>";}if($submit) {$query = "UPDATE challanges SET date = '$matchdate', replay = '$matchreplay', map = '$mapused', winner = '$personwon' WHERE id = '$idc'";$result = mysql_query($query)	or die(mysql_error());echo "<script language=\"Javascript\">alert(\"Success!\");window.location.href = 'console.php'; </script>";}if($deletethis) {deleteStuff("challanges", $idc, 112188);}if($cid == "") {echo "<tr><td class='small'><br><blockquote>This is where you can edit your challenges.  If no challenges are shown that means no one has challenged you <b>OR</b> you have declined from a challange making you unable to now edit it.<br><br>";$query = "SELECT * FROM challanges WHERE (challanger = '$user' OR challanged = '$user') AND declined != '$user' ORDER BY id DESC";$result = mysql_query($query)	or die(mysql_error());while($row = mysql_fetch_array($result)) {extract($row);echo "<a href='console.php?p=EditChallenges&cid=$id'>$challanger vs. $challanged</a> - $date<br>";}echo "</blockquote></td></tr>";}if($cid != "") {$query = "SELECT * FROM challanges WHERE (challanger = '$user' OR challanged = '$user') AND declined != '$user' ORDER BY id DESC";$result = mysql_query($query)	or die(mysql_error());$row = mysql_fetch_array($result);extract($row);if($declined == "") { $wannadecline = "<center><input type='submit' name='decline' value='Decline' class='lp'></center><br>"; }if($declined != "") { $wannadelete = "<center><input type='submit' name='deletethis' value='Delete' class='lp'></center><br>"; }echo "<tr><td class='small'><form action='console.php?p=EditChallenges&cid=$id' method='post'><blockquote><br><center><b>$challanger</b> vs. <b>$challanged</b></center><br><br><input type='hidden' name='idc' value='$id'><b>Date:</b> <input type='text' name='matchdate' value='$date' class='textarea'><br><b>Map:</b> <input type='text' name='mapused' value='$map' class='textarea'><br><b>Winner:</b> <input type='text' name='personwon' value='$winner' class='textarea'><br><b>Replay:</b> <input type='text' name='matchreplay' value='$replay' class='textarea'><br><br>$wannadelete$wannadecline<center><input type='submit' name='submit' value='Submit' class='lp'></center></form></td></tr>";}echo "</table>";} // end editChallenges

Edited by Jonas
Link to comment
Share on other sites

There's still something missing, which might be the problem. In the edit challenges function, you have a list of global variables at the top. One of the global variables is $cid, which is the id number of the challenge that was clicked on. But I don't see the section where $cid is being saved from the previous page (when you click on it). I see it getting passed along to the next page, but I don't see it being retrieved anywhere. Do a search in the console.php page, and search for $cid. Look for a line where you see $cid on the left side of the equals:$cid = xxxxxor something similar. Or maybe a function call likegetvalue("cid", $cid);Another thing you can do to verify that $cid is actually storing a value is echo $cid right after the function starts. After the global line in the editchallenges function, write this:

echo "<script type=\"text/javascript\">alert(\"cid: {$cid}\");</script>";

Click on one of the links and make sure the value matches what you see in the address bar. If the address bar says "console.php?p=EditChallenges&cid=13", then the value of cid you see should also be 13.

Link to comment
Share on other sites

OK, well if you're getting the correct ID then it doesn't matter how it's getting retrieved, as long as it is.I found the problem, the query to select the challenge that was clicked on was not using the ID that was passed to it, it was always getting the first challenge that the user was in (probably copied and pasted the SQL statement that lists all the challenges). I also cleaned up the code and reformatted it so it's a little easier to read.

// edits challengesfunction editChallenges($user){  global $bordercolor1,         $tablebg1,         $submit,         $cid,         $decline,         $idc,         $matchdate,         $matchreplay,         $mapused,         $personwon,         $deletethis;  echo "<table align='center' border='1' cellspacing='0' cellpadding='0' bordercolor='{$bordercolor1}' width='500'>  <tr><td background='{$tablebg1}' class='main' align='center'><b>Edit Challenges</b></td></tr>";  if($decline)  {    echo "<script language='javascript'>    if(!confirm('Do really want to decline? You won\'t be able to edit this \\n\ challenge after you decline.'))    {    window.location = 'console.php?p=EditChallenges&cid={$idc}'    }    </script>";    $query = "UPDATE challanges SET declined = '{$user}' WHERE id = '{$idc}'";    mysql_query($query) or die(mysql_error());    echo "<script language=\"Javascript\">    alert(\"Success!\");    window.location.href = 'console.php';    </script>";  }  if($submit)  {    $query = "UPDATE challanges SET date = '{$matchdate}', replay = '{$matchreplay}', map = '{$mapused}', winner = '{$personwon}' WHERE id = '{$idc}'";    mysql_query($query) or die(mysql_error());    echo "<script language=\"Javascript\">    alert(\"Success!\");    window.location.href = 'console.php';    </script>";  }  if($deletethis)  {    deleteStuff("challanges", $idc, 112188);  }  if ($cid == "")  {    echo "<tr><td class='small'><br>    <blockquote>    This is where you can edit your challenges. If no challenges are shown that means no one has challenged you <b>OR</b> you    have declined from a challange making you unable to now edit it.    <br><br>";    $query = "SELECT * FROM challanges WHERE (challanger = '{$user}' OR challanged = '{$user}') AND declined != '{$user}' ORDER BY id DESC";    $result = mysql_query($query) or die(mysql_error());    while($row = mysql_fetch_assoc($result))    {      echo "<a href='console.php?p=EditChallenges&cid={$row['id']}'>{$row['challanger']} vs. {$row['challanged']}</a> - {$row['date']}<br>";    }    echo " </blockquote> </td></tr> ";  }  else  {    $query = "SELECT * FROM challanges WHERE id={$cid}";    $result = mysql_query($query) or die(mysql_error());    $row = mysql_fetch_assoc($result);    if ($row['declined'] == "")    {      $wannadecline = "<center><input type='submit' name='decline' value='Decline' class='lp'></center><br>";      $wannadelete = "";    }    else    {      $wannadelete = "<center><input type='submit' name='deletethis' value='Delete' class='lp'></center><br>";      $wannadecline = "";    }    echo "<tr><td class='small'><form action='console.php?p=EditChallenges&cid={$row['id']}' method='post'>    <blockquote><br>    <center><b>{$row['challanger']}</b> vs. <b>{$row['challanged']}</b></center><br><br>    <input type='hidden' name='idc' value='{$row['id']}'>    <b>Date:</b> <input type='text' name='matchdate' value='{$row['date']}' class='textarea'><br>    <b>Map:</b> <input type='text' name='mapused' value='{$row['map']}' class='textarea'><br>    <b>Winner:</b> <input type='text' name='personwon' value='{$row['winner']}' class='textarea'><br>    <b>Replay:</b> <input type='text' name='matchreplay' value='{$row['replay']}' class='textarea'><br><br>    {$wannadelete}    {$wannadecline}    <center><input type='submit' name='submit' value='Submit' class='lp'></center>    </form>    </td></tr>";  }  echo "</table>";}// end editChallenges

Edited by Jonas
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...