ie does not render my php if statement well, any ideas? I say this because it works well in firefox.
<input type="image" src="Images/submit.png" value="REGISTER" name="command" />
if($_REQUEST['command'] == 'REGISTER'){
print "test";
}
else{
}
It is not printing "test"
Internet Explorer is not interpreting your PHP statement at all.
PHP is a server-side programming language, i.e. executed at the server, not the client.
Please rephrase your question. By your previous posts it seems you realize that.
You're missing the <?php ... ?> tags surrounding your PHP code.
PHP is executed server side; IE has no bearing on your if statement. My guess is that $_REQUEST['command'] is not being set.
What does this print:
if(empty($_REQUEST['command')) print 'command is empty';
Another idea would be to append the "command" data to your URL:
http://localhost/your-php-script.php?command=foo
EDIT
Just noticed that you're using type="image", I don't know if IE supports that: http://www.codingforums.com/archive/index.php/t-79035.html, try using a regular submit button.
However: You should check first, if $_REQUEST['command']; is set
if(isset($_REQUEST['command'])) {
if($_REQUEST['command'] == 'REGISTER'){
print "test";
}
else{
}
}
Related
Can anyone tell me the right way to do this. I want a pop up first, then the script to stop, but when I run this, the exit just overrides the pop up?
if (HandOverNotesModifiedTime > $datetime_from)
{
echo "<script type='text/javascript'>alert('WARNING: Notes have not been updated!');<script>";
exit(header('Location:/handoverTESTING.html');
}
I tried without the exit, just to make sure the pop up works, and it does.
You can use like this :
if (HandOverNotesModifiedTime > $datetime_from)
{
echo "<script type='text/javascript'>alert('WARNING: Notes have not been updated!');</script>";
echo "<script>window.location.assign('/handoverTESTING.html');</script>";
}
Page redirection reason :
Popups are created on the client side, and the header redirection takes place on the server side.
PHP is executed at the server side. It renders HTML,Styles and sends it to the browser then browser execute the javascript codes
I need to compile the php code on HTML Button click and display the compilation output on browser.I am using the following code to display the output on browser,it works well in terminal but doesn't give anything on browser.I am using XAMPP server on windows machine.
<?php
if(isset($_POST['compile'])){
$cmd="php php_part.php";
$var=system($cmd);
echo $var;
}
?>
<input type="submit" class="button" name="compile" value="Compile Code" />
First you are not compiling the php_part.php script, you are running it. Yes I realise that running a php script requires that it first be compiled or rather interpreted but that statement will execute the php_part.php script.
There are 2 likely reasons why it is not running.
When run from the browser i.e via Apache it does not know where to find php.exe
Depending on where the php_part.php script is kept it may not be able to find that either.
Try changing this statement
$cmd="php php_part.php";
to
$cmd="C:/path/to/php/php.exe C:/path/to/script/php_part.php";
If that works then that above was the problem.
I have to also say that there must be a better way of running this script. As you are in a PHP section of code would not a simple include or require not be a better solution. Something like this
<?php
if(isset($_POST['compile'])){
require "php php_part.php";
echo $var;
}
?>
Of course this depend on how you have written that php_part.php script. If you wrote it as a function then this would be a better solution
The php_part.php script
function xxx() {
// do whatever coding
return $the_result;
}
The main code
<?php
if(isset($_POST['compile'])){
require "php php_part.php";
$var = xxx();
}
?>
I have my long PHP script with some JavaScript at the end. In the middle of the script if an 'if' statement is true then is their a way to stop the rest of the PHP script and output the rest of the HTML part of the page. Here's a little snippet:
... more code ...
case 2:
$e=$_POST['email'];
$n=$_POST['name'];
mysql_connect($dbloc,$dbuser,$dbpass);
mysql_select_db($dbname)or die(mysql_error());
$query="SELECT * FROM users WHERE email='$e'";
$re=mysql_query($query);
$numm=mysql_numrows($re);
if($numm>=1){
$js="alert('Sorry but your email is currently in use. Please try again with a different email address.');";
$url="./";
exit();
}
else{
$_SESSION['rEmail']=$e;
$_SESSION['rName']=$n;
}
break;
... more code...
<html goes here />
I originally thought exit() would end just the PHP portion but still give back the rest of the page but that does not seem to be the case.
exit() is performing what it was maid to do. It is exiting the your PHP code right from the point where it is called.
Your concept that it'll print the remaining of HTML is wrong. The whole of PHP code is taken as a PHP script, with all your logic/PHP functions tagged inside <?php and ?> and the text outside is just like documentation, and is outputted as it is.
With the exit inside the if statement, the code/text after it isn't processed at all. I'd suggest that you use a break statement instead.
I have the following code:
echo "<script type='text/javascript'>
if(window.location.href.toLowerCase().indexOf('test') != -1) {
}
else
window.open('http://google.com', '_parent', '');
</script>";
echo "test";
The code executes successfully BUT if it will open http://google.com using window.open it still shows echo "test" before successfully redirecting to google.com.
Can I somehow prevent executing code after the else statement in the javascript (window.open('http://google.com', '_parent', '');)?
Thanks
EDIT: Does that seem that I just ask to ask? I thought that something might exist that I could use in javascript to stop browser from printing echo "test" if I reached else statement in javascript code.
You should understand this order.
PHP executes script and generate HTML/JS/etc
Then browser get it, parse and execute.
So you should use any of php condition to avoid printing "test" in some cases
I've been having this problem for around an hour, and have searched the internet for answers. I've checked the PHP documentation, looked around, Googled, nothing.
Anyways, my problem is that after I try to validate something (and it's wrong), if I use exit; it will also stop the HTML after. Here's what I'm talking about:
if ($_POST['exampleEmail'] == "")
{
echo "Please enter an e-mail."; //Now I want only the PHP script to stop, however...
exit; //If I use exit, then the HTML after this script (footer) doesn't show.
}
If anyone can help, please do. I've tried using break, but to no avail, since it's only for loops and switches.
If there is a better/more correct (or simply correct if this is the wrong way), please share. I've had this problem in the past, and I just used exit then.
Thanks.
Just wrap the rest of the script in a new if block:
$execute = true;
// HTML here...
if (empty($_POST['exampleEmail'])) {
echo "Please enter an e-mail.";
$execute = false;
}
// HTML here...
if ($execute) {
// do stuff only if execute is still true.
}
// HTML here...
Now that this is working for you, I advise you to do some research into separating your presentation and your logic. There's a lot of tutorials and blogs on the subject, you just need to start searching.
You should use an if-statement in PHP
if ($_POST['exampleEmail'] == "")
{
echo "Please enter an e-mail.";
$stop_script = true; //stop the script
}
else $stop_script = false; //or continue the script
if($stop_script === false)
{
//php scripts
}
//html
Use break http://php.net/manual/en/control-structures.break.php instead. But you probably have a structural Problem if it comes to this usecase in the first place.