Need help with dynamic player signatures. [PHP and MySQL]
#1

Hello I was trying to make dynamic player signatures using this tutorial: https://sampforum.blast.hk/showthread.php?tid=301435

I have a bug that the image is not showing. I am using the script here: link removed don't think it is necessary.

Here are the scripts:

signature2.php
pawn Код:
<html>
<head>
        <title>My title here</title>
</head>
        <h1>Signature configuration.</h1>
        <p>Hello, welcome to the image configuration page.<br />
        Before you can make your signature, we need your in-game name, exact as it is.</p>
       
        <form action="signature.php" method="get"> <!-- When you click the "send" button, this information will be send to the "signature.php" page. If you're using another php page, you need to change "signature.php" to the file you called it. -->
        Playername: <input type="text" name="player_name"><br>  <!-- This is a little text box which will ask for you playername. -->
       <input type="Submit"> <!-- A "send" button. -->
       </form>


</body>
</html>
signature.php
pawn Код:
<?
$player_name=$_GET['player_name']; // This gets the player his name from the previous page.

/* Let's start by configuring your mysql details. */
$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.

/* 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.");

/* To protect MySQL injection. */
$player_name = stripslashes($player_name);
$player_name = mysql_real_escape_string($player_name);

$query="SELECT * FROM users WHERE Username ='$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 != 0) // 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,"Username"); // Gets the username of the player and put it in the variable $Playername.
    $Money=mysql_result($result,0,"pMoney"); // Gets the money of the player and put it in the variable $Money.
    $Score=mysql_result($result,0,"pKills"); // Gets the score of the player and put it in the variable $Score.

    header('Content-Type: png;'); // Don't touch this. We use this to tell the script we're working with an image.
    $im = @imagecreatefrompng('playersign.png') or die("Cannot select the correct image. Please contact the webmaster."); // Don't forget to put your picture there. Eg: playersig.png
    $text_color = imagecolorallocate($im, 197,197,199); // RED, GREEN, BLUE --> Go to http://www.colorpicker.com, select a nice color, copy the R/G/B letters provided by colorpicker and put them here.
    $text_username = "$Playername"; // This gets the information: player name to be showed in the picture.
    $text_score = "$Score"; // Same as above but with score.
    $text_money = "$Money"; // Same as above but with money.
    $font = "Action.ttf" /* 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, 0, 0, $text_color, $font, $text_username); // Prints the username in the picture.  
    imagettftext($im, 16, 0, 1, 1, $text_color, $font, $text_score); // Prints the score in the picture.
    imagettftext($im, 16, 0, 2, 2, $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();
?>
Please tell me whats wrong?

EDIT: I got something like `Username` , `pKills`,etc in the script.
pawn Код:
format(Query, sizeof(Query), "SELECT * FROM `users` WHERE `Username` = '%s'", escpname);
What is (`) here? I tried it but it doesn't works either.
Reply
#2

Please anyone? The image is loading but not showing up just a small box appears with "Image" text in its center.
Reply
#3

Make sure your image work without the mysql information.

By the way, i also had problems with imagecreatefrompng , so i created a true color one instead, and placed the image above it with imagecopy.

Here is a simple working PHP image:

PHP код:
// Establish image factors:
    
$font_size 18// Font size is in pixels.
    
$font_file 'Tahoma.ttf'// This is the path to your font file.


    // Create image:
    
$image imagecreatetruecolor(450110); // Create a truecolor image 450x110

    // Allocate text and background colors (RGB format):
    
$bg_color imagecolorallocate($image000);
    
$text_color imagecolorallocate($image,237,176,07);

    
// Fill image:
    
imagefill($image00$bg_color);

    
// Bg IMG
    
$bg_image imagecreatefrompng("bg.png"); // Load PNG image
    
imagecopy($image,$bg_image,0,0,0,0,450,110); // Then copy it into our image

    // Add TrueType text to image:
    
imagettftext($image$font_size010060$text_color$font_file"This is a test!");

    
// Generate and send image to browser:
    
header('Content-type: image/png');
    
imagepng($image);

    
// Destroy image in memory to free-up resources:
    
imagedestroy($image); 
Hope i helped you.
Reply
#4

Nothing changed still same problem this is my modified code.
pawn Код:
if ($i != 0) // 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,"`Username`"); // Gets the username of the player and put it in the variable $Playername.
    $Money=mysql_result($result,0,"`pMoney`"); // Gets the money of the player and put it in the variable $Money.
    $Score=mysql_result($result,0,"`pKills`"); // Gets the score of the player and put it in the variable $Score.

    $text_username = "$Playername"; // This gets the information: player name to be showed in the picture.
    $text_score = "$Score"; // Same as above but with score.
    $text_money = "$Money"; // Same as above but with money.

    $font_size = 18; // Font size is in pixels.
    $font_file = 'Action.ttf'; // This is the path to your font file.

    // Create image:
    $image = imagecreatetruecolor(450, 110); // Create a truecolor image 450x110

    // Allocate text and background colors (RGB format):
    $bg_color = imagecolorallocate($image, 0, 0, 0);
    $text_color = imagecolorallocate($image,237,176,07);

    // Fill image:
    imagefill($image, 0, 0, $bg_color);

    $bg_image = imagecreatefrompng("playersign.png"); // Load PNG image
    imagecopy($image,$bg_image,0,0,0,0,450,110); // Then copy it into our image

    imagettftext($image, 16, 0, 0, 0, $text_color, $font_file, $text_username); // Prints the username in the picture.  
    imagettftext($image, 16, 0, 1, 1, $text_color, $font_file, $text_score); // Prints the score in the picture.
    imagettftext($image, 16, 0, 2, 2, $text_color, $font_file, $text_money); // Prints the money in the picture.

    header('Content-Type: image/png'); // Don't touch this. We use this to tell the script we're working with an image.

    imagepng($image);
    imagedestroy($image);
EDIT: Is the problem can be in image?
Reply
#5

I am bumping this as I still need help with it.
Reply
#6

BUMP! Help. I also want to know how can I test it on local MySQL server? what files should I need to establish a local MySQL server on my Windows 7, 32 bit.
Reply
#7

The problem here i see is that u are trying to run a php script directly but php script wont run until u host it.
To host it locally you need Apache server or Windows server with php and Mysql support
But believe me i tried doing it form over 2 weeks then too was not successful caz its very complicated to install them..

So the Question is is there any easier way?
Yes there is which i used.
If u are using MySql then u must have installed WAMP server which has phpMyAdmin.
If u don't have WAMP server then ****** it and download the latest version and install it.

After installing it do the following steps-
  • Go to folder where WAMP server is installed [it is probably in C:/wamp]
  • Open folder named www in it.
  • Create a new folder inside www folder of any name you want, lets say you created folder named sig in it.
  • Now copy both of your php files inside sig folder
  • The php file which takes input of name that is signature2.php, rename signature2.php to index.php
  • Now launch WAMP server application OR if it is already launched then right click on its icon in task bar[beside the clock] and press Refresh
  • Make sure WAMP server is online, if its online then its icon in task bar will be green, if not then right click it and click on put Online button. NOTE after opening or clicking Online button you have to wait for 5 - 15 sec to make it a green icon.
  • Now open your internet browser [ eg ****** chrome ] and type localhost/sig in address bar
  • Now done !
Reply
#8

Doesn't works either. I already hosted the script, will send you the link in PM.
Reply
#9

Still need help. Or can anyone make one for me? I can give him Admin Rank in my server.
Reply
#10

I found the problem. Its in imagettftext. When I remove this code the image appears. Please tell me how can I solve this problem or is there any other way to add text to image without this function. I am using 000webhost for testing.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)