broj1 356 Humble servant Featured Poster

Use the resize parameter of the image function to scale the image . See the documentation.

Something like:

// set the required parameters
$posX = 100;      // position x of the upper left corner 
$posY = 100;      // position y of the upper left corner 
$newWidth = 400;  // new width that you wish to scale to 
$newHeight = 300; // new height that you wish to scale to
$type = '';       // will be kept default
$link = '';       // will be kept default
$align = '';      // will be kept default
$resize = true;   // this will make the image resize

// add the scaled image
$pdf->image($name, $posX, $posY, $newWidth, $newHeight, $type, $link, $align, $resize);
broj1 356 Humble servant Featured Poster

You are welcome. Please mark the thread as solved. Happy coding.

broj1 356 Humble servant Featured Poster

And the comments and solutions are:

  1. In lines 2 and 3 there is no need to send the header. FPDF will take care of all.
  2. Before line 11 you should use a SetFont() FPDF method to set the font you wish to use
  3. On lines 24 and 25 you used mysql_query function twice, with errors in syntax
  4. On line 28 you used a nonexisting index 1 (only index 0 exists)
  5. Before line 30 you should again use SetFont() FPDF method (I think)
  6. I do not know where the values $row['id'] and $row['name'] come from. I ignored them. Make sure they exist. (credits also to pzuurveen)
  7. Make sure you can write to the current directory or add a parameter to the Output() method (like 'D' for Download)
  8. I do not know what is the point of line 30. Get rid of it. (credits also to pzuurveen)

The code that works for me is (a bit rearranged to be more clear):

<?php
$link=mysql_connect('localhost:3306','root','');
mysql_select_db('uploadimage');-
$query = "SELECT name FROM image1 WHERE id=1";
$result = mysql_query($query);
$row=mysql_fetch_row($result);
$name=$row[0];

require("fpdf.php");
class PDF1 extends FPDF
{
    // Page header
    function Header()
    {
        // Logo
        $this->SetFont('Arial','B',12);
        $this->Cell(0,10,'APPLICATION FORM FOR ADMISSION INTO MEDICAL PG DEGREE/DIPLOMA COURSES',0,0,'C');
        $this->Ln(6);
        $this->Cell(0,10,'UNDER MANAGEMENT QUOTA FOR THE ACADEMIC YEAR 2014-2015',0,0,'C');
        $this->Ln(6);
        $this->Cell(0,10,'-----',0,'C');
        // Line break
        $this->Ln(15);
    }
}

$pdf = new PDF1();
$pdf->AddPage();
$pdf->SetFont('Arial','',16);
$pdf->Image($name);
// $pdf->Cell(0,10,'id'.$row['id'],0,1);
// $pdf->Cell(0,10,'name'.$row['name'],0,1);
$pdf->Cell(0,10,'id',0,1);
$pdf->Cell(0,10,'name',0,1);
$pdf->Output("image.pdf", 'D');
?>

The code works provided that the image is present and the path to it is correct.

broj1 356 Humble servant Featured Poster

OK, I had a look at the files that you sent me. In this post I will post a file that is causing troubles. In next post I will describe the solutions. The troublesome script is:

<?php
header('Content-type: image/jpeg');
header('Content-type: application/pdf');
require("fpdf.php");
class PDF1 extends FPDF
{
    // Page header
    function Header()
    {
        // Logo
        $this->Cell(0,10,'APPLICATION FORM FOR ADMISSION INTO MEDICAL PG DEGREE/DIPLOMA COURSES',0,0,'C');
        $this->Ln(6);
        $this->Cell(0,10,'UNDER MANAGEMENT QUOTA FOR THE ACADEMIC YEAR 2014-2015',0,0,'C');
        $this->Ln(6);
        $this->Cell(0,10,'-----',0,'C');
        // Line break
        $this->Ln(15);
    }
}
$link=mysql_connect('localhost:3306','root','');
mysql_select_db('uploadimage');
$pdf = new PDF1();
$pdf->AddPage();
$query=mysql_query("select name from image1 where id=1");
$result = mysql_query($link, $query);

$row=mysql_fetch_row($result);
$name=$row[1];
$pdf->Image($name);
$pdf->Cell(0,10,'id'.$row['id'],0,1);
$pdf->Cell(0,10,'name'.$row['name'],0,1);
$pdf->Output(".pdf");
header('Location: '. ".pdf");
?>
broj1 356 Humble servant Featured Poster

I sent you a message 11 hours ago with my gmail email address. There is a menu on top of the forum page that says Private messages. Click on it and you will see my message.

broj1 356 Humble servant Featured Poster

I have already done that. Have a look at your personal messages.

broj1 356 Humble servant Featured Poster

Sory, I did not know this but it seems it is not possible. I sent you my email in a PM.

broj1 356 Humble servant Featured Poster

If you click on my avatar or name on the left side of the post you get to my profile page. Find a button there that says Send private message. I have just sent you a provate message so you can also just reply to it.

anis_1 commented: can i get your email? +0
broj1 356 Humble servant Featured Poster

You can zip the affected scripts and send them as a personal message to me here. Pease include the database structure and a few rows of data (export in sql format from phpmyadmin).

broj1 356 Humble servant Featured Poster

BTW, have you tried to ask the question on the fpdf forum?

broj1 356 Humble servant Featured Poster

First check if you got the path to the image correctly. Put this temporary debug code immediatelly after line 27 in your fpdf code:

die($name);

This will display the path to your image. Check it whether is OK. Please post it here.

broj1 356 Humble servant Featured Poster

If you have image path in the DB and the image stored in the filesystem, then it is easy:

First get the image path form the DB, i.e:

// establish a link to the database
$link = ...

// a query to read the path
$query = "SELECT imagePath FROM images WHERE imageId=$someImageId";)

// send the query
$result = mysqli_query($link, query);

// get the row
$row = mysqli_fetch_row($result);

// image path is the first (and the only) element of the $row array
$imagePath = $row[0];

Then assemble the PDF document and use the fpdf image method:

$pdf = new FPDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->Image($imagePath);
$pdf->Output();

For optional parameters for the image method see the FPDF manual.

For retrieving an image stores in a blob I did not have time to research. What was the method to store the binary data? Was it using a function file_get_contents? Was the data base64 encoded?

broj1 356 Humble servant Featured Poster

This is a bit tricky for me, I must admit :-). I have never used this approach. You could try sending the blob data base64 encoded to the Image method and see what you get. This is really a wild guess and I do not have time to try it right now. Maybe this link can help you: http://stackoverflow.com/questions/13225726/i-need-my-php-page-to-show-my-blob-image-from-mysql-database

I will give it a try tonight if I find some time. Meanwhile I hope other members with experience in this will be able help.

broj1 356 Humble servant Featured Poster

Is the image stored in a database (as a blob) or is it just a path to the image stored in the DB?

broj1 356 Humble servant Featured Poster
broj1 356 Humble servant Featured Poster

In real life nothing is 100% secure. But if you are opening access only for a short time (only for assessment), you should be quite safe. Nevertheless consider the following:

Your phpmyadmin should be configured securely: create a user for your teacher, grant him only the necessary privileges, allow him to access only from predefined IP address (or range).

Also mysql should be installed securely (I hope you ran mysql secure installation script).

Make sure your webserver is setup securelly, too. You can google for tips about that (i.e. if you are using XAMP google for xamp security).

Shut down unnecessary services, especially insecure ones (ftp, telnet...).

aVar++ commented: Ok, I will look into that. Thank you. +4
broj1 356 Humble servant Featured Poster

Many issues here:

  • database is a mysql reserved word so it is a bad idea to use it for the table name (and is missguiding also), but if you insist, enclose it in backticks
  • sending two queries is not necessary if you retrieve all data with the first one
  • escape all the values from $_REQUEST before using them in queries otherwise you risk an SQL injection attack: $username = mysql_real_escape_string($_REQUEST['username']);
  • better use $_POST and $_GET arrays instead of $_REQUEST since you already use GET and POST in the same script
  • check for existence of values before using them: if(isset($_REQUEST['username'])) ...
  • mysql database extension is very old, witch to mysqli or even better to PDO
broj1 356 Humble servant Featured Poster

First try to turn error_reporting to E_ALL and display_errors to on in the php.ini. Your script probably has some errors but the errors aren't displayed (just my guess).

Szabi Zsoldos commented: this is what i wanted to sugges also! :) +4
broj1 356 Humble servant Featured Poster

You are welcome. If the problem is solved please mark the thread as solved. Happy coding.

broj1 356 Humble servant Featured Poster

so i have add following line below my select query mysql_query('SET CHARACTER SET utf8');

It is actually a good piece of information for other people with similar problems. Please mark as solved (using the nick that opened the thread).

broj1 356 Humble servant Featured Poster

Will you post it (it might help someone else)?

broj1 356 Humble servant Featured Poster

Have you tried the htmlspecialchar function? Do you have any unescaped quotes in the text? Is it a html text? And why are you using two nicks?

broj1 356 Humble servant Featured Poster

Your question is not very clear about what exactly is the problem.

Is the text html? To display html use htmlspecialchars function which will safely display problematic characters (such as < and >). If you have different character sets use mb_encode_numericentity function instead.

If the text is plain text your only option for formatting is existence of escape sequences \t, \r, \n and some others.

The other thing you have to be careful is to not run out of memory on your server.

broj1 356 Humble servant Featured Poster

Your code has a few errors:

$amount= mysql_real_escape_string("£59.99");

echo $first= $amount[1];

    if( ($first=="$")||($first=="£") ) {
    $amount =substr($amount,1);
    $amount="£".$amount;
}
  1. do the escaping at the end
  2. first letter has index 0: $first= $amount[0];
  3. I advise you not to store the pound sign into the database. The money values should be stored as DECIMAL

So in my view the code should be:

$amount= '$59.99';
$first= $amount[0];

// ASCII 36 = dollar sign, ASCII 163 = pound sign
if( ($first == chr(36)) || ($first== chr(163)) ) {
    $amount = substr($amount,1);
}

// store this value in database
$safe_amount= mysql_real_escape_string($amount);
broj1 356 Humble servant Featured Poster

You can change the existing values in the database with a query like this:

UPDATE `test` SET amount = 
IF(
    SUBSTRING(`amount`, 1, 1) = '$', 
    CAST(SUBSTRING(`amount`, 2) AS DECIMAL(10,2)), 
    CAST(`amount` AS DECIMAL(10,2))
)

I am assuming that you have the amount column of type DECIMAL which I think is appropriate for money. You might have to create a temporary column if transformation can not be done in the same column.

broj1 356 Humble servant Featured Poster

It seems that the SQL statement the $sql variable does not get constructed properly. In the lines below you can see how it gets built up up to the VALUES part. But where are the actual values added to it then? Is there any more code you did not post?

Line  26: $sql = "INSERT INTO ".$table." (";
...
Line 205: $sql.= strtolower($column) . ",";
...
Line 208: $sql = rtrim($sql, ", ").", created_date ) VALUES ( ";
...

It is in the code that follows you should use the mb_substr function.

broj1 356 Humble servant Featured Poster

Have you tried the mb_substr function (see above post)?

broj1 356 Humble servant Featured Poster

I think in the database you should have only the number without any sign (provided that all the values are in same currency). You should get rid of the pound symbol i.e. using the mb_substr function, something like:

$trimmedAmount = mb_substr($amount, 1);

But I am not sure if this will work correctly since it depends on how the amount is read, what the encoding is and what the database column type for the amount is. Let me know the result.

broj1 356 Humble servant Featured Poster

Is there an attribute in the excel reader class that keeps the currency setting?

broj1 356 Humble servant Featured Poster

maybe the ajax part is playing up. Can you test it by inserting this between lines 31 and 32:

alert(data);

It should display an alert box with the html code for options.

You could also check the generated code for the subcategories dropdown with web developer add-on for Firefox (or similar dev tool).

If this is OK we'll go further.

broj1 356 Humble servant Featured Poster

Line 13:

<?php echo $op;?>

should probably create the html for options for the categories dropdown. But I can't find where $op is defined. Have you checked the generated code for the categoties dropdown?

broj1 356 Humble servant Featured Poster

Pass the above function the appropriate element of the array, containing the excel data. Maybe something like this:

$correctDate = reformatDate($this->spreadsheet_excel_reader->sheets[0]['cells'][1]['sale_date']);

I am just guessing this since I do not know the structure of the excel reader class.

broj1 356 Humble servant Featured Poster

If dates in Excel are formatted as dd/mm/yy (allways) you can use the following function on each date during the import or write to database:

function reformatDate($theDate) {

    // get the parts of the date
    $day = substr($theDate, 0, 2);
    $month = substr($theDate, 3, 2);
    $year = substr($theDate, 6, 2);

    // return the parts in different order and separated by dash
    return "$month-$day-$year";
}

[EDIT] or even better:

function reformatDate($theDate) {

    // explode date string into array
    $dateArr = explode('/', $theDate);

    // return string with reordered elements
    return "{$dateArr[1]}-{$dateArr[0]}-{$dateArr[2]}";
}
broj1 356 Humble servant Featured Poster

OK, how is the date written in Excel and how you want to have it written in mysql? Post an example if possible.

broj1 356 Humble servant Featured Poster

Hang on. You said in your previous post that you have data in mysql table which you want to update, or have I missunderstood the question.

So do you want to update a row in an excel sheet? I do not hink you could do that. You have to read in the whole file, find the row to change and write the whole file back, as far as I know. But I could be werong so maybe anyone else knows?

broj1 356 Humble servant Featured Poster

I just need to update only the date field curresponding customer account number.

Where do you get the customer account number from?

broj1 356 Humble servant Featured Poster

Use UPDATE ... WHERE ... syntax. If you want more detailed help post the code you already have and be as specific as possible with your question.

Read this.

broj1 356 Humble servant Featured Poster

Unfortunately it is not enough just change mysql_* commands to mysqli_*. There are minor differences. For example mysql_query takes first parameter the query and optional second the link while mysqli_query takes the first parameter link (must be present) and second the query. I suggest you check the syntax of each command on php.net. And be aware that mysqli_* has and object oriented API as well as procedural. You probably want to start with procedural.

So in your case:

<?php
   include 'connect.php'; // assuming that link identifier is stored in $link
   //populate form dropdown box
   $op = '';
   $r = mysqli_query($link, "SELECT cat_id, category FROM categories ORDER BY cat_id");
   if (mysqli_num_rows($r)){
      while ($d = mysqli_fetch_assoc($r)){
         $op .= "\n\t<option value='{$d['cat_id']}'>{$d['category']}</option>";
      }
   }
?>
broj1 356 Humble servant Featured Poster

(headers_send()) wasn't working for me.
gave an error(white page)

If you only get a blank page when in error then first turn on error reporting and display of errors in php.ini. This would have helped in first place.

broj1 356 Humble servant Featured Poster

Also make sure function.php script does not send output too early.

broj1 356 Humble servant Featured Poster

Line 48 is incorrect:

if(headers_send)

It should be:

if((headers_sent())

See headers_sent function reference.

broj1 356 Humble servant Featured Poster

First remove all the echo statements in the code since they send output too early. Some of them are not needed at all (since they are positioned after the redirection should happen). If this does not work check teh included scripts (or post them here). If you post the database connection script here, do not forget to remove password and other confidential data.

broj1 356 Humble servant Featured Poster

So can you remove the output before the header function? If not sure, post the scripts.

broj1 356 Humble servant Featured Poster

You make sure no HTML output has been sent before any header() function. You can achieve that in several ways:

  1. make sure no html is before header() functions
  2. make sure no single space (or whitespace chars) is outside <?php ?> tags before header() functions
  3. make sure no HTML output or white space is in included files function before header() functions

If sending an output before header() functions can not be avoided, use output buffering.

broj1 356 Humble servant Featured Poster

Then let's try if headers have already been sent:

if(headers_sent()) {
    die('Headers have already been sent, you can not send them again.');
}

if($status == 1) {
die('location: index.php?user='.$user.'');
//header('location: index.php?user='.$user.'');
} else {}
broj1 356 Humble servant Featured Poster

so if i see this correctly i have to print somethign for the value to become 1 and not stay empty or whatever.

No, this was just a test. It might be that the location header is not getting the correct address or maybe some output has been sent before it (which prevents header for being sent). Remove the above debug code and try this:

if($status == 1) {
    die('location: index.php?user='.$user.'');
    //header('location: index.php?user='.$user.'');
} else {}

and check if the correct location string has been constructed and displayed.

broj1 356 Humble servant Featured Poster

Are you sure the query returns 1? Test it with some code like:

if($status == 1) {
    die('Status is obviously 1');
    // header('location: index.php?user='.$user.'');
} else {
    die('Status is actually ' . print_r($status, 1));
}
broj1 356 Humble servant Featured Poster

The isset() function returns TRUE or FALSE. You probably wanted it this way:

if(isset($_GET['_rp']) && $_GET['_rp'] == 1)
...
elseif(isset($_GET['_rp']) && $_GET['_rp'] == 2)
...
broj1 356 Humble servant Featured Poster

If you resize your window width below about 970 px the horizontal scrollbar appears. This is usually set using min-width css property on container div element.

broj1 356 Humble servant Featured Poster

On each click of a button the form gets submitted with only one value. You'd be better off putting checkboxes next to each image (and only one submit button) and then check the array of checked ckeckboxes to produce the IN condition. Just an idea.