Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Donovan
Client



Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Fri Oct 20, 2006 4:40 pm Reply with quote

I have a page that captures a team_id.

I use this when displaying information on the page such as:

Code:
echo"<center><H2><strong>Campaign Movement Orders for  </strong></H2></center><br>";

echo"<center><H2><strong>$unitname</strong></H2></center><br>";


I have a statement written but can't seem to read the value of the $id that I used before.

Code:
if ($op == "Move") {    

   //convert all the posts to variables:
            
      $tid = intval($_POST['tid']);      
      $action = 'Move';
      //Insert the values into the correct database with the right fields

      $result = $db->sql_query ("INSERT INTO " . $prefix . "_eto_movelog (log_id, ateam_id, tid, move_dt, action)".
         "VALUES ('NULL','$id','$tid',CURRENT_TIMESTAMP(),'$action')");      

      $update = $db->sql_query("UPDATE " . $prefix . "_tc_teams SET tid = '$tid' WHERE team_id = '$id'");   
      
}


The log_id, tid, move_dt and action are all being written to the table.

ateam_id is not being inserted into movelog

nor is team_id being updated in tc_teams

It seems to me that I can't read the value of $id inside this statement?

Why?
 
View user's profile Send private message Visit poster's website ICQ Number
Donovan







PostPosted: Fri Oct 20, 2006 4:42 pm Reply with quote

I get the value of id earlier in my script.

Code:
$id = $_GET['team_id'];
 
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Fri Oct 20, 2006 6:44 pm Reply with quote

Try using the variable name of $team_id instead of $id. I could have sworn somewhere that I read to avoid $id, but not sure.

Also, if your $id (now $team_id) was valued outside a function and you are trying to use it now within the function, make sure to define it within the function as "global". (I'll be honest with you, I forget this all the time... so if that is it, don't fret.)

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
Donovan







PostPosted: Sat Oct 21, 2006 10:23 am Reply with quote

I didn't write a function.

I changed it to team_id but still cannot write the team_id to either table.

Code:
$team_id = $_GET['team_id'];

$sql = "SELECT * FROM " . $prefix . "_tc_ladderteams tclt WHERE team_id ='$team_id'";
$result = $db->sql_query($sql);
$info = $db->sql_fetchrow($result);
   if (!$result) {
      echo("<p>Error performing query: " . mysql_error() . "</p>");
      exit();
   } else {
      $unitname = $info['name'];
   }
if ($op == "Move") {   
               
      $tid = intval($_POST['tid']);      
      $action = 'Move';
      //Insert the values into the correct database with the right fields

      $result = $db->sql_query ("INSERT INTO " . $prefix . "_eto_movelog (log_id, ateam_id, tid, move_dt, action)".
         "VALUES ('NULL','$team_id','$tid',CURRENT_TIMESTAMP(),'$action')");      

      $update = $db->sql_query("UPDATE " . $prefix . "_tc_teams SET tid = '$tid' WHERE team_id = '$team_id'");

}
 
Donovan







PostPosted: Sat Oct 21, 2006 11:02 am Reply with quote

I had to POST the value. I thought if the value was passed by another page I would not need to.

Code:
if ($op == "Move") {    

         $team_id = intval($_POST['team_id']);      
      $tid = intval($_POST['tid']);      
      $action = 'Move';
                                etc



My next page I'm working on is the Attack page. In this script I would have an attacking team_id and defending team_id such as ateam_id and dteam_id.

ateam_id is easy to get but dteam_id I'm trying to get from a dropdown box. So far I've been unsuccessful.

Same as before..both scripts look very similiar. I need the team_id passed to be ateam_id for attacking team. I think I have this part working.

Code:
$team_id = intval($_GET['team_id']);

$sql = "SELECT * FROM " . $prefix . "_tc_ladderteams tclt WHERE team_id ='$team_id'";
$result = $db->sql_query($sql);
$info = $db->sql_fetchrow($result);
   if (!$result) {
      echo("<p>Error performing query: " . mysql_error() . "</p>");
      exit();
   } else {
      $unitname = $info['name'];
   }
Opentable()
?>
<center><H2><strong>Attack Orders for  </strong></H2></center><br>
<center><H2><strong><?php echo $unitname ?></strong></H2></center><br>
<br>
<br>
<!-- Attack page -->
<?php
if ($op == "Attack") {   
   //convert all the posts to variables:   
      $ateam_id = intval($_POST['team_id']);
      $dteam_id = intval($_POST['dteam_id']);
      $tid = intval($_POST['tid']);      
      $action = 'Attack';
      //Insert the values into the database

      $result = $db->sql_query ("INSERT INTO " . $prefix . "_eto_movelog (log_id, ateam_id, dteam_id, move_dt, action)".
         "VALUES ('NULL','$ateam_id','$dteam_id',CURRENT_TIMESTAMP(),'$action')");
      
}
?>


And further below I have my dropdown box to select what team to be attacked which would be dteam_id. So far this is not getting written to the table.

Code:
//Filter the values for the drop down box.

$result = $db->sql_query("SELECT * FROM " . $prefix . "_tc_ladderteams tclt
LEFT JOIN " . $prefix . "_tc_teams tct ON (tclt.team_id = tct.team_id)
LEFT JOIN " . $prefix . "_eto_campaigns ec ON (tclt.ladder_id = ec.cid)
LEFT JOIN " . $prefix . "_tc_ladders tcl ON (tcl.sid = tclt.ladder_id)
WHERE tct.div_id != $div_id
AND tcl.active = 1
AND tct.is_active = 1");

 //Team List Box for Selection of Enemy.
while ( $row = $db->sql_fetchrow($result) ) {
   $dteam_name = $row["name"];
   $dteam_id = $row["team_id"];
   echo "<option value='$dteam_id'>$dteam_name</option>";   
}
echo"</select>"


Then at the bottom I have

Code:
."<input type=\"hidden\" name=\"op\" value=\"Attack\">"

."<input type=\"hidden\" name=\"team_id\" value=\"$team_id\">"
."<input type=\"submit\" align=\"center\" name=\"Submit\" value=\"Attack This Unit!\">";
CloseTable();


I don't want the two team_id to step on each other which has happend already.
 
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Mon Oct 23, 2006 12:22 am Reply with quote

Donovan wrote:
I had to POST the value. I thought if the value was passed by another page I would not need to.

All values that are passed by any means have to retrieved by using $_GET, $_POST, or $_SESSION - there are a few other ways, but these are the main ones. There is no other way but by referencing the type method that was used to pass the variable. I'm not sure what you have confused here.
 
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©