Jump to content


Need some advices for my PHP code....


3 replies to this topic

#1 J.Wilson

    Young Padawan

  • Members
  • Pip
  • 5 posts

Posted 23 December 2007 - 12:48 PM

Hi P2L Gang!
First, I should say i am very glad for being a new to the amazing P2L :biggrin:
I've found here by searchin' for some tutz for the great codin' lang, PHP and i think here will be my #1 resource for improvin' my very little php knowledge (I am a real newbie in PHP).
I've written a little php code for calculatin' and now i need someone debug my code and give me some advices for better codin'.
thanks.

here you are:

Attached Files



#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 23 December 2007 - 11:12 PM

Moved to proper category.

#3 AceLord

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 23 December 2007 - 11:56 PM

Looks pretty nice.... better than mine:
#!/usr/bin/php
<?php
function addGivenNumbers() {
/*
* Code created by AceLord	 
* © 2007-2008 [url="http://ghostblade.us/"]http://ghostblade.us/[/url]													   
* Contact via ghost@ghostblade.us, dxsurvives@gmail.com, or AceLord on MSN 
* Good luck!
* Script made for PHP 4+
*/
$a = $_POST['number1'];
$b = $_POST['number2'];
$c = $_POST['operation'];
$d = $a + $b;
$e = $a - $b;
$f = $a * $b;
$g = $a / $b;
echo "<font color=\"red\"> Your answer is&nbsp;";
if($c == add)
echo "$a + $b = $d";
if($c == sub)
echo "$a - $b = $e";
if($c == mul)
echo "$a × $b = $f";
if($c == div)
echo "$a ÷ $b = $g";
echo ".</font>";

   }

if(isset($_POST['submitted'])) {
addGivenNumbers();
}
echo "<fieldset>
<legend>Calculator</legend>
<form action='<?php echo $_PHP_SELF; ?>' method='post'>
Numeral 1: <input type='text' name='number1' ><br />
Numeral 2: <input type='text' name='number2' ><br />
<br />Operation:
<select name='operation'>
<option name='calc' value='add' selected>Add (+)
<option name='calc' value='sub'>Subtract (-)
<option name='calc' value='mul'>Multiply (×)
<option name='calc' value='div'>Divide (÷)
</select>
<br /><br />
<input type='submit' id='submitted' name='submitted' value='Calculate' />
<input type='reset" value='Reset' />
</form>
</fieldset>";
?>

Edited by Mr. Matt, 24 December 2007 - 02:48 AM.
Changed SQL tags to code tags


#4 J.Wilson

    Young Padawan

  • Members
  • Pip
  • 5 posts

Posted 24 December 2007 - 01:44 AM

Thanks man! :yodasearch:

your codes are like a poem!
it's pretty beautiful!
it's very better than my code :)

Edited by J.Wilson, 24 December 2007 - 01:46 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users