Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP Help please

Posted on 2011-03-25
2
Medium Priority
?
192 Views
Last Modified: 2012-05-11
Hi Experts, I need help

Ive got this error and i dont know how to get rid of it, could someone please help the error is.

Warning: preg_match() [function.preg-match]: No ending delimiter '/' found in M:\EasyPHP-5.3.5.0\www\clac2.php on line 101

code is attached
<?php
// Defining the "calc" class
class calc {
var $number1;
var $number2;
function add($number1,$number2)
{
$result =$number1 + $number2;
echo "The sum of $number1 and $number2 is $result<br><br>";
echo "$number1 + $number2 = $result";
exit;
}
function subtract($number1,$number2)
{
$result =$number1 - $number2;
echo "The difference of $number1 and $number2 is $result<br><br>";
echo "$number1 &#045 $number2 = $result";
exit;
}
function divide($number1,$number2)
{
$result =$number1 / $number2;
echo "$number1 divided by $number2 is $result<br><br>";
echo "$number1 ? $number2 = $result";
exit;
}
function multiply($number1,$number2)
{
$result =$number1 * $number2;
echo "The product of $number1 and $number2 is $result<br><br>";
echo "$number1 x $number2 = $result";
exit;
}
function square($number)
{
$result = $number * $number;
echo "The square of $number is $result<br><br>";
echo "$number &#94; 2 = $result";
}
function squareroot($number)
{
$result = sqrt($number);
echo "The square root of $number is $result<br><br>";
}
function cube($number)
{
$result = $number * $number * $number;
echo "The cube of $number is $result<br><br>";
echo "$number1 &#94; 3 = $result";
}
}
//Creating object of class
$calc = new calc();
?>
<title>PHP Calculator </title>
<h2>Calculator 1</h2>
<form name="calc" action="" method="POST">
Number 1: <input type="text" name="value1"><br>
Number 2: <input type="text" name="value2"><br>
Operation:
<select name="oper">
<option value="add">Addition</option>
<option value="subtract">Subtraction</option>
<option value="divide">Division</option>
<option value="multiply">Multiplication</option>
</select>
<br>
<input type="submit" value="Calculate" name="submit">
</form>
<br>
<br>
<h2>Calculator 2</h2>
<form name="calc2" action="" method="POST">
Number : <input type="text" name="value"><br>
Operation:
<select name="operat">
<option value="square">Square</option>
<option value="squareroot">Square Root</option>
<option value="Cube">Cube</option>
</select>
<br>
<input type="submit" value="Calculate" name="submit1">
</form>
<?php
if($_POST['submit']){
$number1 = $_POST['value1'];
$number2 = $_POST['value2'];
$oper = $_POST['oper'];
if(!$number1){
echo "<font color='red'>Please enter first number in calculator 1</font>";
exit;
}
if(!$number2){
echo "<font color='red'>Please enter second number in calculator 1</font>";
exit;
}
if(!$oper){
echo "<font color='red'>Please select operator in calculator 1</font>";
exit;
}
if(!preg_match("/^-?(0|[1-9]\d*)(\.\d+)?$", $number1)){
echo "<p style='color: red'>The entry for number 1 was not a number</p>";
exit;
}
if(!preg_match("/^-?(0|[1-9]\d*)(\.\d+)?$", $number2)){
echo "<p style='color: red'>The entry for number 2 was not a number</p>";
exit;
}
if($oper == "add"){
$calc->add($number1,$number2);
}
if($oper == "subtract"){
$calc->subtract($number1,$number2);
}
if($oper == "divide"){
$calc->divide($number1,$number2);
}
if($oper == "multiply"){
$calc->multiply($number1,$number2);
}
}
?>
<?php
if($_POST['submit1']){
$number = $_POST['value'];
$operat = $_POST['operat'];
if(!$number){
echo "<font color='red'>Please enter number in calculator 2</font>";
exit;
}
if(!$operat){
echo "<font color='red'>Please select operator in calculator 2</font>";
exit;
}
if(!eregi("[0-9]", $number)){
echo "<font color='red'>Value must be digits in calculator 2</font>";
exit;
}
if($operat == "square"){
$calc->square($number);
}
if($operat == "cube"){
$calc->cube($number);
}
if($operat == "squareroot"){
$calc->squareroot($number);
}
}
?>

Open in new window

0
Comment
Question by:NeoAshura
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 2000 total points
ID: 35216918
Try chancing the following lines:

Line 101: if(!preg_match("/^-?(0|[1-9]\d*)(\.\d+)?$/", $number1)){

Line 105: if(!preg_match("/^-?(0|[1-9]\d*)(\.\d+)?$/", $number2)){
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35217498
thnx that sorted it
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question