Jump to content

Major SQL problem


Drezard

Recommended Posts

Okay, SQL has been a great friend of mine for a while. But now its just being a .....

 

So heres my code for my WHOLE function:

 


	if (!isset($_SESSION['userinfo'])) {

		echo "You are not logged in <br>";

	}

	if (isset($_SESSION['userinfo'])) {

	$this->check_userid();

		if ($this->logged == 1) {

			$userinfo = $_SESSION['userinfo'];
			$pieces = explode(" ", $userinfo);
			$user = $pieces[0]; 

			$query = "SELECT * FROM user_ids WHERE user='$user' AND priv=0";

			$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

			$count = mysql_num_rows($result);

			if ($count == 1) {


				echo "<form action='' method='post'>

					  <select name='race'>
					  <option value='human'>Human - Your Average Human</option>
					  <option value='shadow'>Shadow - Dark and Mysterious</option>
					  <option value='vampire'>Vampire - Half-Human Half-Bat</option>
                          </select> <br>
					  
					  <select name='class'>
					  <option value='hunt'>Hunter</option>
					  <option value='defend'>Defender</option>
					  <option value='rogue'>Rogue</option>
					  <option value='war'>Warlock</option>
					  <option value='priest'>Priest</option>
                          </select> <br>						  

					  <input type='submit' name='submit'>
					  </form>";
					  
				if (isset($_POST['race'])) {

						$race = $_POST['race'];
						$class = $_POST['class'];

						$str = 10;
						$dex = 10;
						$con = 10;
						$mag = 10;

						if ($race == "human") {

							$str - 4;
							$dex + 2;
							$mag + 5;
							$con - 3;

						}

						if ($race == "shadow") {

							$mag - 3;
							$con - 3;
							$dex + 3;
							$str + 3;

						}

						if ($race == "vampire") {

							$mag - 5;
							$str - 3;
							$con + 5;
							$dex + 3;

						}

						if ($class == "hunt") {

							$mag - 5;
							$str + 5;

						}

						if ($class == "defend") {

							$mag - 5;
							$con + 4;
							$str + 1;

						}

						if ($class == "rogue") {

							$con - 5;
							$dex + 3;
							$str + 2;

						}

						if ($class == "war") {

							$con - 5;
							$str - 5;
							$mag + 7;
							$dex + 3;

						}

						if ($class == "priest") {

							$con + 3;
							$str - 5;
							$dex - 5;
							$mag + 7;

						}

						$query ="INSERT INTO user_chars (user, race, class, str, dex, con, mag) VALUES ('$user', 					
						'$race', '$class',  '$str',  '$dex', '$con', '$mag')";

						$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

						$query ="INSERT INTO user_ids (priv) VALUES ('2')";

						$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

						echo "Character Created";

				}

			}

			if ($count == 0) {

				echo "You have already created";


			}

		}

	}	

	if ($this->logged == 0) {

		echo "Incorrect Session";

	}

}

 

Now, In my Database in user_ids under user is the name Peter and under priv is 1. Now whenever I try and run this script it always says char already created. What have i done wrong.

Link to comment
https://forums.phpfreaks.com/topic/37947-major-sql-problem/
Share on other sites

Okay, SQL has been a great friend of mine for a while. But now its just being a .....

 

Now, In my Database in user_ids under user is the name Peter and under priv is 1. Now whenever I try and run this script it always says char already created. What have i done wrong.

 

Notice your query you are asking if privledge = 0

 

But you said Peter is = 1

 

therefore the count will be 0 and result in echoing the character is already created.

Link to comment
https://forums.phpfreaks.com/topic/37947-major-sql-problem/#findComment-181691
Share on other sites

Correct but you are asking

You said peters priv is 1 And no rows will get returned because you are asking for priv = 0

 

 

$query = "SELECT * FROM user_ids WHERE user='$user' AND priv=0";

 

therefore SELECT * FROM user_ids WHERE user='Peter' AND priv=0;

 

And the $count = mysql_num_rows() will return 0; because peters priv is 1;

 

And your if statement that says if ($count == 0) {

 

echo "You have already created";

 

 

}

 

Will print.

Link to comment
https://forums.phpfreaks.com/topic/37947-major-sql-problem/#findComment-181700
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.