-1

Hallo so this is what I have:

test.php

<form action="index.php" method="post">
   <input type="text" name="nick">
   <input type="submit" name="test">
</form>

index.php

    <?php
if(isset($_POST['test'])) {

  $bg = imagecreatefrompng('img/sygn/1.png') or die("t");
    $font = "others/rte.ttf";
    $blackColor = imagecolorallocate($bg, 47, 53, 62);
    $diamondColor = imagecolorallocate($bg, 140, 244, 226);
    $emeraldColor = imagecolorallocate($bg, 92, 244, 149);
    $goldCollor = imagecolorallocate($bg, 234, 238, 87);
    header("Content-type: image/png");
    imagettftext($bg, 29, 0, 5, 33, $blackColor, $font, 'Username');
    imagettftext($bg, 17, 0, 360, 83, $goldCollor, $font, '20');
    imagettftext($bg, 17, 0, 360, 43, $emeraldColor, $font, '20');
    imagettftext($bg, 28, 0, 50, 125, $diamondColor, $font, '400');
    imagepng($bg);
    imagepng($bg, "users/image.png");
    imagedestroy($bg);
}

?>

I would like to display the image after clicking on the button. But it doesn't work, I don't get any image only the blank side. If I remove if statement it works correctly. Also if I Add:

echo '<input type="text">'

In the first line, image generator wont work as well. Same with for example:

include form.php

This is what I get:

http://screenshot.net/pjg6du1
To dO
  • 53
  • 5
  • Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Mar 18 '15 at 21:40
  • Why do you call `imagepng` twice? – andrewsi Mar 18 '15 at 21:40
  • I don't get any Errors. I have tried it. andrewsi this is not important now. It work correctly if I remove if statement. This is what I get after clicking on the button http://screenshot.net/pjg6du1 – To dO Mar 18 '15 at 21:42

3 Answers3

0

Try this :

if(isset($_POST['nick']) && $_POST['nick'] != '') {
    //my code
}
Marcel Djaman
  • 1,276
  • 1
  • 17
  • 34
0

You need to set value for your input submit as the following:

<input type="submit" value="Submit" name="submit" />

Similar another answer

Community
  • 1
  • 1
Mohamed Yakout
  • 2,868
  • 1
  • 25
  • 45
  • No. It is not the problem. When I look in the code my image is generated But I don't see it. – To dO Mar 18 '15 at 21:31
  • Ok, Try to echo isset($_POST['test']) before if condition, if it's true, so it'll go through code inside if statement, that's to make sure, and let me know – Mohamed Yakout Mar 18 '15 at 21:45
0
  1. Check all paths are right (img, font and user directory).
  2. Your if statement is correct.
  3. Add
     on your page.
  4. It works.

imagepng create image in the user directory but you don't display it on your page.

Correct code below :

<html>
<head>
<?php
if(isset($_POST['test'])) {

  $bg = imagecreatefrompng('img/sygn/1.png') or die("t");
    $font = "others/rte.ttf";
    $blackColor = imagecolorallocate($bg, 47, 53, 62);
    $diamondColor = imagecolorallocate($bg, 140, 244, 226);
    $emeraldColor = imagecolorallocate($bg, 92, 244, 149);
    $goldCollor = imagecolorallocate($bg, 234, 238, 87);
    header("Content-type: image/png");
    imagettftext($bg, 29, 0, 5, 33, $blackColor, $font, 'Username');
    imagettftext($bg, 17, 0, 360, 83, $goldCollor, $font, '20');
    imagettftext($bg, 17, 0, 360, 43, $emeraldColor, $font, '20');
    imagettftext($bg, 28, 0, 50, 125, $diamondColor, $font, '400');
    imagepng($bg);
    imagepng($bg, "users/image.png");
    imagedestroy($bg);
}

?>
</head>
<body>
<form action="test.php" method="post">
   <input type="text" name="nick">
   <input type="submit" name="test">
</form>
<img src="users/image.png" />
</body>
</html>