PHP - Barcode Generation
Similar Tutorialsso I have this code that makes a barcode: Code: [Select] <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ www.flashbuilding.com -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM members WHERE userid='$userid' LIMIT 1"); while($row = mysql_fetch_array($sql)){ $name = $row['name']; $phone = $row["phone"]; $username = $row["username"]; $address = $row["address"]; $city = $row["city"]; $state = $row["state"]; $zip = $row["zip"]; $cell = $row["cell"]; $email = $row["email"]; $accounttype = $row["accounttype"]; $rank = $row["rank"]; $badges = $row["badges"]; } $sql = mysql_query("SELECT * FROM Events WHERE userid='$userid' && eventid=".$_GET['eventid'].""); while($row = mysql_fetch_array($sql)){ $price1 = $row['price1']; $price2 = $row["price2"]; $price3 = $row["price3"]; $price4 = $row["price4"]; $price5 = $row["price5"]; $price6 = $row["price6"]; $price7 = $row["price7"]; $price8 = $row["price8"]; $title1 = $row['title1']; $title2 = $row['title2']; $title3 = $row['title3']; $title4 = $row['title4']; $title5 = $row['title5']; $title6 = $row['title6']; $title7 = $row['title7']; $title8 = $row['title8']; $barcode1 = $row['barcode']; } $total = $price1 + $price2 + $price3 + $price4 +$price5 + $price6 + $price7 + $price8; require('fpdf.php'); class PDF extends FPDF { function EAN13($x=1, $y, $barcode, $h=16, $w=.35) { $this->Barcode(13,200,$barcode,$h,$w,13); } function UPC_A($x, $y, $barcode, $h=16, $w=.35) { $this->Barcode($x,$y,$barcode,$h,$w,12); } function GetCheckDigit($barcode) { //Compute the check digit $sum=0; for($i=1;$i<=11;$i+=2) $sum+=3*$barcode[$i]; for($i=0;$i<=10;$i+=2) $sum+=$barcode[$i]; $r=$sum%10; if($r>0) $r=10-$r; return $r; } function TestCheckDigit($barcode) { //Test validity of check digit $sum=0; for($i=1;$i<=11;$i+=2) $sum+=3*$barcode[$i]; for($i=0;$i<=10;$i+=2) $sum+=$barcode[$i]; return ($sum+$barcode[12])%10==0; } function Barcode($x, $y, $barcode, $h, $w, $len) { //Padding $barcode=str_pad($barcode,$len-1,'0',STR_PAD_LEFT); if($len==12) $barcode='0'.$barcode; //Add or control the check digit if(strlen($barcode)==12) $barcode.=$this->GetCheckDigit($barcode); elseif(!$this->TestCheckDigit($barcode)) $this->Error('Incorrect check digit'); //Convert digits to bars $codes=array( 'A'=>array( '0'=>'0001101','1'=>'0011001','2'=>'0010011','3'=>'0111101','4'=>'0100011', '5'=>'0110001','6'=>'0101111','7'=>'0111011','8'=>'0110111','9'=>'0001011'), 'B'=>array( '0'=>'0100111','1'=>'0110011','2'=>'0011011','3'=>'0100001','4'=>'0011101', '5'=>'0111001','6'=>'0000101','7'=>'0010001','8'=>'0001001','9'=>'0010111'), 'C'=>array( '0'=>'1110010','1'=>'1100110','2'=>'1101100','3'=>'1000010','4'=>'1011100', '5'=>'1001110','6'=>'1010000','7'=>'1000100','8'=>'1001000','9'=>'1110100') ); $parities=array( '0'=>array('A','A','A','A','A','A'), '1'=>array('A','A','B','A','B','B'), '2'=>array('A','A','B','B','A','B'), '3'=>array('A','A','B','B','B','A'), '4'=>array('A','B','A','A','B','B'), '5'=>array('A','B','B','A','A','B'), '6'=>array('A','B','B','B','A','A'), '7'=>array('A','B','A','B','A','B'), '8'=>array('A','B','A','B','B','A'), '9'=>array('A','B','B','A','B','A') ); $code='101'; $p=$parities[$barcode[0]]; for($i=1;$i<=6;$i++) $code.=$codes[$p[$i-1]][$barcode[$i]]; $code.='01010'; for($i=7;$i<=12;$i++) $code.=$codes['C'][$barcode[$i]]; $code.='101'; //Draw bars for($i=0;$i<strlen($code);$i++) { if($code[$i]=='1') $this->Rect($x+$i*$w,$y,$w,$h,'F'); } //Print text uder barcode $this->SetFont('Arial','B',12); $this->Text($x,$y+$h+11/$this->k,substr($barcode,-$len)); } //Instanciation of inherited class $pdf=new PDF(); $pdf->AliasNbPages(); $pdf->AddPage(); //* here is part of barcode $pdf->EAN13(10, 120, $barcode1); $pdf->SetFont('Arial','B',12); $pdf->Output('ticket.pdf', 'I'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> </body> </html> How do I make it so that the bars still draw correctly, but they don't draw from the code, they draw from $barcode. or how do I put the value of $barcode into there.........currently it has to be a 8 digit $barcode and I believe 4-5 random numbers either on front or back. I want to be able to make $barcode have the value of an ean 13 barcode(which is how many numbers? 13 right?) and so that that is the only thing dictating barcode(I do know how to make it more numbers, but I cant do that because of the 5 random ones). does this make sense? Hello, I'm interested in hiring someone if it's too difficult but possible, or doing it myself if isn't too much work (I know basic php) which I doubt. I want that when I scan an item with my barcode pistol it automatically changes something in my page. I mean, I have a delivery system, so when the package arrive I want just to scan the barcode of the package and that automatically changes the status in the client area on my php site to "Ready". What are the requirements, and if I need to hire someone what would be the estimated reasonable price to pay. Thanks a lot. Best Regards Hi, I'm trying to run an api from upcdatabase.com. I works fine but some barcodes are 8digits or 13digits, i need those barcodes to be changed by adding in zero's if 8 or subtracting 1 zero if 13. It needs to do this before being sent to the sever. Your help is really appreciated this should be simple but has got be stumped i don't know where to even put the code... here's what i've got so far. THANKYOOUUU FOR YOUR TIME! <?php extract($_GET); if(isset($upc)) { ?> <form method="get" action="<?php print $_SERVER[PHP_SELF]; ?>"> <p><input type="text" name="upc" value=""/></p> <p><input type="submit" value="Search"/></p> </form> <?php require_once 'XML/RPC.php'; $rpc_key = 'c737eb5b608f31e5fa022718860f1578cf2cc2a6'; // Set your rpc_key here // Setup the URL of the XML-RPC service $client = new XML_RPC_Client('/xmlrpc', 'http://www.upcdatabase.com'); // Construct the entire parameter list (an array) for the call. // The array contains a single XML_RPC_Value object, a struct. // The struct is constructed from a PHP associative array, and each // value needs to be an XML_RPC_Value object. $params = array( new XML_RPC_Value( array( 'rpc_key' => new XML_RPC_Value($rpc_key, 'string'), 'upc' => new XML_RPC_Value($_REQUEST['upc'], 'string'), ), 'struct')); // Construct the XML-RPC request. Substitute your chosen method name $msg = new XML_RPC_Message('lookup', $params); $upc_count = count($upc); If ($upc_count == 7){ echo '0000'.$upc; } elseif ($upc == 13) { echo '000'.$upc; } else { echo 'incorrect number of digits'; } //Actually have the client send the message to the server. Save response. $resp = $client->send($msg); //If there was a problem sending the message, the resp will be false if (!$resp) { //print the error code from the client and exit echo 'Communication error: ' . $client->errstr; exit; } //If the response doesn't have a fault code, show the response as the array it is if(!$resp->faultCode()) { //Store the value of the response in a variable $val = $resp->value(); //Decode the value, into an array. $data = XML_RPC_decode($val); //Optionally print the array to the screen to inspect the values echo "<pre>" . print_r($data, true) . "</pre>"; echo '<p>'.$data['status'].'</p>'; echo '<p>'.$data['upc'].'</p>'; echo '<p>'.$data['description'].'</p>'; }else{ //If something went wrong, show the error echo 'Fault Code: ' . $resp->faultCode() . "\n"; echo 'Fault Reason: ' . $resp->faultString() . "\n"; } } else { ?> <p>Enter a 12 digit UPC Barcode</p> <form method="get" action="<?php print $_SERVER[PHP_SELF]; ?>"> <p><input type="text" name="upc" value=""/></p> <p><input type="submit" value="Search"/></p> </form> This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=316549.0 Hi guys, to compliment my ORM. On the multiple choice sheets which are scanned into images and then interpreted with the OMR thier is a barcode (like the ones on stuff you buy from the shops), this barcode contains digits to decide the layout of the sheet and how to run the OMR. How can I get PHP to read and understand the barcode. The barcode is originally generated by PHP and now I need PHP to read it and convert to numbers which then I run against mySQL db to enable the OMR to read correctly. If anyone can suggest a script or method or even a different way to tackle the issue it would be greatly appreciated. Thanks in advance. Hello, I use barcodegen.1d for php5 v2.2.0 to make barcodes, and works fine. I can show OK in html page with this code: <img alt="" src="image.php"> <br> barcodegen creates a png image (image.php). My question is: Exists a script to export the image "image.php" to "image.jpg" for example image.php <?php // Including all required classes require('class/BCGFont.php'); require('class/BCGColor.php'); require('class/BCGDrawing.php'); // Including the barcode technology include('class/BCGcode128.barcode.php'); // Loading Font $font = new BCGFont('./class/font/Arial.ttf', 18); // The arguments are R, G, B for color. $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $code = new BCGcode128(); $code->setScale(2); // Resolution $code->setThickness(30); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) $code->parse('122222222-adm-a'); // Text /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new BCGDrawing('', $color_white); $drawing->setBarcode($code); $drawing->draw(); // Header that says it is an image (remove it if you save the barcode to a file) header('Content-Type: image/png'); // Draw (or save) the image into PNG format. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); ?> A basic convert script from png to jpg: <?php // Quality is a number between 0 (best compression) and 100 (best quality) function png2jpg($originalFile, $outputFile, $quality) { $image = imagecreatefrompng($originalFile); imagejpeg($image, $outputFile, $quality); imagedestroy($image); } png2jpg("image.php","image.jpg", 100); //convert to jpg ?> But this didn't work, I've the error: Warning: imagecreatefrompng(): 'image.php' is not a valid PNG file in /var/www/barcodegen.1d-php5.v2.2.0/convertir.php Bye! and thanks Dear All, Below is a php file for my website invitacoach.com I need to issue passwords myself to members who have already paid up for my services...of which they will then be able to access the advantages of a members area which include Videos, Audios and other publications. Which part of my code am i to edit Below is the SQL and register.php code. SQL CREATE TABLE users ( userid int(25) NOT NULL auto_increment, first_name varchar(25) NOT NULL default '', last_name varchar(25) NOT NULL default '', email_address varchar(25) NOT NULL default '', username varchar(25) NOT NULL default '', password varchar(255) NOT NULL default '', info text NOT NULL, user_level enum('0','1','2','3') NOT NULL default '0', signup_date datetime NOT NULL default '0000-00-00 00:00:00', last_login datetime NOT NULL default '0000-00-00 00:00:00', activated enum('0','1') NOT NULL default '0', PRIMARY KEY (userid) ) TYPE=MyISAM COMMENT='Membership Information'; REGISTER.PHP <? include 'db.php'; // Define post fields into simple variables $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email_address = $_POST['email_address']; $username = $_POST['username']; $info = $_POST['info']; /* Let's strip some slashes in case the user entered any escaped characters. */ $first_name = stripslashes($first_name); $last_name = stripslashes($last_name); $email_address = stripslashes($email_address); $username = stripslashes($username); $info = stripslashes($info); /* Do some error checking on the form posted fields */ if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){ echo 'You did not submit the following required information! <br />'; if(!$first_name){ echo "First Name is a required field. Please enter it below.<br />"; } if(!$last_name){ echo "Last Name is a required field. Please enter it below.<br />"; } if(!$email_address){ echo "Email Address is a required field. Please enter it below.<br />"; } if(!$username){ echo "Desired Username is a required field. Please enter it below.<br />"; } include 'join_form.html'; // Show the form again! /* End the error checking and if everything is ok, we'll move on to creating the user account */ exit(); // if the error checking has failed, we'll exit the script! } /* Let's do some checking and ensure that the user's email address or username does not exist in the database */ $sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'"); $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'"); $email_check = mysql_num_rows($sql_email_check); $username_check = mysql_num_rows($sql_username_check); if(($email_check > 0) || ($username_check > 0)){ echo "Please fix the following errors: <br />"; if($email_check > 0){ echo "<strong>Your email address has already been used by another member in our database. Please submit a different Email address!<br />"; unset($email_address); } if($username_check > 0){ echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />"; unset($username); } include 'join_form.html'; // Show the form again! exit(); // exit the script so that we do not create this account! } /* Everything has passed both error checks that we have done. It's time to create the account! */ /* Random Password generator. http://www.phpfreaks.com/quickcode/Random_Password_Generator/56.php We'll generate a random password for the user and encrypt it, email it and then enter it into the db. */ function makeRandomPassword() { $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i = 0; while ($i <= 7) { $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $random_password = makeRandomPassword(); $db_password = md5($random_password); // Enter info into the Database. $info2 = htmlspecialchars($info); $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, info, signup_date) VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', '$info2', now())") or die (mysql_error()); if(!$sql){ echo 'There has been an error creating your account. Please contact the webmaster.'; } else { $userid = mysql_insert_id(); // Let's mail the user! $subject = "Your Membership at invitacoach.com!"; $message = "Dear $first_name, Thank you for registering at our website, http://www.invitacoach.com You are two steps away from logging in and accessing our exclusive members area. To activate your membership, please click he http://www.invitacoach.com/test/activate.php?id=$userid&code=$db_password Once you activate your membership, you will be able to login with the following information: Username: $username Password: $random_password Thanks! Invita Coach Hi guys, this is very urgent. Can anyone help me out..... I want to generate reports using php and MySQL. I have one table which includes customer_id, full_name, name_with_initials, address, contact_number and gender fields. I want to print the details of all the records of the table. It should be good if results will come on a PDF format. Thanks, Hi i am using a script to upload an image and resize it twice first to create the large image and then again to create a thumbnail. The large image is being created fine and is uploading ok. I'm using the following code to then make the thumbnail but it does not appear to be working ( well nothing is in the thumbnail image folder i expect it to be anyways) can anyone see anything obvious that i am doing wrong ? Many Thanks /////////////////////////// Create a Thumbnail of the Image //////////////////////////////////// list($width, $height) = getimagesize($upload_image); // this is the large image which has apready been uploaded $ratio = $height/$width; if($ratio >= '1') // portret { $ht_tmb = 150; $br_tmb = 150/$ratio; } else { // landscape $ht_tmb = 150*$ratio; $br_tmb = 150; } // create thumb $source = imagecreatefromjpeg($upload_image); // The large image already uploaded //--- resize uploaded file $resize = imagecreatetruecolor($br_tmb, $ht_tmb); imagecopyresized($resize, $source, 0, 0, 0, 0, $br_tmb, $ht_tmb, $width, $height); imagejpeg($resize, "gallery_images/small/" .$filenamefd); $image = imagecreatefromjpeg("gallery_images/small/" .$filenamefd); imagejpeg($image, "gallery_images/small/" . $filenamefd); // end of making thumb ///////////////////////////////////////////////////////////////////////////////////////////////// Hi all, sorry cos there is no code. please how can i generate pairs (in twos, threes, fours or five) from a given set of numbers. the numbers are to be typed in the form text field and when click generate(submit button) it brings out the pair of numbers. thanks in advance my form Code: [Select] <form id="form1" name="form1" method="post" action=""> <table width="100%" border="0" cellspacing="2" cellpadding="1"> <tr> <td width="21%">Input Numbers : </td> <td width="79%"><input name="numbers" type="text" id="numbers" size="50" /></td> </tr> <tr> <td> </td> <td><input name="generate" type="submit" id="generate" value="Generate" /></td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2"> </td> </tr> </table> </form> Hello everyone, I am interested in creating a site with similar capabilities to this one: http://www.inkpixi.com/item/Classic+University/A223/295/item.html On this site, enter your name name and hit "Preview". The artwork is created using your name as a variable and other parameters to define how the artwork looks. I have a bunch of variables and I want to generate images (dynamically) using these variables. Any ideas or suggestions on how they do this on InkPixi.com? Thank you in advance, Tim I have set this up with a form on another page so that they can generate a runescape stat signature, although there is something wrong, if they do not select a font it comes up with an error. Here is the Code: Code: [Select] <?php header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); $user = ""; $img = ""; $fnt = ""; if(isset($_GET['user'])) { if(!empty($_GET['user'])) { $user = $_GET['user']; } } if(isset($_GET['img'])) { if(!empty($_GET['img'])) { $img = $_GET['img']; } else{$img='blue';} } else{$img='blue';} if(isset($_GET['fnt'])) { if(!empty($_GET['fnt'])) { $fnt = $_GET['fnt']; } else{$fnt='arial';} } else{$img='blue';} if(isset($_POST['user'],$_POST['img'],$_POST['fnt'])) { if(!empty($_POST['user'])) { $user=$_POST['user']; } if(!empty($_POST['img'])) { $img = $_POST['img']; } if(!empty($_POST['fnt'])) { $fnt=$_POST['fnt']; } } //Skill Grabs $order = array("Overall", "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft", "Hunter", "Construction", "Summoning", "Dungeoneering"); $get = file_get_contents("http://hiscore.runescape.com/index_lite.ws?player=$user"); $get = explode("\n", $get); $i = 0; foreach ($order as $key => $value) { $value = strtolower($value); $temp = explode(",", $get[$i]); $temp = array("rank" => $temp[0], "level" => $temp[1], "exp" => $temp[2]); $stats[$value] = $temp; $eval = "\$$value = array(\$temp[\"rank\"], \$temp[\"level\"], \$temp[\"exp\"]);"; eval($eval); $i++; } //End Skill Grabs $image = imagecreatefrompng("http://slay2day.x10.mx/highscores/signatures/".$img.".png"); $font = "/fonts/".$fnt.".ttf"; $color = imagecolorallocate($image, 255,255,255); ImageTTFText ($image, "7", 0, 280, 10, $color, "/fonts/arial.ttf","Slay2day"); ImageTTFText ($image, "12", 0, 240, 55, $color, $font,$user); if(is_numeric($overall[0])) { if($overall[0]==-1) { ImageTTFText($image, "11", 0, 230, 105, $color, $font,"2000000+"); } else { ImageTTFText($image, "11", 0, 240, 105, $color, $font,$overall[0]); } } else { ImageTTFText($image, "11", 0, 230, 105, $color, $font,"2000000+"); } ImageTTFText ($image, "10", 0, 27, 20, $color, $font,$attack[1]); ImageTTFText ($image, "10", 0, 27, 42, $color, $font,$strength[1]); ImageTTFText ($image, "10", 0, 27, 64, $color, $font,$defence[1]); ImageTTFText ($image, "10", 0, 27, 88, $color, $font,$hitpoints[1]); ImageTTFText ($image, "10", 0, 27, 114, $color,$font,$ranged[1]); ImageTTFText ($image, "10", 0, 70, 20, $color, $font,$prayer[1]); ImageTTFText ($image, "10", 0, 70, 42, $color, $font,$magic[1]); ImageTTFText ($image, "10", 0, 70, 64, $color, $font,$cooking[1]); ImageTTFText ($image, "10", 0, 70, 88, $color, $font,$woodcutting[1]); ImageTTFText ($image, "10", 0, 70, 114, $color,$font,$fletching[1]); ImageTTFText ($image, "10", 0, 117, 20, $color, $font,$fishing[1]); ImageTTFText ($image, "10", 0, 117, 42, $color, $font,$firemaking[1]); ImageTTFText ($image, "10", 0, 117, 64, $color, $font,$crafting[1]); ImageTTFText ($image, "10", 0, 117, 88, $color, $font,$smithing[1]); ImageTTFText ($image, "10", 0, 117, 114, $color,$font,$mining[1]); ImageTTFText ($image, "10", 0, 162, 20, $color, $font,$herblore[1]); ImageTTFText ($image, "10", 0, 162, 42, $color, $font,$agility[1]); ImageTTFText ($image, "10", 0, 162, 64, $color, $font,$thieving[1]); ImageTTFText ($image, "10", 0, 162, 88, $color, $font,$slayer[1]); ImageTTFText ($image, "10", 0, 162, 114, $color,$font,$farming[1]); ImageTTFText ($image, "10", 0, 212, 20, $color, $font,$runecraft[1]); ImageTTFText ($image, "10", 0, 212, 42, $color, $font,$construction[1]); ImageTTFText ($image, "10", 0, 212, 64, $color, $font,$hunter[1]); ImageTTFText ($image, "10", 0, 212, 88, $color, $font,$summoning[1]); ImageTTFText ($image, "10", 0, 212, 114, $color,$font,$dungeoneering[1]); header("Content-type: image/png"); imagepng($image); imagedestroy($image); //Logging $url = getenv("HTTP_REFERER"); // connect to the database include('connect-db.php'); //variables date_default_timezone_set('Pacific/Auckland'); $datepickerbox = $_POST['datepickerbox']; $datepickerbox = date("Y-m-d H:i:s", time($datepickerbox)); echo $datepickerbox; // save the data to the database mysql_query("INSERT signature SET user='$user', img='$img', time='$datepickerbox', url='$url', font='$fnt'") or die(mysql_error()); //End Logging ?> if they do not have a font i get: Code: [Select] Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/slay2day/public_html/highscores/signatures/signature.php on line 130 but of they dont choose a font i want it to use arial... I'm looking for a function that creates a random string that contains random letters, numbers and symbols. Also it needs to generate it in a way that there are no repeating characters. Any ideas? I am in the process of trying to create a pedigree website (php/mysql)...
I want to be able to calculate a dog's inbreeding coefficient on 10 generations.
I am so not sure where to even begin.
I have a database table:
dogs:
Fields: id name sireid damid
equation:
FX = å [ (½) n1+n2+1 (1 + FA)]
http://www.highflyer...coefficient.htm
Can someone give me a starting point?
Do I need to learn bianary trees? could I do this with an array?
Thanks
Edited by Triple_Deuce, 20 November 2014 - 01:27 PM. Hi guys i am facing a problem in my php code and i dont know how to figure out so i search on google and i have started searching for a php forums and i found this community. The problem is i made three pages in page1 i create a simple form with one text field and add two buttons one name is "add more fields" and one is "submit" when i click on add more fields button a text field is generate by using javascript functions. Let say i create 3 fields and enter names and submit the form by having form action "page2" In page2 i just simply get all values i entered in fields and print them on screen and also there is a link of "page3" that says edit your information and the session is start. In "page3" i made changes to values and submit them again again. Its all working. But i i also want "add more fields" button in page3 so that i can generate more fields also on page3 and this this the point where i stucked and i didn't figure out how can i do this task to create add more fields button. Can you guys help me in this regard thanks. Page1 Code: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script> function addonemore() { var tot = document.getElementById('count').value; tot = parseInt(tot)+1; document.getElementById('count').value=tot; var newhtml = 'student '+tot+' <input type="text" name="val'+tot+'" id="val'+tot+'" /><br/>'; document.getElementById('mydiv').innerHTML += newhtml; } </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="page2.php" method="post" enctype="application/x-www-form-urlencoded"> student 1 <input type="text" name="val1" id="val1" /> <div id="mydiv"></div> <input type="button" id="addnew" name="addnew" value="Add more" onclick="addonemore()" /> <input type="submit" id="submit" name="submit" value="submit" /> <input type="hidden" name="count" id="count" value="1" /> </form> </body> </html> Page2 Code: Code: [Select] <?php session_start(); $_SESSION['count'] = $_REQUEST['count']; for($i=1;$i<=($_REQUEST['count']);$i++) { $html .= 'student '.$i.':'.$_REQUEST['val'.$i].'<br/>'; $_SESSION['val'.$i] = $_REQUEST['val'.$i]; } echo $html; echo "<br/><a href='page3.php'>click here to edit</a>"; ?> Page3 Code: Code: [Select] <html> <head> <script> function addonemore() { var tot = document.getElementById('count').value; tot = parseInt(tot)+1; document.getElementById('count').value=tot; var newhtml = 'student '+tot+' <input type="text" name="val'+tot+'" id="val'+tot+'" /><br/>'; document.getElementById('mydiv').innerHTML += newhtml; } </script> </head> <body> <?php session_start(); $html = '<form action="page2.php" method="post" enctype="application/x-www-form-urlencoded">'; for($i=1;$i<=($_SESSION['count']);$i++) { $html .= 'student '.$i.':<input type="text" name="val'.$i.'" id="val'.$i.'" value="'.$_SESSION['val'.$i].'" />'; } $html .='<input type="submit" id="submit" name="submit" value="submit" /><input type="hidden" name="count" id="count" value="'.$_SESSION['count'].'" /></form>'; echo $html; ?> <?php $html = '<form action="" method="post" enctype="application/x-www-form-urlencoded">'; $html .= '<input type="button" id="addnew" name="addnew" value="Add more" onclick="addonemore()" /></form>' ?> </body> </html> Well, I had this working perfectly until they stopped using a mysql database and started using a flatfile. What it should do: Grab data from the flatfile, trim the unwanted parts and set it in an array. With the received data display as an image. I am very confused about how I would do this. My current code: signature.php: Code: [Select] <?php //GET AND TRIM $fileName="accounts.txt"; $fileHandle = fopen($fileName,"r"); $filecontents = fread($fileHandle,filesize($fileName)); $exploded = explode(" ",$filecontents); $name=""; $balance=""; $accounts=array(); $num=0; for($i=0;$i<count($exploded);$i++) { $line = explode("\t",$exploded[$i]); for($a=0;$a<count($line);$a++) { if(trim($line[$a])=="player") { }elseif($line[$a]=="money") { }elseif($line[$a]=="type") { }elseif(trim($line[$a])=="{") { }else { $subline = explode("\r",$line[$a]); for($e=0;$e<count($subline);$e++) { if(trim($subline[$e])=="}") { } elseif(is_numeric(trim($subline[$e]))) { $balance=trim($subline[$e]); } else { $name=trim($subline[$e]); } if($name!=""&&$balance!="") { $temp=array($name=>$balance); $accounts[$num]=$temp; $num++; $name=""; $balance=""; } } } } } //Image Generation require_once('../func.inc.php'); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); $font = "minecraft.ttf"; $user=""; if(isset($_GET['u'])) { if(!empty($_GET['u'])) { $user = $_GET['u']; } } if(isset($_GET['i'])) { if(!empty($_GET['i'])) { $img = $_GET['i']; } else{$img='1';} } else{$img='1';} if(isset($_POST['u'],$_POST['i'])) { if(!empty($_POST['u'])) { $user=$_POST['u']; } if(!empty($_POST['i'])) { $img = $_POST['i']; } } if(in_array($user, $accounts)) { //Info Grabs $money = get_balance($user); //End Info Grabs } else { die("That is an invalid player."); } //Display Image $user = ucfirst($user); $image = imagecreatefrompng("images/".$img.".png"); $color = imagecolorallocate($image, 255,255,255); if ($_GET['i'] >= '8') { ImageTTFText ($image, "8", 0, 100, 13, $color, $font,"Name:"); ImageTTFText ($image, "8", 0, 138, 13, $color, $font,$user); ImageTTFText ($image, "8", 0, 240, 13, $color,$font,"Money:"); ImageTTFText ($image, "8", 0, 285, 13, $color,$font,"$".$money); } else { ImageTTFText ($image, "7", 0, 246, 10, $color, $font,"Spartan Universe"); ImageTTFText ($image, "12", 0, 130, 50, $color, $font,"Name:"); ImageTTFText ($image, "12", 0, 130, 96, $color,$font,"Money:"); ImageTTFText ($image, "12", 0, 185, 50, $color, $font,$user); ImageTTFText ($image, "12", 0, 198, 96, $color,$font,"$".$money); } //End Image Display header("Content-type: image/png"); imagepng($image); imagedestroy($image); ?> accounts.txt: Code: [Select] arkangel011 { type player money 23.47 } chemicalbacon { type player money 203.89 } func.inc.php Code: [Select] <?php function get_players() { $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("minecraft",$con); $query = "SELECT * FROM `lb-players` ORDER BY `lb-players`.`playername` ASC "; $res = mysql_query($query,$con); while($row = mysql_fetch_assoc($res)) { echo "<option value='".$row['playername']."'>".$row['playername']."</option>"; } } function is_valid_player($user) { $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("minecraft",$con); $query = "SELECT COUNT(playername) AS count FROM `lb-players` WHERE `playername` = '".$user."'"; $res = mysql_query($query,$con); $row = mysql_fetch_assoc($res); if($row['count']==1) { return true; } else { return false; } } function get_balance($name) { $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("iconomy",$con); $query = "SELECT * FROM `iconomy` WHERE `iconomy`.`username` = '".$name."'"; $res = mysql_query($query,$con); $row=mysql_fetch_array($res); //echo $row['balance']; mysql_close($con); return $row['balance']; } function update_economy() { $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("iconomy",$con); $fileName="accounts.txt"; $fileHandle = fopen($fileName,"r"); $filecontents = fread($fileHandle,filesize($fileName)); $exploded = explode(" ",$filecontents); $name=""; $balance=""; $accounts=array(); $num=0; for($i=0;$i<count($exploded);$i++) { $line = explode("\t",$exploded[$i]); for($a=0;$a<count($line);$a++) { if(trim($line[$a])=="player") { //unset($line[$a]); }elseif($line[$a]=="money") { //unset($line[$a]); } elseif($line[$a]=="type") { //unset($line[$a]); } elseif(trim($line[$a])=="{") { //unset($line[$a]); } else { //echo $line[$a]."<br>"; $subline = explode("\r",$line[$a]); for($e=0;$e<count($subline);$e++) { //echo $subline[$e]."<br>"; if(trim($subline[$e])=="}") { //unset($subline[$e]); } elseif(is_numeric(trim($subline[$e]))) { //echo $subline[$e]."<br>"; $balance=trim($subline[$e]); } else { //echo $subline[$e]."<br>"; $name=trim($subline[$e]); } if($name!=""&&$balance!="") { $temp=array($name=>$balance); $accounts[$num]=$temp; $num++; $name=""; $balance=""; } } } } } foreach($accounts as $account=>$balance) { foreach($balance as $name=>$dollar) { $query = "UPDATE `iconomy`.`iconomy` SET `balance` = '".$dollar."' WHERE `iconomy`.`username` ='".$name."'"; mysql_query($query,$con); //echo "Name: ".$name; //echo ": Balance: ".number_format($dollar,2); //echo "<br>"; } } } ?> Hello, I installed Tango on Windows 8, and successfully created the database on a MySQL server. But when I launch the start-db.bat script, I get the message C:\Program Files\tango\bin>start-db.bat main(): arrived omniORB: Warning: the local loop back interface (127.0.0.1) is the only address available for this server. Received a CORBA::Exception Tango exception Severity = ERROR Error reason = CANNOT_CONNECT_MYSQL Desc : Failed to connect to TANGO database (error = Can't connect to MySQL serve r on 'localhost' (10061)) Origin : DataBase::init_device() Exiting pleaaaaase help me to find this problem I'm praying there's a function somewhere out there that: generates a html form based on the fields of a particular table within a DB (namely mySQL) generates the appropriate form input based on the fields type or notes (ie. for field: avatar_img, it knows to generate a file input) uses the POST method to submit generates and submits SQL insert query to database In addition to that, a similar function that generates a form that allows the editing of records. It doesn't take too long to write these each time myself, but if there's a function that you provide the formname, database driver, table name, whether your form is to insert or edit, that would be quite nifty i think. ie. generateForm(addUser, mySQL, tUsers, insert) Seen any such thing? Many thanks. I have this little snippet of code that runs when a user updates their password: fetch_user_salt_new(): Code: [Select] function fetch_user_salt_new($length = 5) { $salt_a = ''; for ($i = 0; $i < $length; $i++) { $salt_a .= chr(vbrand(33, 126)); } return $salt_a; } Code: [Select] $salt = fetch_user_salt_new(); $salt_processed = mysql_real_escape_string($salt); Now, occasionally when a user changes their password (or anything that inserts the salt into the database, such as registration), the salt length stored in the database becomes 6 or 7 instead of 5. As in, 99% of salts are only 5 digits long, but some salts are longer... The longer salts normally have odd components, such as \', \", or \\ leading to salts increasing by 1 or 2 digits in length. My idea is that mysql_real_escape_string() is putting a \ in front of quotes which is not what I intended when adding that piece of code in. By adding mysql_real_escape_string() in, I intended for quotes (' or ") to not be factors affecting the Query. Prior to instituting mysql_real_escape_string(), a ' or " would close the query and mess up the insertion of the salt. (Original Topic: http://www.phpfreaks.com/forums/index.php?topic=356368.0 ) It seemed to work but not doesn't Any help is very appreciated, Mark |