Jump to content

PHP Code Error


Go to solution Solved by Codey,

Recommended Posts

Hello

 

Hope some one can guide me in the right direction, am working on a simple PHP Calculator.

 

Been trying to find the problem for quite some hours all I get is a blank page, and have not been able to spot the issue, here is the code:

 

<html> 
  <head>
  
  <title></title> 
  
  </head> 
  
  <body>
  
<?php 


$operacion = $_POST['lista'];




if (isset($_POST['c1']) && !empty($_POST['c1']) &&


isset($_POST['c2']) && !empty($_POST['c2']) &&


isset($_POST['c3']) && !empty($_POST['c3'])


echo "El resultado es";


else {
echo "debes insertar todos los campos"; }


switch($operacion) {


case sumar:
echo $_POST['c1'] + $_POST['c2'] + $_POST['c3']; 
break;


case restar:
echo $_POST['c1'] - $_POST['c2'] - $_POST['c3']; 
break;


case multiplicar:
echo $_POST['c1'] * $_POST['c2'] * $_POST['c3']; 
break;


case dividir:
echo $_POST['c1'] / $_POST['c2'] / $_POST['c3']; 
break;


default: "no se ha podido realizar la operacion"; 


}



?>
  
</body> 
</html> 

Any help would be appreciated, thank you.

 

Link to comment
https://forums.phpfreaks.com/topic/288281-php-code-error/
Share on other sites

 

 

all I get is a blank page,

Turn error reporting on, open the php.ini and make sure display_errors is set to on and error_reporting is set to E_ALL

 

On line 18 - 24 you have a malformed if statement. Have left off the closing parenthesis for the condition and a opening { (curly brace) for the statement.

On line 29 before the else you have left of the closing  } (curly brace) for closing the if statement

 

Refer to the manual for the proper structure for an if/esle

 

The values for each case statement should be wrapped in quotes

Edited by Ch0cu3r
Link to comment
https://forums.phpfreaks.com/topic/288281-php-code-error/#findComment-1478395
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.