Sign in to follow this  
Stieny

[web] PHP/mySQL help

Recommended Posts

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. There are no errors in the code. The code works, until it is time to update the data. It is executing the final query, 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... Code:
   		elseif($chance > 1000 and $chance < 4999)
   	{
	   		$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 "
 $chance";
            echo $footer;
			$query = "UPDATE members SET locations = '".$loc_leader."' WHERE leader='".($_SESSION['SESS_LEADER_NAME'])."'";
			mysql_query($query) or die (mysql_error());
            exit();
   	}	

Share this post


Link to post
Share on other sites
Your post is a little confusing, so bear with my possibly stupid questions :)

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

What do you mean by "not accepting the data"? Does your script die with a message from mysql_error? Is the locations field being set to an incorrect value? If so, what is it?

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

Are "entries" players in the members table? What field(s) are you trying to update?

If you are asking how to have a 'location' field for players, assuming that each member has their own location/kingdom, you can just use a member ID in a 'location' column to show which member's kingdom another player is at. (If this makes sense?)

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

What does a "cell" refer to? A kingdom?

Quote:
Code:
*** Source Snippet Removed ***

You are fetching the results of the first SQL query into $loc, but you are using "$loc_leader" when building your second query string. Perhaps you meant to use $loc['leader'] instead?

Share this post


Link to post
Share on other sites
Quote:
$query = "UPDATE members SET locations = '".$loc_leader."' WHERE leader='".($_SESSION['SESS_LEADER_NAME'])."'";


One thing I'm noticing is that I don't see anywhere where $loc_leader is set. Maybe you meant to use $loc['leader'] from the result set? Thing with PHP is it won't complain if you attempt to use an undeclared/uninitialized variable.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ibatex
Thing with PHP is it won't complain if you attempt to use an undeclared/uninitialized variable.
...with default settings. I strongly suggest cranking the warning level up to the "paranoid commie-hating witch-burning psycho" level:

error_reporting(E_ALL);


Share this post


Link to post
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

Sign in to follow this