/    Sign up×
Community /Pin to ProfileBookmark

Problem embedding php

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) {

to post a comment
PHP

17 Comments(s)

Copy linkTweet thisAlerts:
@crh3675Apr 19.2004 — Can you post more of the code please.
Copy linkTweet thisAlerts:
@PerfidusauthorApr 19.2004 — 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>
Copy linkTweet thisAlerts:
@crh3675Apr 19.2004 — 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.
Copy linkTweet thisAlerts:
@PerfidusauthorApr 19.2004 — 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?>
Copy linkTweet thisAlerts:
@crh3675Apr 19.2004 — You still have 2 "break;" statements in your code
Copy linkTweet thisAlerts:
@crh3675Apr 19.2004 — I cleaned your code a bit, try this

<i>
</i>&lt;?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")) {

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

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

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

<i> </i>$fp = fopen($tmp, "rb");
<i> </i>$str = fread($fp, filesize($tmp));

<i> </i>fclose($fp);
<i> </i>unlink($tmp);

<i> </i>$im1 = ImageCreateFromString($str);

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

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

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

<i> </i>$im2 = ImageCreateTrueColor($width2, $height2);
<i> </i>ImageCopyResampled($im2, $im1, 0, 0, 0, 0, $width2, $height2, $width1, $height1);

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

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

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

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

<i> </i>$im4 = ImageCreateTrueColor($width22, $height22);
<i> </i>ImageCopyResampled($im4, $im3, 0, 0, 0, 0, $width22, $height22, $width12, $height12);

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

}
header("Location: newinsert.php?pos=".$pos."&amp;color=".$color."&amp;ref=".$Ref.");
?&gt;
Copy linkTweet thisAlerts:
@PerfidusauthorApr 19.2004 — Now I have remove them all, it doesn´t work neither.

I think this is maybe not the reason...
Copy linkTweet thisAlerts:
@crh3675Apr 19.2004 — 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?
Copy linkTweet thisAlerts:
@PerfidusauthorApr 19.2004 — 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...
Copy linkTweet thisAlerts:
@ConorApr 19.2004 — you cant have php in a file with a .html extension
Copy linkTweet thisAlerts:
@PerfidusauthorApr 19.2004 — I can show you 1000 working examples on the internet!
Copy linkTweet thisAlerts:
@ConorApr 19.2004 — 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,
Copy linkTweet thisAlerts:
@PerfidusauthorApr 19.2004 — [URL=http://www.costa4seasons.com]go here[/URL] 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.
Copy linkTweet thisAlerts:
@PerfidusauthorApr 19.2004 — 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.
Copy linkTweet thisAlerts:
@crh3675Apr 19.2004 — 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.
Copy linkTweet thisAlerts:
@neenach2002Apr 20.2004 — 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...?
Copy linkTweet thisAlerts:
@The_CheatApr 20.2004 — if you are curious about how to make the webserver process .html as .php- i recently explained how to do this in this [URL=http://forums.webdeveloper.com/showthread.php?s=&threadid=32917]topic[/URL]
×

Success!

Help @Perfidus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...