Jump to content

Recommended Posts

Here is the working code I have:

 

   		$leader = rand(1,$count);
            $qry="SELECT * FROM members WHERE member_id='".$leader."'";
		$result = mysql_query($qry);
            $loc = mysql_fetch_array($result);
            header('refresh: 4; url= exploration.php');
            echo $success_header;
		echo "You have found the borders of ";
		echo $loc['kingdom']; 
		echo "<br>where "; 
		echo $loc['leader']; 
		echo " resides.";
		echo "<BR> $chance";
            echo $footer;
		$new_loc = $loc['leader'];
		mysql_query("UPDATE members SET locations = '".$loc_leader."' WHERE leader='".($_SESSION['SESS_LEADER_NAME'])."'");
            exit();

 

Update is not working. What I would like it to do is add the current searched location to the previous found locations. Currently I have locations set to longtext in mysql. I have tried serialize to add multiple instances, but that is not working either.

 

Any suggestions on how to store the multiple unique locations?

Link to comment
https://forums.phpfreaks.com/topic/186402-multiple-uniqe-entries-to-sql/
Share on other sites

If your query is failing then verify the query (Note: "or die()" should only be used for ad hoc debugging and should never be in your final code. Better to implement real error handling for final code).

 

$query = "UPDATE members SET locations = '{$loc_leader}' WHERE leader='{$_SESSION['SESS_LEADER_NAME']}'");            
mysql_query($query) or die (mysql_error()."<br />{$query}");

There are no errors in the code. The code works, until it is time to update the data. It is executing the update, however mysql is not accepting the data.

 

I need to know which data type to set in mysql, and and how to update multiple entries to 'locations'.

 

Or, if there is a better way other than multiple entries to one cell that someone could propose...

I guess I could be a little more specific. This is an exec script for searching for other players. To get other players to interact with, you need to search for their locations. The script works great and randomly pulls other players, however, I want to store them in order to populate a drop down list of available players to interact with.

No errors in the code? Did you check it like I showed? If there is an error int he query you will not see an error unless you check for it. If the query is valid then there is no reason why it won't update correctly. So, the likely problem IS the query. So, echo the query to the page regardless if it fails or not. If the query isn't failing then the problem should be the session value doesn't match the records you are wanting to update.

Yes, no errors.

 

Let us say that you try and update an sql field with varchar, and the field data type is set to int. You will not get a php error, however it will not update in sql. (unfortunately I know this by trial and error). 

 

Again, there are no errors in the script. What I am failing to do is show a value in sql. The way I have it set right now, it is going to have to make a list in one cell in sql.  I have the field data type set to large text, which I am not sure is correct. I have tried making a separate table, but I want to be able to recall each location a specific user has collected in one place via a WHERE, instead of multiple rows, as well as avoid duplicate searches on the same user. I have read about serialize, which I believe could apply here, however, I have not gotten that to work either.

 

Let me show the entire code and see if it helps to see what I am trying to do a little more:

<?PHP
require_once('auth.php'); 
include("gm_cnst.php"); 

//Set a random number for a user ID
$qry="SELECT member_id FROM members";
$result = mysql_query($qry);
$count = 0;

while(mysql_fetch_array($result)) 
{
$count++;
}

//Set the chance to find another player
$mod = rand (0,5);
$chance = (($user[scouts]*$bonus[scouts]) + ($user[scouts]*$bonus[explore]))*$mod;

//Make sure the user has enough turns
      if($user[turns] <= 0)
   {
            header('refresh: 4; url= exploration.php');
            echo $error_header;
            echo "You do not have enough turns to do that.";
            echo $footer;
            exit();
   }
//Search for other players according to conditions.
      if($chance <= 0)
   {
            header('refresh: 4; url= exploration.php');
            echo $error_header;
            echo "Your Scouts searched the lands, but only came back tired and hungry.";
            echo $footer;
            exit();
   }
      	elseif($chance < 999)
   	{
            header('refresh: 4; url= exploration.php');
            echo $error_header;
            echo "Your Scouts searched the lands, but only came back tired and hungry.";
            echo $footer;
            exit();
   	}      
   		elseif($chance > 1000 and $chance < 4999)
   	{
	header('refresh: 4; url= exploration.php');
                echo $success_header;
   	$leader = rand(1,$count);
	$qry="SELECT * FROM members WHERE member_id='".$leader."'";
	$result = mysql_query($qry);
	$loc = mysql_fetch_array($result);
	echo "You have found the borders of ";
	echo $loc['kingdom']; 
	echo "<br>where "; 
	echo $loc['leader']; 
	echo " resides.<p>";
        echo $footer;
	//Need an update statement here that will work
        exit();
}
?>

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.