PHP - Imagettftext() - Just Can't Get It To Work
Imagettftext() - Just can't get it to work
Hi ALL I'm trying to create a simple font tester. Imagettftext() looks perfect but I can't get it to work. I'm using this piece of code from php.net. Nothing is output and I get an error message in Firefox: The image "http://www.ttmt.org.uk/test/index.php" cannot be displayed because it contains errors. The font is available in the same location as the php file. http://www.ttmt.org.uk/test/index.php Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>untitled</title> </head> <body> <?php // Set the content-type header('Content-Type: image/png'); // Create the image $im = imagecreatetruecolor(400, 30); // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 399, 29, $white); // The text to draw $text = 'Testing...'; // Replace path by your own font path $font = 'corbelb.ttf'; // Add the text imagettftext($im, 20, 0, 10, 20, $black, $font, $text); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im); ?> </body> </html> Similar TutorialsHi, I have a small code to display some data from mysql db as .png image, however the image loads but it doesn't show any data on it. php: <? $username=""; $password=""; $database=""; $host=""; $player_name=$_GET['player_name']; mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database. Be sure the databasename exists and online is."); $player_name = stripslashes($player_name); $player_name = mysql_real_escape_string($player_name); $query="SELECT * FROM characters WHERE name='$player_name'"; $result=mysql_query($query); $i=mysql_num_rows($result); if ($i == 1) { $name=mysql_result($result,0,"name"); $OnServer=mysql_result($result,0,"OnServer"); $hours=mysql_result($result,0,"hours"); header('Content-Type: image/png;'); $im = @imagecreatefrompng('1.png') or die("Cannot select the correct image. Please contact the webmaster."); $text_color = imagecolorallocate($im, 197,197,199); $text_username = "$name"; $text_hours = "$hours"; $text_online = "$OnServer"; $font = 'visitor2.ttf'; imagettftext($im, 2, 0, 39, 15, $text_color, $font, $text_username); imagettftext($im, 2, 0, 160, 15, $text_color, $font, $text_hours); imagettftext($im, 2, 0, 297, 15, $text_color, $font, $text_online); imagepng($im); imagedestroy($im); } else echo('Username is not in our database. Please try again.'); mysql_close(); ?> html: Code: [Select] <html> <head> <title>My title here</title> </head> <h1>Signature configuration.</h1> <p>Hello and welcome to the image configuration page.<br /> Before you can make your signature, we need in-game name, exact as it is.</p> <form action="signature.php" method="get"> Playername: <input type="Submit"> </form> </body> </html> sql dump: http://pastebin.com/zXHgCDpt Any ideas? (it's 6am in here so I probably missed something obvious, sorry about that) <? $username="root"; //Your MySQL Username. $password="pass"; // Your MySQL Pass. $database="clan"; // Your MySQL database. $host="127.0.0.1"; // 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 `playerdata` WHERE user = '$player_name' LIMIT 1"; // 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,"user"); // Gets the username of the player and put it in the variable $Playername. $Money=mysql_result($result,0,"kills"); // Gets the money of the player and put it in the variable $Money. $Score=mysql_result($result,0,"deaths"); // 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 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 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(); ?> I'm writing a Dynamic image, that display's a user's Name, but for some reason, the kills stat won't print. I made a .php file using the same parsing method, but using echo, and it worked fine. I also know it's not an issue with X,Y, Size, float, anything like that because I tried replacing "$kill" with "Test," and it printed fine. Here is the actual image: And here is the code for it: <?php Header ('Content-type: image/jpeg'); Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT'); Header('Pragma: no-cache'); // get CMID variable from the url $cmid = $_GET['cmid']; // create the image using your own background $image = imagecreatefromjpeg("background.jpg"); // dimensions of the image used $img_width = 600; $img_height = 9; // set the colours $cool = imagecolorallocate($image, 81, 86, 96); $black = imagecolorallocate($image, 0, 0, 0); $white = imagecolorallocate($image, 255, 255, 255); $red = imagecolorallocate($image, 255, 0, 0); $grey = imagecolorallocate($image, 204, 204, 204); $green = imagecolorallocate($image, 206, 129, 18); $blue = imagecolorallocate($image, 0, 0, 255); $yellow = imagecolorallocate($image, 225, 225, 0); // set the font and print text $font = 'Verdana.ttf'; /* // counter - CHMOD your counter file to 777 $viewss = file("views.txt"); $views = $viewss[0]; $views++; $fp = fopen("views.txt", "w"); fwrite($fp, $views); fclose($fp); $counter = "$views"; // View Output imagettftext($image, 7, 0, 16, 117, $yellow, $font, "Views:$counter"); */ // Attempt to make web content grabber. function get_url_contents($url){ $crl = curl_init(); $timeout = 5; curl_setopt ($crl, CURLOPT_URL,$url); curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); $ret = curl_exec($crl); curl_close($crl); return $ret; } // Web content grabber execution. $returned_content = get_url_contents('http://uberstrike.cmune.com/Profile?cmid=' . $cmid); // Parsing the returned content for Clan Tag. $namestart = strpos($returned_content, '<span style="color: #FEC42C; font-size: 20px; font-weight: bold;">'); $nameend = strpos($returned_content, '</span>', $namestart); $name = substr($returned_content, $namestart, $nameend-$namestart); // Stripping the parsed Clan Tag of HTML elements. $name = html_entity_decode(strip_tags($name)); // Clan and name output. imagettftext($image, 7, 0, 53, 7, $yellow, $font, "$name"); // Parsing the returned content for Global Rank. $rankstart = strpos($returned_content, '<h2 style="font-size:14px; font-weight:bold; text-indent:0px; margin-left:25px;">'); $rankend = strpos($returned_content, '<br />', $rankstart); $rank = substr($returned_content, $rankstart, $rankend-$rankstart); // Stripping the parsed Global Rank of HTML. $rank = html_entity_decode(strip_tags($rank)); // Filtering Rank to only show the value number, not text or formatting in between. $rank = str_replace ("G", "", $rank); $rank = str_replace ("l", "", $rank); $rank = str_replace ("o", "", $rank); $rank = str_replace ("b", "", $rank); $rank = str_replace ("a", "", $rank); $rank = str_replace ("R", "", $rank); $rank = str_replace ("n", "", $rank); $rank = str_replace ("k", "", $rank); $rank = str_replace (":", "", $rank); $rank = str_replace (" ", "", $rank); // Rank Output. imagettftext($image, 7, 0, 220, 7, $yellow, $font, "$rank"); $killstart = strpos($returned_content, '<h3 style="color: #FEC42C;">All time record</h3>'); $killend = strpos($returned_content, '</tr>', $killstart); $kill = substr($returned_content, $killstart, $killend-$killstart); // Stripping the parsed kill of HTML. $kill = html_entity_decode(strip_tags($kill)); // Filtering kill to only show the value number, not text or formatting in between. $kill = str_replace ("K", "", $kill); $kill = str_replace ("i", "", $kill); $kill = str_replace ("l", "", $kill); $kill = str_replace ("A", "", $kill); $kill = str_replace ("t", "", $kill); $kill = str_replace ("m", "", $kill); $kill = str_replace ("e", "", $kill); $kill = str_replace ("r", "", $kill); $kill = str_replace ("o", "", $kill); $kill = str_replace ("d", "", $kill); $kill = str_replace ("c", "", $kill); $kill = str_replace ("s", "", $kill); $kill = str_replace (" ", "", $kill); // Kill Stats output. imagettftext($image, 7, 0, 410, 7, $yellow, $font, "$kill"); // IP Logger $logfile= 'iplog.html'; $IPlog = $_SERVER['REMOTE_ADDR']; $logdetails= date("F j, Y, g:i a") . ': ' . '<a href=http://www.ip2location.com/demo.aspx?ip='.$_SERVER['REMOTE_ADDR'].'>'.$_SERVER['REMOTE_ADDR'].'</a>'; $fplog = fopen($logfile, "a"); fwrite($fplog, $logdetails); fwrite($fplog, "<br>"); fclose($fplog); // output and destroy imagepng($image); imagedestroy($image); ?> I tried using the same parsing code for the $kill stat, and it works fine: http://dynfosig.com/Phoenix_uploads/clangadget/Test.php?cmid=563853 <?php // get CMID variable from the url $cmid = $_GET['cmid']; function get_url_contents($url){ $crl = curl_init(); $timeout = 5; curl_setopt ($crl, CURLOPT_URL,$url); curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); $ret = curl_exec($crl); curl_close($crl); return $ret; } $returned_content = get_url_contents('http://uberstrike.cmune.com/Profile?cmid=' . $cmid); $killstart = strpos($returned_content, '<h3 style="color: #FEC42C;">All time record</h3>'); $killend = strpos($returned_content, '</tr>', $killstart); $kill = substr($returned_content, $killstart, $killend-$killstart); // Stripping the parsed kill of HTML. $kill = html_entity_decode(strip_tags($kill)); // Filtering kill to only show the value number, not text or formatting in between. $kill = str_replace ("K", "", $kill); $kill = str_replace ("i", "", $kill); $kill = str_replace ("l", "", $kill); $kill = str_replace ("A", "", $kill); $kill = str_replace ("t", "", $kill); $kill = str_replace ("m", "", $kill); $kill = str_replace ("e", "", $kill); $kill = str_replace ("r", "", $kill); $kill = str_replace ("o", "", $kill); $kill = str_replace ("d", "", $kill); $kill = str_replace ("c", "", $kill); $kill = str_replace ("s", "", $kill); $kill = str_replace (" ", "", $kill); // Kill Stats output. echo $kill; ?> * Moderator Note: Please do not remove code snippets from the question. i have this code: $wap_image_filename = $wap_profile_pic."-wap.jpg"; $image =0; if($mimetype=='IMAGE/PNG') { $image = imagecreatefrompng($profile_pic); imagejpeg($image,$wap_image_filename , 100); } else if($mimetype=='IMAGE/JPG') { $image = imagecreatefromjpeg($profile_pic); imagejpeg($image,$wap_image_filename , 100); } //resize photo with 100% quality $this->resizeImage($profile_pic,$wap_image_filename,300,300,100); $filename = $wap_image_filename; $date_card_image = imagecreatetruecolor(400, 500); //$date_card_image gives resource id $bg_col = imagecolorallocate ( $date_card_image, 200, 200, 200 ); imagefill ( $date_card_image, 0, 0, $bg_col); $source = imagecreatefromjpeg($filename); //$source gives a resource id# list($ppwidth, $ppheight) = getimagesize($filename); // Resize imagecopyresized($date_card_image, $source , 0, 40, 0,0, 400, $ppheight, $ppwidth, $ppheight); $uc_color = ImageColorAllocate ($date_card_image,10, 10, 10); $info_color = ImageColorAllocate ($date_card_image,42, 134, 186); $white = imagecolorallocate($date_card_image, 255, 255, 255); $black = imagecolorallocate($date_card_image, 0, 0, 0); $blue = imagecolorallocate($date_card_image, 0, 0, 128); $font = '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed-Bold.ttf'; $text = $this->getUniqueCode(); // Add the text imagettftext($date_card_image, 24, 0, 55, 30, $blue, $font, $text); [COLOR="Red"]//get warning on this line 227[/COLOR] the warning i get is: Warning: imagettftext(): Could not find/open font in /home/helloises/traffic_2/phoenix/plugins/rainbowCodePlugin/lib/model/RcProfileTable.php on line 227 please can some one help me fix this? thank you Hello i have some code which is suppose to create a simple captcha image...the code was working fine until it was moved from one location to another...now what it does is the image is created...but for some reason, it's not displaying the text. Here is my code : Code: [Select] <?php session_start(); $image = imagecreate(100, 50); $background = imagecolorallocatealpha($image, 204, 204, 204, 127); $text = imagecolorallocate($image, 0, 0, 0); imagettftext($image, 20, 0, 30, 30, $text, 'Gabriola.ttf', $_SESSION['captcha']); $lines = 20; for($i = 0; $i <= $lines; $i++){ $x1 = rand(1, 100); $y1 = rand(1, 100); $x2 = rand(1, 100); $y2 = rand(1, 100); imageline($image, $x1, $y1, $x2, $y2, $text); } header('content-type: image/jpeg'); imagejpeg($image); ?> this code does create the gray box and displays the 20 lines but no text. when i echo out the $_SESSION['captcha'] on the page it displays the number generated (generated in another file)....i've even replaced that with a string and it doesn't work...the interesting thing about it is that it works on local machine but not on a hosted page...what could possibly cause this?...all the files were changed so the .ttf file is also within the same file as this page Hi All, I am getting this problem for one of my site that i am developing . When I insert special characters string like thi's ~!@#$%^&*()_+| the code is unable to convert it into right image with all text on it when the chosen font in trajanpro.ttf, but when I change the font with Ariel it work's fine. If anyone want to check this problem then you can check at this link http://www.centralstationery.com/produc ... ate_id=231 Click the text on card and a pop up will open and then change the font to Ariel then the image on card will be converted into right text. The code is imageSaveAlpha($image, true); ImageAlphaBlending($image, false); $bgcolor = imagecolorallocate($image, 200, 200, 200); $transparentColor = imagecolorallocatealpha($image, 200, 200, 200, 127); imagefill($image, 0, 0, $transparentColor); // pick color for the text $fontcolor = imagecolorallocate($image, $red, $grn, $blu); // fill in the background with the background color imagefilledrectangle($image, 0, 0, $width, $height, $transparentColor); $x = 0; $y = $fontsize; imagettftext($image, $fontsize, 0, $bx, $by, $fontcolor, $font, $quote); $final_image=DIR_USER_EDITOR.$new_image; // output image to the browser imagepng($image, $final_image); // delete the image resource imagedestroy($image); Thanks in advance Hi I'm creating a program that creates an image from an input using imagettftext(). Is there a way I can force a new line if the text exceeds the permitted image width? Thanks in advance Ste Well, I have been tryna figure this out for days but it wont seem to work. The base image appears fine but it wont write the text or the avatar on it. Code: [Select] <?php //Do Not Cache header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); //Getting Variables $user = "Dusaro"; $rank = "Administrator"; $a = "0"; if(isset($_GET['a'])) { if(!empty($_GET['a'])) { $a = $_GET['a']; } } if(isset($_GET['u'])) { if(!empty($_GET['u'])) { $user = $_GET['u']; } } if(isset($_GET['r'])) { if(!empty($_GET['r'])) { $rnk = $_GET['r']; } else{$rnk='Administrator';} } else{$rnk='Administrator';} if(isset($_POST['u'],$_POST['r'],$_POST['a'])) { if(!empty($_POST['u'])) { $user=$_POST['u']; } if(!empty($_POST['r'])) { $rnk = $_POST['r']; } if(!empty($_POST['a'])) { $a = $_POST['a']; } } //Setting up Image $image = imagecreatefrompng("base.png"); $avatar = imagecreatefrompng($a.".png"); $font = "US101.TTF"; imagecopymerge($image, $avatar, 0, 0, 0, 0, 100, 100, 100); $color = imagecolorallocate($image, 0,0,0); ImageTTFText ($image, "15", 0, 230, 0, $color, $font,$user); ImageTTFText ($image, "14", 0, 257, 96, $color,$font,$rnk); //Displaying Image header("Content-type: image/png"); imagepng($image); imagedestroy($image); imagedestroy($avatar); ?> can any1 help?
I need to draw various font sizes onto a canvas to create a web service. Wanting to protect my HD assets, the intent is to use PHP to populate the image with the necessary text, and then scale down the image before presenting it to the user. <?php $img = imagecreatetruecolor(750, 530); $black = imagecolorallocate($img, 0, 0, 0); $gray = imagecolorallocate($img, 125, 125, 125); $white = imagecolorallocate($img, 255, 255, 255); $font = realpath('../fonts/micross.ttf'); $size = 12; $spacing = 20; for ($x = 0; $x <= 25; $x++) { $box = imageftbbox($size + $x/10, 0, $font, "The longer the phase the more apparent the size difference should be"); $boxWidth = $box[2] - $box[0]; imagefilledrectangle($img, 5, $x*$spacing+5, $boxWidth+5, ($x+1)*$spacing+5, $gray); imagefttext($img, $size + $x/10, 0, 5, $spacing*($x+1), $white, $font, "The longer the phase the more apparent the size difference should be Font Size ".($size+($x/10))); } imagejpeg($img); imagedestroy($img); ?> You can see how despite the font size steadily increasing by 0.1, it sporadically jumps at what seem at first like random intervals, however if you increase the number of loops and log the data, you can see that it alternates between increasing every 0.7, and 0.8. Unfortunately that doesn't help me any, just some insight. if($last != $boxWidth) { $last = $boxWidth; echo $boxWidth." ".($size+($x/10))."<br>"; }
This outputs the current width and font size each time the text width changes. Hi, I am creating an image with a random number to use as a capcha. I've done the image creation before and had it working but now I have a font path error. However......I know my font path is the same...I didn't change it and it was working perfectly. What I changed was I made the image creation piece of code into a function...so I could return a value and use the function as a capcha....can you not use this image creation stuff in a function? The difficulty is getting hold of the random number to verify someone typed it correctly. If you have any ideas I'm open to other methods. My code is: function capcha(){ $capchatxt = rand(10000,99999); $font = '/includes/balloon.ttf'; $textarray = imagettfbbox(30, 0, $font, $capchatxt); $width = $textarray[2]-$textarray[0]; $height = $textarray[3]-$textarray[7]; $image = imagecreate($width+10,$height+10); $background = imagecolorallocate ($image, 255,227,232); $colour = imagecolorallocate($image, 0, 154, 239); // blue; $pink = imagecolorallocate($image, 239, 0, 144); // crimson pink; $peach = imagecolorallocate($image, 255, 227, 232); // pale pink; // Add the text imagettftext($image, 30, 0, 5, $height+5, $pink, $font, $capchatxt); header('Content-type: image/png'); imagepng($image); imagedestroy($image); return $capchatxt; } At the moment: The function and the font file are in the same folder. The file which is calling the function is in a different folder. BTW - Forgot to mention that right now I'm using localhost (xampp)...not a real server. Thanks for the help. IceKat Hi.., I use below method to export data to excel. header('Content-type: application/ms-excel'); header('Content-Disposition: attachment; filename=abc.xls'); if I run the script from the server. (http://localhost/export.php) it is work. (pop-up window if i want save or open the file) but if i run the script from the client (http://192.168.1.5/export.php) it is not work. (nothing happen) any idea how to solve this? This one requires lots of up front information: I have a page, for this example that I will call page.php. It takes get parameters, and for this example I'll call the parameter "step". So I have a URL like this: page.php?step=1 This page has a form with an action of page.php?step=1. The code on the page validates the posting information. If the information is bad, it returns the user to page.php?step=1; if it is good, it takes the user to page.php?step=2 via header( "location:page.php?step=2" ). So redirection is done by relative path, not full URLs. This all works as expected. Now what I've done is set .htaccess to be HTTPS for this page, via this code: # Turn SSL on for payments RewriteCond %{HTTPS} off RewriteCond %{SCRIPT_FILENAME} \/page\.php [NC] RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] This works (initially). However, once you try to post the form, it just redirects back to the step=1 version of the page. I really don't know how or why that would be. I'm not sure how else I can explain this or what other information you may have. But it's frustrating to not get a page working in HTTPS that works in HTTP. Very odd. Any suggestions? (I don't even really know the best location to figure out when/why it's redirecting back to the original page.) require_once 'includes/upload.class.php'; $upload = new uploads(); $details = $upload->getFileInformation($id); <?php echo $details['upload_desc']; ?> then here the class. require_once 'db.class.php'; class uploads extends database { private $uploadData; function uploadFile() { public function getFileInformation($id) { $this->uploadData = $this->readData("uploadfiles", "upload_id", $id); return $this->uploadData; } But it wont work! Some of you may have seen one of my many posts about email issues. Some users don't get them, and I have determined it is probably because we are marked as spam.
We are a service that grades sales team members on their phone skills. Listening to pre-recorded calls, grading and uploading them to our site, and then another part of our business looks them over and sometimes leaves a message that then get's forwarded to this persons work email.
I have determined there is ways to get marked as spam as default by not having an opt out link. This is not an option, these sales members employer has opted in, and the emails are going to work related accounts hosted at that employer. Also, if one of these staff members is not so bright, or disgruntled they may mark us as spam anyways. The bottom line is that we have very little control over whether we are or are not marked as spam.
So we want to start looking into sending text messages and this is where I start to question how good of an idea this is.
First off, if it was me, and the messages where being sent to a device that my employer did not provide, I would in no way want work related text messages coming to me. Unless there is a vested interest in getting them. IE, I'm the boss at this place and am always on the clock. What if you are on the bottom? It's just a job for you.
What if it is a pre-paid device, text messages cost money. What then? What if they don't even have, or want a cell phone?
The short of it is this. If I'm at a job that is just another job, and this employer tells me that I have to get these messages. I'm going to look for another job. I see the organizations having continuous issues and complaints from their employees. Thus us as a business having issues keeping clients.
What am I getting into here? What are your opinions on this matter? What are your recommendations as to alerting users of something on our site that we can rest assured are being received 100% of the time?
Thanks!
Nick
i need help trying to get this delete feature to work its not deleting from the database (by the way i took out my database names and passwords at the top of the file) is it possible someone could help me, ive been working on this for like a week and cant figure out the problem. thanks! you can email me at spr_spng@yahoo.com picture 2.png is showing what it looks like Code: [Select] <?php $host="localhost"; // Host name $username="username"; // Mysql username $password="password"; // Mysql password $db_name="database_name"; // Database name $tbl_name="table_name"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <style> /*table affects look of the whole table look */ table { margin-left: auto; margin-right: auto; border: 1px solid #330000; border-collapse:collapse; width:70%; border-width: 5px 5px 5px 5px; border-spacing: 1px; border-style: outset outset outset outset; border-color: #330000 #330000 #330000 #330000; border-collapse: separate; background-color: #330000; #800517 f535aa #330000 school color #9A0000 school color2 #991B1E school color3 #CCCC99 school color4 #9A0000 } /*th is table header */ th { text-align: left; height: 2.5em; background-color: #330000; color: #FC0; font-size:1.5em; } /*td is table data or the cells below the header*/ td { text-align: left; height:1.0em; font-size:1.0em; vertical-align:bottom; padding:10px; border-width: 5px 5px 5px 5px; padding: 8px 8px 8px 8px; border-style: outset outset outset outset; border-color: #9A0000 #9A0000 #9A0000 #9A0000; background-color: #CCCC99; -moz-border-radius: 0px 0px 0px 0px; } </style> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td bgcolor="#FFFFFF"> </td> <td colspan="4" bgcolor="#FFFFFF"><strong>Pick Which Rows you want to delete, Then press delete.</strong> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td> <td align="center" bgcolor="#FFFFFF">delete</td></tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['name']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <? // Check if delete button active, start this // edited if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">"; } } mysql_close(); ?> </table> </form> </td> </tr> </table> Hi there, As the question says i tried several things but i can't work it out and my knowledge about php isn't that well. So I wanted to use a \ in order to stop PHP from registering my quotes. For some reason it does not seem to work. I am running PHP version 5.3.8. What am I doing wrong? Ok strange one. I have an image upload script. It works fine and the image uploads and puts its name in my database. I also then post the name to the next page. Here is the image uploader <?php if (isset($_POST['insert_image'])) { $folder = "../../images/image_box/"; move_uploaded_file($_FILES["photo"]["tmp_name"] , "$folder".$_FILES["photo"]["name"]) or die(mysql_error()); //connect to database include('../../Connections/database.php'); $photo = $_FILES["photo"]["name"]; $qInsert = "INSERT INTO `photos` (`photo_name`) VALUES ('".$photo."')"; $rInsert = mysql_query($qInsert) or die(mysql_error()); //Tells you if its all ok if ($rInsert) { $url = "add_image_to_album.php?image_name='".$photo."'" or die(mysql_error()); header("Location: ".$url.""); } else { $errors = "There was an error inserting the image into the database"; } } ?> Notice I then post the image name to the next page. Now on the next page I have only this <?php include('../../Connections/database.php'); session_start();?> <?php echo '".$_GET['image_name']."' ;?> But there is an error at line one but I have tested the connection and its fine so its erroring displaying for example; landscape.png Does it have something to do with the .png in the name? If so how do i solve this? Hello, I am trying to make this work. what i am trying to do is to make a function that changes a variable back and forth. for example, I need to have a variable $bgcolorplace that is set to 1, as soon as the function is executed the variable $bgcolorplace changes to 0. The next time the function executes, variable should turn to 1 again. This pattern should repeat forever only when the function is executed. I am trying to use this to change the background color of a generated HTML code which will be on the webpage. Here is my script. <?php $input=($_GET['inputText']); //get info from JS $ItemNum='Item'.$input; //make a var with contents "Item" + the info from JS to display later $bgcolorplace; //var that keeps track of what color to make the next background $bgcolor; //keeps the color of the background for this execution function changebgcolor(){ if ($bgcolorplace=="0"){ $bgcolorplace="1"; //$bgcolor="444444" echo("0 to 1<br/>".$bgcolorplace."<br/>");//display which part of code is executed 1 to 0 or 0 to 1(can never get the script to run this part), this line is temp/test code }else{ $bgcolorplace="0"; //$bgcolor="ffffff" echo("1 to 0<br/>".$bgcolorplace."<br/>"); //display which part of code is executed 1 to 0 or 0 to 1(It works), this line is temp/test code } } //this next section I have temporarily commented for testing purposes, this section works fine /*$out="<tr bgcolor=#'".$bgcolor."' id='".$input."'><td align='center' width='5%'>".$input."</td><td align='center' width='30%'>bible</td><td align='center' width='50%'>Softcover</td><td align='center' width='5%'>45</td><td align='center' width='5%'>1</td><td align='center' width='5%'>45</td></tr>";*/ if ($input=='123'){ changebgcolor(); //echo($out); }else{ echo('none'); } ?> I get a responds of this everytime 1 to 0 1 this means that the function is being processed, but the value of $bgcolorplace is always a 1, it never changes to 0 like I am trying to inside the IF Else Statement. The commented Items are just my code that I have temp disabled while I try to figure out why my IF Else statement doesnt work. Help is much appreciated, and thank you in advanced. hi all, i have been struckling with this code of mine i want when i click a link to change the setting for the menu (see code) Code: [Select] <? echo "[".$_SESSION['menu']."]"; ?> <table class="border_test"> <tr> <td valign="top" align="left"> <!-- menu items: menu --> <img src="../design/item.png" width="10" height="10"><a href="<?=$_SERVER['REQUEST_URI'];?>" onclick="<? $_SESSION['menu']=1;?>"><b> Site menu:</b></a> </td> </tr> <? if($_SESSION['menu']==1) { echo ' <tr> <td> <img src="../design/subitem.png" width="10" height="10"> <a href="?topic=add_menu">Toevoegen menu item.</a><br> <img src="../design/subitem.png" width="10" height="10"> <a href="?topic=edit_menu">Bewerken menu item.</a><br> <img src="../design/subitem.png" width="10" height="10"> <a href="?topic=del_menu">Verwijderen menu item.</a> </td> </tr>'; } ?> <tr> <td> <!-- menu items: submenu --> <img src="../design/item.png" width="10" height="10"><a href="<?=$_SERVER['REQUEST_URI'];?>" onclick="<? $_SESSION['menu']=2;?>"><b> Site submenu:</b></a> </td> </tr> <? if($_SESSION['menu']==2) { echo ' <tr> <td> <img src="../design/subitem.png" width="10" height="10"> <a href="?topic=add_submenu">Toevoegen submenu item.</a><br> <img src="../design/subitem.png" width="10" height="10"> <a href="?topic=edit_submenu">Bewerken submenu item.</a><br> <img src="../design/subitem.png" width="10" height="10"> <a href="?topic=del_submenu">Verwijderen submenu item.</a> </td> </tr>'; } ?> <tr> <td> <!-- menu items: Pagina's --> <img src="../design/item.png" width="10" height="10"><a href="<?=$_SERVER['REQUEST_URI']; ?>"><b> Pagina's:</b></a> </td> </tr> </table> so what it wil do is show the subitem list of the main menu item when de var is changed! butt when i use it it always set to the last ( in this case to: 2 ) even when i click the first link to set it to 1 can somebody help me to get it to work? thnx, |