
ivoilic
Members-
Posts
38 -
Joined
-
Last visited
Everything posted by ivoilic
-
Thanks PaulRyan your code worked perfectly! @Pickachu2000 Don't worry the serials are saved to a database and the newly generated ones are checked against the db.
-
So I wrote this code to generate a 12 character long serial number looking something like this: 123a-34se-sdf3 I am new to php and really bad at using loops. If some one could explain to me some method of repeating the action rather than having to copy and paste. $ser_num = array("1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"); $num1 = rand(0,count($ser_num)-1); $numf1 = wordwrap($ser_num[$num1],1,"\n", true); $num2 = rand(0,count($ser_num)-1); $numf2 = wordwrap($ser_num[$num2],1,"\n", true); $num3 = rand(0,count($ser_num)-1); $numf3 = wordwrap($ser_num[$num3],1,"\n", true); $num4 = rand(0,count($ser_num)-1); $numf4 = wordwrap($ser_num[$num4],1,"\n", true); $num5 = rand(0,count($ser_num)-1); $numf5 = wordwrap($ser_num[$num5],1,"\n", true); $num6 = rand(0,count($ser_num)-1); $numf6 = wordwrap($ser_num[$num6],1,"\n", true); $num7 = rand(0,count($ser_num)-1); $numf7 = wordwrap($ser_num[$num7],1,"\n", true); $num8 = rand(0,count($ser_num)-1); $numf8 = wordwrap($ser_num[$num8],1,"\n", true); $num9 = rand(0,count($ser_num)-1); $numf9 = wordwrap($ser_num[$num9],1,"\n", true); $num10 = rand(0,count($ser_num)-1); $numf10 = wordwrap($ser_num[$num10],1,"\n", true); $num11 = rand(0,count($ser_num)-1); $numf11 = wordwrap($ser_num[$num11],1,"\n", true); $num12 = rand(0,count($ser_num)-1); $numf12 = wordwrap($ser_num[$num12],1,"\n", true); $serial = ''.$numf1.''.$numf2.''.$numf3.''.$numf4.'-'.$numf5.''.$numf6.''.$numf7.''.$numf8.'-'.$numf9.''.$numf10.''.$numf11.''.$numf12.'';
-
Yeah problem solved i modified to the example you gave me to this: http://jsfiddle.net/kKNNE/14/ It's exactly what I need! THANKS!
-
So I have a series of textboxes and when any of the values are changed I want JS to apply some basic calculations to each and then display the sum. I can do this where it detects the change in one textbox, but I am not sure how to get it to detect a change in any of the textboxes other than copy and pasting the code and changing the id for each. $(document).ready(function()//When the dom is ready { $("#def").keyup(function() { //if theres a change in var def = $("#def").val(); var acc = $("#acc").val(); //Calculate Each Cost var def_cost = def * 5; var acc_cost = acc * 5; //Total Costs var points= Number(acc_cost) + Number(def_cost); //Display Costs in Span $("#pointspreview").html(points); }) });
-
Thanks scootstah you solution worked perfectly!
-
Hi I relatively new to PHP and I am having trouble solving this problem: I want to take the number the user has given and then enter it in this equation 100/(2^X). I can do this easily. However I also need to apply the same equation to every number less than the given (If the user enters 4 it must by applied to 3,2,1 as well) I can generate a list of numbers using the range() function: foreach (range(0, $users_number) as $number) { echo $number; } However I can't figure out how to apply the equation to each number. The next step is to get the total sum but given the values of the the others that's pretty easy.
-
Let me clarify the file is being saved as $serial$title.png. $serial is not a folder. There is no problem with that part of the code. The image gets saved but does no appear in the browser.
-
So I am trying to generate an image based off of a form filled out by the user. It generates the image which is saved to a folder but the image does not show up in the browser. However when I comment out the header there are no errors! Here is the message I get: "The Image: 'http:// localhost/whatever.php' cannot be displayed because it contains errors. Here is all of the code I included it all because I have no clue what is causing it. <?php require 'connect.inc.php'; require 'core.inc.php'; //Get all info from cardcrafter.php $title = $_REQUEST['title'] ; /* $desc = $_REQUEST['desc'] ; */ $cardart = $_REQUEST['cardart'] ; $atk = $_REQUEST['atk']; $def = $_REQUEST['def']; $acc = $_REQUEST['acc']; $hp = $_REQUEST['hp']; //$quo = ($desc == "") ? "" : "\""; //Serial Number Generation (Needs to be shortned with a function) $ser_num = array("1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"); $num1 = rand(0,count($ser_num)-1); $numf1 = wordwrap($ser_num[$num1],1,"\n", true); $num2 = rand(0,count($ser_num)-1); $numf2 = wordwrap($ser_num[$num2],1,"\n", true); $num3 = rand(0,count($ser_num)-1); $numf3 = wordwrap($ser_num[$num3],1,"\n", true); $num4 = rand(0,count($ser_num)-1); $numf4 = wordwrap($ser_num[$num4],1,"\n", true); $num5 = rand(0,count($ser_num)-1); $numf5 = wordwrap($ser_num[$num5],1,"\n", true); $num6 = rand(0,count($ser_num)-1); $numf6 = wordwrap($ser_num[$num6],1,"\n", true); $num7 = rand(0,count($ser_num)-1); $numf7 = wordwrap($ser_num[$num7],1,"\n", true); $num8 = rand(0,count($ser_num)-1); $numf8 = wordwrap($ser_num[$num8],1,"\n", true); $num9 = rand(0,count($ser_num)-1); $numf9 = wordwrap($ser_num[$num9],1,"\n", true); $num10 = rand(0,count($ser_num)-1); $numf10 = wordwrap($ser_num[$num10],1,"\n", true); $num11 = rand(0,count($ser_num)-1); $numf11 = wordwrap($ser_num[$num11],1,"\n", true); $num12 = rand(0,count($ser_num)-1); $numf12 = wordwrap($ser_num[$num12],1,"\n", true); $serial = ''.$numf1.''.$numf2.''.$numf3.''.$numf4.'-'.$numf5.''.$numf6.''.$numf7.''.$numf8.'-'.$numf9.''.$numf10.''.$numf11.''.$numf12.''; //$serial = '569B-U31Z-QOKW'; // array of random abilites (No longer needed for now) //$ability = array("When $title is spawned draw a card", "Any card damaged by $title is delt 1 damage every turn"); // generate a random number with range of # of array elements //$pos = rand(0,count($ability)-1); // get the ability and word wrap it //$ability_f = wordwrap($ability[$pos],40,"\n", true); $query="SELECT `serial` FROM `Cards` WHERE `serial`='$serial'"; $query_run=mysql_query($query); if(mysql_num_rows($query_run)>=1) { header('Location: cardcrafter.php'); } else { if ($title == ""){echo "Your card needs a name!";} else {if ($atk <=0 || $def <=0 || $acc <=0 || $hp <= 0) {echo "All skills need at least one skill point!";} else { //Calculate total points $points = $atk + $def + $acc + $hp; $user_id = getuserfield('id'); $username = getuserfield('username'); $query = "INSERT INTO `Cards` VALUES ('','".mysql_real_escape_string($user_id)."','".mysql_real_escape_string($title)."','".mysql_real_escape_string($cardart)."','".mysql_real_escape_string($serial)."','".mysql_real_escape_string($atk)."','".mysql_real_escape_string($def)."','".mysql_real_escape_string($acc)."','".mysql_real_escape_string($hp)."','".mysql_real_escape_string($username)."','')"; if($query_run = mysql_query($query)) { } else { echo mysql_error(); } // Load Template $image = imagecreatefrompng ( "../Card_Images/water.png" ); $filename = "../Art/eyebook.jpg"; // get new dimensions list($width, $height) = getimagesize($filename); $new_width = "638"; $new_height = "450"; // Resample $image_p = imagecreatetruecolor($new_width, $new_height); $art = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $art, 0, 0, 0, 0, $new_width, $new_height, $width, $height); //Merge Background with card art imagecopymerge($image, $image_p, 60, 130, 0, 0, 638, 450, 100); // Path to our font file $font = '../Joanna/MJoa'; $italic = '../Joanna/MJoaIta'; // pick color for the text $fontcolor = imagecolorallocate($image, 0, 0, 0); //Create Title imagettfbbox(35, 0, $font, $title); imagettftext($image, 35, 0, 40, 80, $fontcolor, $font, stripslashes($title)); //Create Description /*imagettfbbox(30, 0, $italic, $desc); imagettftext($image, 30, 0, 70, 700, $fontcolor, $italic, stripslashes(" $quo$desc$quo "));*/ //Create Ability (Not used as of game V3) //imagettfbbox(25, 0, $font, $ability_f); //imagettftext($image, 25, 0, 70, 700, $fontcolor, $font, stripslashes($ability_f)); //Points imagettfbbox(35, 0, $font, $points); imagettftext($image, 35, 0, 585, 80, $fontcolor, $font, $points); //HP imagettfbbox(50, 0, $font, $hp); imagettftext($image, 50, 0, 40, 1000, $fontcolor, $font, $hp); //Attack imagettfbbox(30, 0, $font, $atk); imagettftext($image, 30, 0, 150, 635, $fontcolor, $font, $atk); //Defense imagettfbbox(30, 0, $font, $def); imagettftext($image, 30, 0, 360, 635, $fontcolor, $font, $def); //Accuracy imagettfbbox(30, 0, $font, $acc); imagettftext($image, 30, 0, 560, 635, $fontcolor, $font, $acc); //Serial imagettfbbox(25, 0, $font, $serial); imagettftext($image, 25, 0, 150, 1000, $fontcolor, $font, stripslashes($serial)); // get new dimensions $imagewidth = 754; $imageheight = 1054; $final_width = "251"; $final_height = "351"; // Resample $image_f = imagecreatetruecolor($final_width, $final_height); imagecopyresampled($image_f, $image, 0, 0, 0, 0, $final_width, $final_height, $imagewidth, $imageheight); // output image to the browser header('Content-type: image/png'); imagepng($image_f, '../Cards/'.$serial.''.$title.'.png'); // delete the image resource imagedestroy($image); imagedestroy($art); imagedestroy($image_p); imagedestroy($image_f); }}} ?>
-
So I have this function which generates a random serial # that is 12 characters long. However I want to insert a dash every four characters like so: XXXX-XXXX-XXXX Any suggestions? <?php $serial1 = get_serial_num(12); //Serial # function function get_serial_num($number_cnt){ $ret_arr = array(); $serial = ""; $ser_num = array("1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"); for($i = 0; $i < $number_cnt; $i++){ $rand = rand(0,count($ser_num)-1); $val = wordwrap($ser_num[$rand],1,"\n", true); $serial .= $val; } return $serial; } echo ''.$serial1.''; ?> Warning: I am a bit noobish.
-
I tried your script and it did not work however I found this plug-in: http://www.mathachew.com/sandbox/jquery-autotab/ So I ended up getting what I needed and some. Thanks for all your help.
-
Sorry for being a noob but I just tried to figure out how to do that and completely failed. Would you please clarify?
-
So I have code for three text-boxes in a form: <input type='text' name='serial1' style="width:40px;" maxlength="4"> - <input type='text' name='serial2' style="width:40px;" maxlength="4"> - <input type='text' name='serial3' style="width:40px;" maxlength="4"> What I want to know is if there is anyway to make it so that after the user has typed the max # of characters in the first text box the cursor will automatically move to the next text-box.
-
YES it worked! Thanks so much. If it's not to much trouble can you tell me why that actually worked.
-
sorry i'm pretty new at this can you clarify
-
Ok so I have a form to submits to a .php file that creates an image. This works fine, but I also want the info from the form to be sent to MySQL database. The problem is that something in a script I "required" called core.inc.php is interfering and so no image is output. Here is core.inc.php: <?php ob_start(); session_start(); $current_file = $_SERVER['SCRIPT_NAME']; if(isset($_SERVER['HTTP_REFERER'])&&!empty($_SERVER['HTTP_REFERER'])) { $http_referer = $_SERVER['HTTP_REFERER']; } function loggedin() { if(isset($_SESSION['user_id'])&&!empty($_SESSION['user_id'])) { return true; } else { return false; } } function getuserfield($field) { $query="SELECT `$field` FROM `Users` WHERE `id`='".$_SESSION['user_id']."'"; if($query_run=mysql_query($query)) { if($query_result = mysql_result($query_run, 0, $field)) { return $query_result; } } } ?> Here is the code for the image creating .php file: <?php require 'connect.inc.php'; require 'core.inc.php'; $title = $_REQUEST['title'] ; $user_id = getuserfield('id'); $query = "INSERT INTO `---` VALUES ('".mysql_real_escape_string($title)."','".mysql_real_escape_string($user_id)."')"; $query_run = mysql_query($query); //There is some more code in here obviously, but it's irrelevant header('Content-type: image/png'); imagepng($image_f); imagedestroy($image_f) Can anybody give me some idea of what is conflicting or what I can do to fix it?
-
Thank you Mahngiel! Problem Solved!!!! :D :D :D
-
So basically I have two lines that generate an image from png and then preserve the transparency of said png. $bub1 = imagecreatefrompng ("Energy/$energy1b.png"); imageSaveAlpha($bub1, true); This works by itself when generating just this image. But when combined with another image: imagecopymerge($image, $bub1, 680, 40, 0, 0, 50, 50, 100); It fills in the back ground around the image and the transparency is not preserved. Why is this and how can i fix it?
-
Found a bit of code that solved my problem: // get the quote and word wrap it $quote = wordwrap($quotes[$pos],20); Im unsure what the 20 is actually the value of. Also it seems if you put in one line of text without spaces this method fails to work! HELP!
-
Can you give me an example or link or something. I am some what of a noob.
-
So basically I have text which appears on an image. $ability = "$title gets ability"; //Create Ability imagettfbbox(30, 0, $font, $ability); imagettftext($image, 30, 0, 70, 700, $fontcolor, $font, stripslashes($ability)); But the line of text is longer than the width of the area on the image it needs to fit in. How can I change this so it automatically starts a new line once it reaches the end of said area?
-
So basically do this for each input?
-
Ok so I wanted to send user input from a form in html send it through Ajax to a Php file, where it would then be messed around with some and output again (The last bit is not important). I have code for sending the info from Ajax to Php. However it is annoyingly long and requires I create a new function for each input. function allrun(){ meaningless = getmeaningless(); if (meaningless != null) { meaningless.open("GET", "Test.php?title=" +document.getElementById('title').value, true); meaningless.send(null); }} How can I collect all the inputs under one function to forward to php?
-
I also tried the second method and got this message: Warning: imagepng() [function.imagepng]: Unable to open 'img/sdfsa+MJoa.png' for writing: No such file or directory in /Library/WebServer/Documents/temp/test2.php on line 70 Here is the html file: <html> <head> <title>Ajax with jQuery Example</title> <script type="text/JavaScript" src="jquery.js"></script> <script type="text/JavaScript"> $(document).ready(function(){ $("#generate").click(function() { loadImage(); }); function loadImage(){ var inputString = $("#inputString").val(); var inputFont = $("#inputFont option:selected").val(); $("#image p").load("test2.php?text=" + inputString + "&font=" + inputFont) } }); </script> <style type="text/css"> #wrapper { margin-top: 30px; height: 50px; width: 600px; border: 1px solid black; text-align: center; } #image { padding-bottom: 80px; border-style: none; height: 100px; width: 600px; text-align: center; } </style> </head> <body> <center><div id="image"><p> </p></div> <div id="wrapper"> Engraved Text:<input size="30" id="inputString" type="text" /> Font:<select id="inputFont"> <option value="balmo">Balmoral</option> <option value="clar">Clarendon</option> <option value="curlz">Curlz</option> <option value="english">Old English</option> <option value="freehand">Freehand</option> <option value="greek">Greek</option> <option value="interlock">Interlocking Monogram</option> <option value="MJoa">Times</option> <!-- <option value="3">Cool Engraving</option> <option value="3">Cool Engraving</option> <option value="3">Cool Engraving</option> <option value="3">Cool Engraving</option> <option value="3">Cool Engraving</option> --> </select> <input type="submit" id="generate" value="Generate!"> </div> </center> </body> </html> Here is the php: <?php // VARIABLES ############################################################################ // The text to draw $text = $_GET['text']; //$text = 'poopie'; // Font File, don't need a slash if file is in same dir as php file $font = $_GET['font']; //$font = '1'; //size in PTS $size = 78; //Angle $angle = 0; //Width of Canvas $width = 500; //Height of Canvas $height = 200; //Text Bounding Box Dimensions $tb = imagettfbbox($size, $angle, $font, $text); /* Output of imagettfbbox is an array as follows: Array ( [0] => 0 // lower left X coordinate [1] => -1 // lower left Y coordinate [2] => 198 // lower right X coordinate [3] => -1 // lower right Y coordinate [4] => 198 // upper right X coordinate [5] => -20 // upper right Y coordinate [6] => 0 // upper left X coordinate [7] => -20 // upper left Y coordinate ) */ // Centering Function ##################################################################### // X Position Calculated by subtracting width of Text Bounding Box from total canvas width $posx = ceil(($width - $tb[2]) / 2); // Y Position Calculated by subtracting height of Text Bounding Box from total canvas height $posy = ceil(($height - $tb[5]) / 2); // Creating Image File $im = imagecreatetruecolor($width, $height); // State Colors available to Image File $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, $angle, $width, $height, $white); // Add the text imagettftext($im, $size, $angle, $posx, $posy, $black, $font, $text); // Usage of imagettftext() // array imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text ) // $file= "$text+$font.png"; imagepng($im, "img/$file"); imagedestroy($im); $imgloc= "img/$file"; echo "<img src=$imgloc>"; ?> I changed one of the fonts to use my font and I installed jquery. What is wrong here???
-
Thanks for the link PFMaBiSmAd I tried using some of the code from the link but I get the broken link symbol where the image should be (paper ripped in half). Here is the java/html: <head> <script language="javascript" type="text/javascript"> function ajaxFunction(){ var xmlHttp; try{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e){ // Internet Explorer try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("Your browser does not support AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.getElementById("response").innerHTML=xmlHttp.responseText; var img = document.createElement('img'); img.onload = function (e) { document.getElementById("imgHolder").width=this.width; document.getElementById("imgHolder").height=this.height; document.getElementById("imgHolder").src=this.src; } img.onerror = function(e){ alert("Error processing Image. Please try again.") } img.src = xmlHttp.responseText; } } sendVars="tx="+document.forms["myForm"]["txtTxt"].value; sendVars+="&fon=ARIAL.TTF"; sendVars+="&sz="+document.forms["myForm"]["txtSz"].value; sendVars+="&fg="+document.forms["myForm"]["txtFG"].value;; sendVars+="&bg="+document.forms["myForm"]["txtBG"].value;; xmlHttp.open("POST","Test.php",true); xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //include this for post or it won't work!!!! xmlHttp.send(sendVars); } </script> </head> <body> <form name="myForm"> text: <input type="text" name="txtTxt" /><br/> size: <input type="text" name="txtSz" /><br/> fg: <input type="text" name="txtFG" /><br/> bg: <input type="text" name="txtBG" /><br/> </form> <img src="" id="imgHolder"/> <a href="javascript:ajaxFunction()">Send!</a> </body> </html> Here is the php: <?php $id= ("imgHolder"); $tx=$_POST["tx"]; $fon=$_POST["fon"]; $sz=$_POST["sz"]; $fg=$_POST["fg"]; $bg=$_POST["bg"]; $pad=0; $imX=imagettfbbox($sz,0,$fon,$tx); //get bounding box for dimensions $imDim=imgSize($imX, 0); //run a function to get image size $im=imagecreate($imDim["w"], $imDim["h"]); //create new image $bgCol=hex2rgb($bg); //convert bg color from hex to rgb $bgColor=imagecolorallocate($im,$bgCol['r'],$bgCol['g'],$bgCol['b']); //allocate bg color $fgCol=hex2rgb($fg); //convert fg color from hex to rgb $fgColor=imagecolorallocate($im,$fgCol['r'],$fgCol['g'],$fgCol['b']); //allocate fg color imagettftext ($im, $sz, 0,0, imagesy($im)-$imDim["bl"], $fgColor, $fon, $tx); //print the text imagejpeg($im,$id.".jpg", 100); //create and save the image echo $id.".jpg"; //Return Id of pic to javascript //=============================================================================== function imgSize($bb, $pad){ //a function to interpret the bounding box info here. $imgDim=array("w"=>$w,"h"=>$h,"bl"=>$blOff); return($imgDim); } function hex2rgb($hex) { return array( 'r' => hexdec(substr($hex, 0, 2)), // 1st pair of digits 'g' => hexdec(substr($hex, 2, 2)), // 2nd pair 'b' => hexdec(substr($hex, 4, 2)) // 3rd pair ); } ?> What am I doing wrong!?!? :confused:
-
So I have been messing around with code that I got here: http://www.w3schools.com/ajax/ajax_aspphp.asp I am trying to change it up so it displays the image, here is the js file: // JavaScript Document function displaycard(str) { var xmlhttp; if (str.length==0) { document.getElementById("bla").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("bla").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","balancer.php"+str,true); //Confused what should go here xmlhttp.send(); } I still confused on parts of the code... I have this button at the end of my form <button type="button" onclick="displaycard(this.value)">Craft</button> I know there is a lot wrong with this. I was wondering if I could get some help with it. Any help at all would be amazing!!