Jump to content

analog

Members
  • Posts

    45
  • Joined

  • Last visited

    Never

Everything posted by analog

  1. The single quotes around the table names and columns should be backticks (`). Also should it be COUNT(*)? This should work: SELECT COUNT(*), `descriptors`.*, `plantae`.* FROM `descriptors` LEFT JOIN `plantae` ON (`descriptors`.`plant_id` = `plantae`.`plant_name`) WHERE `leaf_shape` LIKE '%$s1%' AND `leaf_venation` LIKE '%$s3%' AND `leaf_margin` LIKE '%$s4%' If the variables $s1, $s3 & $s4 are coming from user input make sure to use mysql_real_escape_string to avoid SQL Injection attacks.
  2. Yes, you can have multiple variables stored in a session. What you posted should work fine.
  3. The previous page stores it in the DB here: $sql = "REPLACE INTO Events (name, event, eventid, userid, title1, title2, title3, title4, title5, title6, title7, title8, email, id, price1, price2, price3, price4, price5, price6, price7, price8) VALUES('$name','$event','$eventid','$userid','$title1','$title2','$title3','$title4','$title5','$title6','$title7','$title8','$email','$id','$price1', '$price2', '$price3','$price4','$price5','$price6','$price7','$price8')"; So you should be able to just select it out of the DB on the next page. For the barcode: <?php // code to popualte $total, ect. here. class PDF extends FPDF { function EAN13($x, $y, $barcode, $h=16, $w=.35) { $this->Barcode($x,$y,$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)); } //Page header function Header() { global $name; global $total; // get the variable $name1 into the scope of this function //Logo //Arial bold 15 $this->SetFont('Arial','B',15); //Move to the right $this->Cell(70); //Title $this->Cell(0,0,'Please bring this to the next Scout Meeting',0,0,C); //Line break $this->Ln(20); $this->Cell(0,0,'',1,0); $this->Ln(20); $this->cell(50,10, 'Registrant:', 1,0); $this->cell(50,10, 'Events:', 1,0); $this->cell(50,10, 'Price:', 1,0); $this->Ln(10); $this->cell(50,10,$name, 1,0); $this->cell(50,10, $events, 1,0); $this->cell(50,10, $total, 1,0); } //Page footer function Footer() { //Position at 1.5 cm from bottom $this->SetY(-15); //Arial italic 8 $this->SetFont('Arial','B',; //Page number $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); } } //Instanciation of inherited class $pdf=new PDF(); $pdf->AliasNbPages(); $pdf->AddPage(); $pdf->EAN13(10, 120, '38927923'); $pdf->SetFont('Arial','B',12); $pdf->Output('ticket.pdf', 'I'); ?>
  4. Whats the problem with the barcode?
  5. Looks like the titles are stored in the database as title1, title2, ect. Dose this not work: <?php $sql = ("SELECT * FROM Events WHERE eventid='$eventid' && userid='$userid'"); $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $event = $row['event']; $startdate = $row['startdate']; $enddate = $row['enddate']; $description = $row['description']; $location = $row['location']; $subevent1 = $row['title1']; $subevent1 = $row['title2']; $subevent3 = $row['title3']; $subevent4 = $row['title4']; $subevent5 = $row['title5']; $subevent6 = $row['title6']; } if (!empty($subevent1)) { echo "<br/>$subevent1"; } if (!empty($subevent2)) { echo "<hr><br/>$subevent2" ; } if (!empty($subevent3)) { echo "<hr><br/>$subevent3"; } if (!empty($subevent4)) { echo "<hr><br/>$subevent4"; } if (!empty($subevent5)) { echo "<hr><br/>$subevent5"; } if (!empty($subevent6)) { echo "<hr> <br/>$subevent6"; } if (!empty($title7)) { echo "<hr><br/>$title7"; } if (!empty($title8)) { echo "<hr><br/>$title8"; } ?>
  6. Whats assigning the titles their value? To make a the barcode first store the random string in a variable and then save is in the database and then use one of the barcode addons for FPDF to make the barcode like: http://www.fpdf.org/en/script/script5.php
  7. If you set $ventid and $userid in the code you posted what is the error? To generate a random string: <?php <?php // from http://www.lost-in-code.com/programming/php-code/php-random-string-with-numbers-and-letters/ function genRandomString($length = 10) { $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; $string =''; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; } return $string; } $this->Cell(0,10,genRandomString(),0,0,'C'); ?>
  8. For event something like: To add a dollar to the front do: $this->cell(50,10, '$' . $total, 1,0);
  9. Could you not select that from the DB using the eventid?
  10. Dose: <?php echo '<a href="/ticket.php?eventid=' . $eventid . '">Download Ticket</a>'; ?> not work? If not what about: <?php var_dump($eventid); ?>
  11. Is the query definitely fetching the data? Where dose $eventid in the query get set? Try dumping the $row variable with var_dump like this: <?php $sql = mysql_query("SELECT * FROM Events WHERE userid='$userid' && eventid='$eventid'"); $row = mysql_fetch_array($sql); // don't need to loop since there should only be one result? var_dump($row); // dump all the rows data die(); //stop execution ?> Dose it show all the data?
  12. Why not have the code work out the total on the page with the PDF instead of the last one. If you need to do it on both then you will need to use the same code as the last page to calculate the total (maybe put the code into a function and call that from both pages). Alternatively you could store the total in the users session like you have their ID and then on the next page fetch it from the session or if it doesn't matter that they can change it, put the total it in the query string and get it from there.
  13. $name1 doesn't exist in the scope of the header function. You would need to either add it as a parameter (preferred) or add global $name1; to the top of the function. For more information see: http://php.net/manual/en/language.variables.scope.php <?php class PDF extends FPDF { //Page header function Header() { global $name1; // get the variable $name1 into the scope of this function //Logo //Arial bold 15 $this->SetFont('Arial','B',15); //Move to the right $this->Cell(70); //Title $this->Cell(0,0,'Please bring this to the next Scout Meeting',0,0,C); //Line break $this->Ln(20); $this->Cell(0,0,'',1,0); $this->Ln(20); $this->cell(100,20, 'Registrant:', 1,0); $this->cell(10,20, $name1, 1,0); } //Page footer function Footer() { //Position at 1.5 cm from bottom $this->SetY(-15); //Arial italic 8 $this->SetFont('Arial','B',; //Page number $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); } } //Instanciation of inherited class $pdf=new PDF(); $pdf->AliasNbPages(); $pdf->AddPage(); $pdf->SetFont('Arial','B',12); $pdf->Output(); die(); // Stop execution, don't want to load that HTML in a PDF document it would most likely corrupt it. ?>
  14. FPDF manual should help, According to it you change: $pdf->Cell(40,10,'Hello ' . $user); to: $pdf->Cell(80,10,'Hello ' . $user, 1); the 4th parameter is if to have a border around the text so setting it to 1 will make a border.
  15. You could have a link to a PHP file which would generate the PDF. Say you had a file with this in it: <?php //FPDF code require_once 'fpdf.php'; $user = $_GET['name']; $pdf=new FPDF(); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Hello ' . $user); $pdf->Output(); ?> It would create a PDF document saying Hello to whatever name you put in the query string.
  16. You could use the PHP PDF functions (http://php.net/manual/en/book.pdf.php) or if your host doesn't have them configured you could use FPDF (http://www.fpdf.org/) which is pure PHP. There are some examples on the FPDF website of how to create documents.
  17. $cupID is coming straight from the query string so if someone changed the query string value to "?cupID=0'; DROP TABLE cups" you would end up with a query like this: SELECT gameaccID, name, start, ende, typ, game, `desc`, status, checkin, maxclan, gewinn1, gewinn2, gewinn3 FROM cups WHERE ID = '0'; DROP TABLE cups // goodbye table cups To stop that happening you should use mysql_real_escape_string to escape all user input. So: $cupID = mysql_real_escape_string($_GET['cupID']); There is a better explanation here: http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php
  18. analog

    echo issue

    Oh I think I might get what you mean. Is it that you want to show: showing -> ascendent from 0 to 10000 then show: showing -> ascendent from 1 to 10000 on the same line of the command line output? Might not be a good explanation but try this and see if it's right: <?php $start = 0; $end = 1000; $last_line_lemgth = 0; echo 'showing -> ascendent from '; for($i=$start;$i<=$end;$i++) { echo str_repeat("\x08", $last_line_lemgth); //backspace char to clear last line echo "{$i} to {$end}"; sleep(1);// so can see it working $last_line_lemgth = strlen("{$i} to {$end}"); } ?>
  19. Shoutbox is susceptible to XSS attacks, it allows HTML to be entered. Just use htmlspecialchars on the messages and it should fix it. Another thing is if you register with ' in your name it doesn't complain about it being an invalid character until the form is submitted but it dose complain with spaces so might want to add it. Nice game though!
  20. Most likely it's the web browser (works in FF4, IE9 but not Opera). The only characters guaranteed to work in a URL are ASCII after that things can go strange. You would need to urlencode it before putting it in the URL either by using PHP or you can do it with a simple HTML form for people to enter and the browser will encode it. <?php echo '<a href="?word=' . urlencode('şüra') . '">şüra</a>'; ?> <form action="" method="get"> <input type="text" name="word" value="şüra" /> <input type="submit" value="Lookup user" /> </form>
  21. Is it outputting the question mark � or %F6? If its the question mark then it has been decoded (well looking at it it didn't need it) and it is most likely because you to correct charset. Try using this: <?php function to_utf8( $string ) { // From http://w3.org/International/questions/qa-forms-utf-8.html if ( preg_match('%^(?: [\x09\x0A\x0D\x20-\x7E] # ASCII | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 )*$%xs', $string) ) { return $string; } else { return iconv( 'CP1252', 'UTF-8', $string); } } echo to_utf8($_GET['word']); ?> From http://php.net/manual/en/function.urldecode.php first comment.
  22. LTRIM removes leading spaces and RTRIM removes trailing spaces. You can also use TRIM which removes both leading and trailing spaces. More information: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_trim To remove only leading spaces you could do: SELECT * FROM table WHERE LTRIM(CUST_KEY) = '95447' It might be faster to add the spaces to the search string instead of removing the spaces from the column depending on if you know how many to add. Is there a reason for storing the data with leading spaces?
  23. urldecode should be converting it back. Can you post the bit of code that is not working.
  24. You can use explode to split the string from the DB into an array of IDs at the spaces. Then use in_array on the array of ids to check if the pages id is in the list. <?php $ids = explode(' ', '17 23 32'); if(in_array($pagg->ID, $ids)) echo 'Page ID is in the ids list.'; else echo 'Page ID is not in the ids list.'; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.