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) {
Problem embedding code
Moderator: General Moderators
If you could show us the bit of PHP code and the HTML either side of it that would help us to help you. Also, don't forget that when mixing HTML and PHP that it's always good to get into the habbit of opening PHP with <?php instead of just <? to avoid conflicts with things like XML etc.
Oh, and don't forget your file will need to have a .php extension even though it contains HTML.
Oh, and don't forget your file will need to have a .php extension even though it contains HTML.
HERE YOU HAVE THE CODE:
[Edit: Added PHP tags for eyecandy. --JAM]
Code: Select all
<?
$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_nam
e'], $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í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>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
potential error:strcasecmp() Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.
error:remove the last ."
there may be others, but those are the ones that jump out at me.
Code: Select all
switch(!strcasecmp($_SERVERї'REQUEST_METHOD'], "POST")) {error:
Code: Select all
header("Location: newinsert.php?pos=".$pos."&color=".$color."&ref=".$Ref.");there may be others, but those are the ones that jump out at me.