Jump to content

davidannis

Members
  • Posts

    627
  • Joined

  • Last visited

  • Days Won

    2

Posts posted by davidannis

  1. Nitpick: The OP didn't specify that he wanted a calculator. He said he wanted to take two numbers and show the result.

     

    The result of WHAT is yet to be defined.

    Hopefully, if it's not one of the operations my 7 year old coded the OP can add another case to the switch statement. ;D  If not, perhaps my son can do it as a freelance job.

  2. My son wrote this (with a little help from his dad):

    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Calculator</title>
        </head>
        <body>
            <p>
            <form method="POST" action="Calculator.php">
                <input type="text" name="x"><br />
                <select name="operation">
                    <option value="+">+</option>
                     <option value="-">minus</option>
                      <option value="*">*</option>
                       <option value="/">/</option>
                       <option value="sqrt">square root</option>
                </select><br />
                <input type="text" name="z">
                <input type="submit">
            </form>
            </p>
            <?php
            switch ($_POST["operation"]){
                case '+':
                    $answer=$_POST['x']+$_POST['z'];
                    break ;
                case '-':
                    $answer=$_POST['x']-$_POST['z'];
                    break ;
                case '*':
                    $answer=$_POST['x']*$_POST['z'];
                    break ;
                case '/':
                    $answer=$_POST['x']/$_POST['z'];
                    break ;
                    case 'sqrt':
                    $answer=sqrt($_POST['x']);
                    break ;
            }
                            echo $answer;
            ?>
        </body>
    </html>
    

    any errors are mine.

  3. Muddy_funster is right. You can set the error message in the loop and echo the error message after the loop completes:

    while(false!== ($file = readdir($res))) {
    if(strpos(strtolower($file),$q)!== false &&!in_array($file,$exclude)) {
    
    if (($info["extension"] == "mp3") || ($info["extension"] == "wav")) {
    }elseif(!isset($errorMsg)){
      $errorMsg = "Your Error Message";
    }
    }
    }// now we are out of the loop
    if (isset($errorMsg)) echo $errorMsg;
    
  4. I was going to re-write this for the OP since he's trying, but before I do I have something that's puzzling me. Can anybody explain why this:

    $construct .="title LIKE '%Funny%'";
    

    is not what I expected, which would have been this:

    $construct .="title LIKE '%$funny%'";
    

    which I would have rewritten as:

    $construct .="title LIKE '%".mysql_real_escape_string($funny)."%'";

    I'm clearly missing something.

  5. Not sure how to sanitize $construct because we don't see how it is built but for $id or $per_page something like

    $id=intval($_REQUEST['id]);
    if ($id<1){
    echo "error message about starting with an id that is at lest one'; // or redirect to an error page
    die();
    } 
    
  6. Assuming that $id and $per_page are not passed in the URL/form and $construct is properly escaped it is fine. We'd need to see how those variables get values to be sure.

  7. If I am understanding you correctly you are trying to total the $totalPayment column. Try replacing this

    			  <?php 
    			  } while ($row_rsTenProp = mysql_fetch_assoc($rsTenProp)); ?>
    

    with this:

    			  <?php 
    $grandTotal+= $totalPayment;
    			  } while ($row_rsTenProp = mysql_fetch_assoc($rsTenProp)); ?>
    

    and this

                  </tr>
                  
              </table>
    

    with this:

                  </tr>
                 <tr><td>Grand Total:</td><td><?php echo $grandTotal;?></td></tr> 
              </table>
    

    If that works you will want to format the number and make the columns look pretty.

×
×
  • 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.