Stieny Posted December 27, 2009 Share Posted December 27, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/186402-multiple-uniqe-entries-to-sql/ Share on other sites More sharing options...
Stieny Posted December 27, 2009 Author Share Posted December 27, 2009 Still looking... Quote Link to comment https://forums.phpfreaks.com/topic/186402-multiple-uniqe-entries-to-sql/#findComment-984359 Share on other sites More sharing options...
Psycho Posted December 27, 2009 Share Posted December 27, 2009 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}"); Quote Link to comment https://forums.phpfreaks.com/topic/186402-multiple-uniqe-entries-to-sql/#findComment-984374 Share on other sites More sharing options...
Stieny Posted December 27, 2009 Author Share Posted December 27, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/186402-multiple-uniqe-entries-to-sql/#findComment-984377 Share on other sites More sharing options...
Stieny Posted December 27, 2009 Author Share Posted December 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/186402-multiple-uniqe-entries-to-sql/#findComment-984383 Share on other sites More sharing options...
Psycho Posted December 27, 2009 Share Posted December 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/186402-multiple-uniqe-entries-to-sql/#findComment-984435 Share on other sites More sharing options...
Stieny Posted December 27, 2009 Author Share Posted December 27, 2009 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(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/186402-multiple-uniqe-entries-to-sql/#findComment-984457 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.