Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php treating greater-than as end script

Tags:

html

php

apache

recently after testing my sql query script I came across a problem. The greater than sign in my if statement ended the php and then output the rest of the code as html.

Here is my code. (It's in "poll.html", an html file with php code in it)

<div class="pollcont">
<?php

$pollrow = mysql_query("SELECT * FROM `Activepoll` ORDER BY `id` DESC LIMIT 1");

$rows = mysql_num_rows($pollrow);


if($rows > 0){ Do this stuff }; ?> </div>

Instead of finishing the if statement, 0){ Do this stuff }; ?> is output into the browser.

Why is this happening and how can I change this so the script will work?

like image 433
user3591017 Avatar asked Jun 08 '14 02:06

user3591017


People also ask

What is =PHP - greater than or equal to operator?

PHP - Greater than or equal to: >= Greater than or equal to operator is a logical operator that is used to compare two numbers.

How to test whether a number is greater than 30 in PHP?

Write a PHP function to test whether a number is greater than 30, 20 or 10 using ternary operator. <?php function trinary_Test ($n) { $r = $n > 30 ? "greater than 30" : ($n > 20 ? "greater than 20" : ($n >10 ? "greater than 10" : "Input a number atleast greater than 10!")); echo $n."

Is it better to exit or return a PHP script?

return may be preferable to exit in certain situations, especially when dealing with the PHP binary and the shell. I have a script which is the recipient of a mail alias, i.e. mail sent to that alias is piped to the script instead of being delivered to a mailbox.

What is the difference between comparison and increment in PHP?

The PHP comparison operators are used to compare two values (number or string): Returns an integer less than, equal to, or greater than zero, depending on if $x is less than, equal to, or greater than $y. Introduced in PHP 7. The PHP increment operators are used to increment a variable's value.


1 Answers

Your file must have the extension ".php".

What your seeing is your browser treating the PHP open tag "<" to the greater than sign ">" as an HTML element and simply hiding that source code. Its not processing anything while its an html file.

like image 101
md5madman Avatar answered Sep 29 '22 18:09

md5madman