if statement

For discussions about game development that does not fit in any of the other topics.
Post Reply
SerbanSpire
Posts: 19
Joined: Fri Dec 14, 2012 11:23 am

if statement

Post by SerbanSpire »

I have this code snippet

Code: Select all

<?php

include 'connect.php';

?>

<?php
session_start();
$char_name = $_POST['char_name'];
$dynasty_name = $_POST['dynasty_name'];

if($char_name == "" || $dynasty_name == "")
{
	echo "You didn't enter all the character requirements!";
	echo "<a href='createchar.php>Go back</a>";
}

else{


$query = sprintf("SELECT id FROM users WHERE UPPER(username) = UPPER('%s')",
			mysql_real_escape_string($_SESSION['username']));
$result = mysql_query($query);
list($userID) = mysql_fetch_row($result);


$sql = sprintf("SELECT char_dynasty FROM characters WHERE id = '%b'", $userID);
$result = mysql_query($sql);


if(mysql_fetch_row($result))
{
	$query = sprintf("SELECT char_dynasty FROM characters WHERE id = '%b'", $userID);
	$result = mysql_query($query);
	echo "There already is a dynasty by that name!";
	echo "<a href='createchar.php>Go back</a>";
}

else
{
	$sql = "Insert into characters(id, char_name, char_dynasty, picture) VALUES ('$userID','$char_name','$dynasty_name','Male1.png')";
	mysql_query($sql);
}

}

?>
Why this code never gets to this if:

Code: Select all

if(mysql_fetch_row($result))
{
	$query = sprintf("SELECT char_dynasty FROM characters WHERE id = '%b'", $userID);
	$result = mysql_query($query);
	echo "There already is a dynasty by that name!";
	echo "<a href='createchar.php>Go back</a>";
}
Winawer
Posts: 180
Joined: Wed Aug 17, 2011 5:53 am

Re: if statement

Post by Winawer »

Assuming id isn't binary, try using %d instead of %b.
SerbanSpire
Posts: 19
Joined: Fri Dec 14, 2012 11:23 am

Re: if statement

Post by SerbanSpire »

Oh wow thanks. It works now. It's not the first time i do this lawl :))
Post Reply

Return to “General Development”