KcoRocK Posted July 23, 2012 Share Posted July 23, 2012 Hello, I am from San Andreas Multiplayer, I need help with these dynamic signatures I am a newb at PHP and MySQL so I was wondering if you can help me out when I try to make the dynamic sig it says User is not found in database <? /* ***Made by: Nodroz*** *** Enjoy your signatures! *** */ $username="***"; //Your MySQL Username. $password="***"; // Your MySQL Pass. $database="***"; // Your MySQL database. $host="***"; // Your MySQL host. This is "localhost" or the IP specified by your hosting company. $player_name=$_GET['player_name']; // This gets the player his name from the previous page. /* Next, we will make a connection to the mysql. If it can't connect, it'll print on the screen: Unable to select database. Be sure the databasename exists and online is. */ mysql_connect($host,$username,$password); // Connection to the database. @mysql_select_db($database) or die( "Unable to select database. Be sure the databasename exists and online is."); //Selection of the database. If it can't read the database, it'll give an error. /* To protect MySQL injection. */ $player_name = stripslashes($player_name); $player_name = mysql_real_escape_string($player_name); $query="SELECT * FROM accounts WHERE Name='$player_name'"; // Gets all the information about the player. $result=mysql_query($query); $i=mysql_num_rows($result); // Here we are counting how many rows this result gives us. /* We will now put the player's information into variables so we can use them more easily. */ /* DON'T FORGET: The names should be exact the same as in your mysql db.*/ if ($i == 1) // If the user has been correct, then it'll give us 1 row. If its 1 row, then it'll proceed with the code. { $Playername=mysql_result($result,0,"Playername"); // Gets the username of the player and put it in the variable $Playername. $Money=mysql_result($result,0,"Money"); // Gets the money of the player and put it in the variable $Money. $Score=mysql_result($result,0,"Score"); // Gets the score of the player and put it in the variable $Score. // Creating of the .png image. header('Content-Type: image/png;'); $im = @imagecreatefrompng('mypicture.png') or die("Cannot select the correct image. Please contact the webmaster."); // Don't forget to put your picture there. $text_color = imagecolorallocate($im, 197,197,199); // RED, GREEN, BLUE --> Go to [url=http://www.colorpicker.com]www.colorpicker.com[/url], select a nice color. Copy the R/G/B letters provided by colorpicker and put them here. $text_username = "$Playername"; // This gets the information about player name to be showed in the picture. $text_score = "$Score"; // Same as above ^^ $text_money = "$Money"; // Same as above ^^ $font = 'myfont.ttf'; //Upload your custum font to the directory where this file is placed. Then change the name here. /* USAGE OF THE imagettftext: First ($im) shouldn't be changed. (16) is the text-size. (0) is the angle of your text. Change it, and you'll see what's going on. (20) is de X-coordinate of the text. (36) is the Y-coordinate of the text. */ imagettftext($im, 16, 0, 20, 36, $text_color, $font, $text_username); // Prints the username in the picture. imagettftext($im, 16, 0, 72, 69, $text_color, $font, $text_score); // Prints the score in the picture. imagettftext($im, 16, 0, 72, 99, $text_color, $font, $text_money); // Prints the money in the picture. imagepng($im); imagedestroy($im); } else echo('Username is not in our database. Please try again.'); // If the username doesn't exist (so the row is 0) then it'll give en error. mysql_close(); ?> In my actually SAMP Script to find the username this is the line [pawn] "SELECT * FROM `accounts` WHERE `Name` = '%s' LIMIT 1", pName[/pawn] If you need anything else just reply, but I am new to MySQL, I know squat crap about it Quote Link to comment https://forums.phpfreaks.com/topic/266102-dynamic-signatures/ Share on other sites More sharing options...
KcoRocK Posted July 23, 2012 Author Share Posted July 23, 2012 Can't find an edit button, but here is the SQL Dump without the data SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; CREATE TABLE IF NOT EXISTS `accounts` ( `Name` varchar(24) NOT NULL, `Password` varchar(129) NOT NULL, `IP` varchar(16) NOT NULL, `Admin` int(9) NOT NULL, `Money` int(9) NOT NULL, `Score` int(9) NOT NULL, `Kills` int(9) NOT NULL, `Deaths` int(9) NOT NULL, PRIMARY KEY (`Name`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; Quote Link to comment https://forums.phpfreaks.com/topic/266102-dynamic-signatures/#findComment-1363609 Share on other sites More sharing options...
xflawless Posted July 23, 2012 Share Posted July 23, 2012 SELECT * FROM accounts WHERE Name='$player_name' Should be SELECT * FROM accounts WHERE Name='$player_name' LIMIT 1 Error here $Playername=mysql_result($result,0,"Playername"); Can you var_dump($result); ? Quote Link to comment https://forums.phpfreaks.com/topic/266102-dynamic-signatures/#findComment-1363758 Share on other sites More sharing options...
DavidAM Posted July 23, 2012 Share Posted July 23, 2012 Since Name is the PRIMARY KEY on the table, LIMIT 1 is not needed here. There can only ever be one (or zero) rows for that query. First, in development, turn on error reporting. There may be errors occurring that prevent the query from succeeding: # AT THE BEGINNING OF EACH PHP SCRIPT - TURN ON ERROR REPORTING error_reporting(E_ALL); ini_set('display.errors', 1); Check to see if the query is actually working: $result=mysql_query($query); # ADD THE FOLLOWING LINE if (! $result) trigger_error(sprintf("Query Failed: %s <BR>\nWith error: %s", $query, mysql_error()), E_USER_ERROR); $i=mysql_num_rows($result); // Here we are counting how many rows this result gives us. to see if the query failed and what the error message is. mySql errors do not produce PHP errors, so you have to call the mysql_error function to get them. I don't see why that script would fail, if the player name is in the database. You can echo out the query and try running it against the database (in phpmyadmin or the mysql command line), to see what happens. The only other things that stick out in my mind are: Is the Name column case-sensitive and are you providing the argument in the same case? Name is limited to 24 characters, are you providing a longer name? Try using trim on the input, in case there are spaces; You are using $_GET, is the player name in the url, or is this coming from a form that is POSTed? You say you are new to PHP. Three things you need to learn (or unlearn): [*]Always use long tags: <?php short tags lead to all kinds of problems [*]Forget you ever heard of the error suppression operator "@". Suppressing errors does not make a script work, it just hides the problems [*]You only need stripslahses if "magic quotes" is on. Since that option has been deprecated, you should always have it off if you have control. If you don't have control, you can check to see if it is on -- get_magic_quotes_gpc -- before you stripslashes Quote Link to comment https://forums.phpfreaks.com/topic/266102-dynamic-signatures/#findComment-1363783 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.