Click to See Complete Forum and Search --> : Problem embedding php


Perfidus
04-19-2004, 05:45 AM
I'm tryng to insert some PHP in the middle of a Html document, but it gets broken for some reason in a way that you can see the PHP in the middle of the html.
The "<?" seems to stop workin when "&&" come in the PHP code.

if($maxheight > 0 && $height2 > $maxheight) {

crh3675
04-19-2004, 06:50 AM
Can you post more of the code please.

Perfidus
04-19-2004, 07:12 AM
HERE IS ALL THE CODE:

<?
$link = mysql_connect('mm', 'mm', 'mm');
mysql_select_db("mm",$link2);
$result = mysql_query("SELECT * FROM fotos", $link);
$num_rows = mysql_num_rows($result);
$numref = ("$num_rows"+5000);
$iniciales = "rkf";
$Ref =$iniciales.$numref;
while(true){
$sql = mysql_query("SELECT * FROM fotos WHERE ref= '$Ref'");
$Ref =$iniciales.($numref++);
if(mysql_num_rows($sql) == 0){
break;
}
}
$msg = "";
switch(!strcasecmp($_SERVER['REQUEST_METHOD'], "POST")) {

case true:

if(!isset($_FILES['image']) || $_FILES['image'] == "none" || $_FILES['image'] == "") {
$msg = "<font color='#0000FF' size='1' face='Arial, Helvetica, sans-serif'>Seleccione sus fotografías pulsando -Examinar-</font>";
break;
}

$tmp = getcwd()."/".$_FILES['image']['name'];

if(!@move_uploaded_file($_FILES['image']['tmp_name'], $tmp)) {

$msg = "<font color='#0000FF' size='1' face='Arial, Helvetica, sans-serif'>Ha ocurrido un error al subir la imagen</font>";
break;
}

$fp = fopen($tmp, "rb");
$str = fread($fp, filesize($tmp));

fclose($fp);
unlink($tmp);

$im1 = ImageCreateFromString($str);

$imgname = $Ref."thumb_1"; // Nombre imagen (se podría indicar desde el formulario)
$maxwidth = 300; // Ancho máximo
$maxheight = 150; // Alto máximo

$width1 = ImageSX($im1);
$height1 = ImageSY($im1);
$width2 = $maxwidth;
$height2 = floor(($width2 * $height1) / $width1);

if($maxheight > 0 && $height2 > $maxheight) {

$height2 = $maxheight;
$width2 = floor(($height2 * $width1) / $height1);
}

$im2 = ImageCreateTrueColor($width2, $height2);
ImageCopyResampled($im2, $im1, 0, 0, 0, 0, $width2, $height2, $width1, $height1);

ImageJpeg($im2, "thumb/".$imgname.".jpg"); // Se copia en temp/
$msg = "Ok";
$im3 = ImageCreateFromString($str);

$imgname2 = $Ref."_1"; // Nombre imagen (se podría indicar desde el formulario)
$maxwidth2 = 800; // Ancho máximo
$maxheight2 = 250; // Alto máximo

$width12 = ImageSX($im3);
$height12 = ImageSY($im3);
$width22 = $maxwidth2;
$height22 = floor(($width22 * $height12) / $width12);

if($maxheight2 > 0 && $height22 > $maxheight2) {

$height22 = $maxheight2;
$width22 = floor(($height22 * $width12) / $height12);
}

$im4 = ImageCreateTrueColor($width22, $height22);
ImageCopyResampled($im4, $im3, 0, 0, 0, 0, $width22, $height22, $width12, $height12);

ImageJpeg($im4, "full/".$imgname2.".jpg"); // Se copia en temp/

break;
}
header("Location: newinsert.php?pos=".$pos."&color=".$color."&ref=".$Ref.");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

</body>
</html>

crh3675
04-19-2004, 08:18 AM
Your switch statement is used in a bizarre way. You have one instance of a "case" declaration and then just post code. You then have multiple "break" statements throughout. All that "break" will do is "break" out of a switch or for-loop, not terminate processing completely. Your "break" actually tells the script to exit the switch statement. So in short, don't use break unless you need to exit the switch statement.

Perfidus
04-19-2004, 12:18 PM
I have remove all the "break;" and it doesn't work neither.
Failure always comes after the "&&":

<?php
$link = mysql_connect('mm', 'mm', 'mm');
mysql_select_db("mm",$link2);
$result = mysql_query("SELECT * FROM fotos", $link);
$num_rows = mysql_num_rows($result);
$numref = ("$num_rows"+5000);
$iniciales = "rkf";
$Ref =$iniciales.$numref;
$sql = mysql_query("SELECT * FROM fotos WHERE ref= '$Ref'");
while(mysql_num_rows($sql) != 0){
$Ref =$iniciales.($numref++);
}
$msg = "";
switch(!strcasecmp($_SERVER['REQUEST_METHOD'], "POST")) {

case true:

if(!isset($_FILES['image']) || $_FILES['image'] == "none" || $_FILES['image'] == "") {
$msg = "<font color='#0000FF' size='1' face='Arial, Helvetica, sans-serif'>Seleccione sus fotografías pulsando -Examinar-</font>";break;

}

$tmp = getcwd()."/".$_FILES['image']['name'];

if(!@move_uploaded_file($_FILES['image']['tmp_name'], $tmp)) {

$msg = "<font color='#0000FF' size='1' face='Arial, Helvetica, sans-serif'>Ha ocurrido un error al subir la imagen</font>";break;

}

$fp = fopen($tmp, "rb");
$str = fread($fp, filesize($tmp));

fclose($fp);
unlink($tmp);

$im1 = ImageCreateFromString($str);

$imgname = $Ref."thumb_1"; // Nombre imagen (se podría indicar desde el formulario)
$maxwidth = 300; // Ancho máximo
$maxheight = 150; // Alto máximo

$width1 = ImageSX($im1);
$height1 = ImageSY($im1);
$width2 = $maxwidth;
$height2 = floor(($width2 * $height1) / $width1);

if($maxheight > 0 && $height2 > $maxheight) {

$height2 = $maxheight;
$width2 = floor(($height2 * $width1) / $height1);
}

$im2 = ImageCreateTrueColor($width2, $height2);
ImageCopyResampled($im2, $im1, 0, 0, 0, 0, $width2, $height2, $width1, $height1);

ImageJpeg($im2, "thumb/".$imgname.".jpg"); // Se copia en temp/
$msg = "Ok";
$im3 = ImageCreateFromString($str);

$imgname2 = $Ref."_1"; // Nombre imagen (se podría indicar desde el formulario)
$maxwidth2 = 800; // Ancho máximo
$maxheight2 = 250; // Alto máximo

$width12 = ImageSX($im3);
$height12 = ImageSY($im3);
$width22 = $maxwidth2;
$height22 = floor(($width22 * $height12) / $width12);

if($maxheight2 > 0 && $height22 > $maxheight2) {

$height22 = $maxheight2;
$width22 = floor(($height22 * $width12) / $height12);
}

$im4 = ImageCreateTrueColor($width22, $height22);
ImageCopyResampled($im4, $im3, 0, 0, 0, 0, $width22, $height22, $width12, $height12);

ImageJpeg($im4, "full/".$imgname2.".jpg"); // Se copia en temp/

break;
}
header("Location: newinsert.php?pos=".$pos."&color=".$color."&ref=".$Ref.");
php?>

crh3675
04-19-2004, 12:23 PM
You still have 2 "break;" statements in your code

crh3675
04-19-2004, 12:26 PM
I cleaned your code a bit, try this


<?php
$link = mysql_connect('mm', 'mm', 'mm');
mysql_select_db("mm",$link2);
$result = mysql_query("SELECT * FROM fotos", $link);
$num_rows = mysql_num_rows($result);
$numref = ("$num_rows"+5000);
$iniciales = "rkf";
$Ref =$iniciales.$numref;
$sql = mysql_query("SELECT * FROM fotos WHERE ref= '$Ref'");


while(mysql_num_rows($sql) != 0){
$Ref =$iniciales.($numref++);
}
$msg = "";

if(!strcasecmp($_SERVER['REQUEST_METHOD'], "POST")) {

if(!isset($_FILES['image']) || $_FILES['image'] == "none" || $_FILES['image'] == "") {
$msg = "<font color='#0000FF' size='1' face='Arial, Helvetica, sans-serif'>Seleccione sus fotografías pulsando -Examinar-</font>";
exit;
}

$tmp = getcwd()."/".$_FILES['image']['name'];

if(!@move_uploaded_file($_FILES['image']['tmp_name'], $tmp)) {
$msg = "<font color='#0000FF' size='1' face='Arial, Helvetica, sans-serif'>Ha ocurrido un error al subir la imagen</font>";
exit;
}

$fp = fopen($tmp, "rb");
$str = fread($fp, filesize($tmp));

fclose($fp);
unlink($tmp);

$im1 = ImageCreateFromString($str);

$imgname = $Ref."thumb_1"; // Nombre imagen (se podría indicar desde el formulario)
$maxwidth = 300; // Ancho máximo
$maxheight = 150; // Alto máximo

$width1 = ImageSX($im1);
$height1 = ImageSY($im1);
$width2 = $maxwidth;
$height2 = floor(($width2 * $height1) / $width1);

if($maxheight > 0 && $height2 > $maxheight) {
$height2 = $maxheight;
$width2 = floor(($height2 * $width1) / $height1);
}

$im2 = ImageCreateTrueColor($width2, $height2);
ImageCopyResampled($im2, $im1, 0, 0, 0, 0, $width2, $height2, $width1, $height1);

ImageJpeg($im2, "thumb/".$imgname.".jpg"); // Se copia en temp/
$msg = "Ok";
$im3 = ImageCreateFromString($str);

$imgname2 = $Ref."_1"; // Nombre imagen (se podría indicar desde el formulario)
$maxwidth2 = 800; // Ancho máximo
$maxheight2 = 250; // Alto máximo

$width12 = ImageSX($im3);
$height12 = ImageSY($im3);
$width22 = $maxwidth2;
$height22 = floor(($width22 * $height12) / $width12);

if($maxheight2 > 0 && $height22 > $maxheight2) {
$height22 = $maxheight2;
$width22 = floor(($height22 * $width12) / $height12);
}

$im4 = ImageCreateTrueColor($width22, $height22);
ImageCopyResampled($im4, $im3, 0, 0, 0, 0, $width22, $height22, $width12, $height12);

ImageJpeg($im4, "full/".$imgname2.".jpg"); // Se copia en temp/

}
header("Location: newinsert.php?pos=".$pos."&color=".$color."&ref=".$Ref.");
?>

Perfidus
04-19-2004, 12:30 PM
Now I have remove them all, it doesn´t work neither.
I think this is maybe not the reason...

crh3675
04-19-2004, 12:43 PM
I think your problem is that the PHP is not being processed on the server. Is the file named .php? Do you have PHP installed and running?

Perfidus
04-19-2004, 02:53 PM
The PHP is being processed in the server.
At least the half, as soon as code arrives to && server stops processing the PHP.
So extrange.
The extension is HTML, but normally I have no problem with that...

Conor
04-19-2004, 03:01 PM
you cant have php in a file with a .html extension

Perfidus
04-19-2004, 03:10 PM
I can show you 1000 working examples on the internet!

Conor
04-19-2004, 03:12 PM
umm, im sorry but you cant. PHP must end in .php or .phtml. I thing there are a couple otheres but .html is definately not one of them,

Perfidus
04-19-2004, 03:57 PM
go here (http://www.costa4seasons.com) and check it, the index is html and have lots of PHP tags inside, also the book I bought for learning PHP doesn't agree with you. If PHP is running on server then you can introduce PHP tags inside html and will be recogniced.

Perfidus
04-19-2004, 03:59 PM
Sorry, when you arrive to the address given by the link, then choose one of the language options, the coming page is html with php.

crh3675
04-19-2004, 04:44 PM
I won't argue this topic any more than already but the only way you can have php process html files is if you re-configure your webserver to treat html as php. And by the way, NOBODY does that.

neenach2002
04-19-2004, 10:44 PM
You are WRONG....ANY file with ANY PHP in it MUST end in .php or .phtml (some others)....
The server spits out an HTML page. I have seen pages where it actually comes out in the form of .html....But you still need to name it .php...

Edit: If you want our help, don't argue with us. We know what we are talking about. Don't be ignorant, rude, cruel, or anything else nagative towards us (or anyone else for that matter)...we are taking our time to help you. When you ask for help, and then tell us we're wrong, you're being arrogant and rude...

Everyone here either helps, needs help, or both. The people providing the help know what they are talking about, because they have spent a long time learning what they are helping with.

P.E.:
I'm not talking to crh3675...lol...it looks like I am...if you read all of my post, you will realize I couldn't be, because he is not asking for help, but is helping...;)

P.P.E..: The server takes php and spits out pure HTML, there is no way to view the source code on a .php or .phtml (SOME OTHERS!) page and find any PHP. It will all be pure HTML

P.P.P.E.: P=post and e=edit....so this edit is the post post post edit...;)

The Cheat
04-19-2004, 11:52 PM
if you are curious about how to make the webserver process .html as .php- i recently explained how to do this in this topic (http://forums.webdeveloper.com/showthread.php?s=&threadid=32917)