Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 2 of 2 FirstFirst 1 2
Results 11 to 13 of 13
  1. #11
    Junior Member
    Join Date
    Jun 2012
    Location
    India
    Posts
    11
    Member #
    32049
    None taken. I'm in a process of discovering whether I'm good as a programmer or not. I'm more or less good with logic, but not quite outstanding; I'm aware of that. A few of my classmates from college are there in my class and they have been saying that they have been having some problems as well. Well I know most of the people in my batch and we discuss issues that we can't solve, so you can say that in a way, they are getting the help I'm getting here.

    I think it'd be beneficial for me if you'd post the script here. It'd be helpful in a way.

  2.  

  3. #12
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,799
    Member #
    5580
    Liked
    726 times
    Here's my script ...

    PHP Code:

    <?php
    session_start
    ();
    //error_reporting(0);

    // are they visiting for the first time?
    if(!isset($_SESSION['values'])){
    $flag=1// first time visitor
    }
    else{
    // they were here before.
    $flag=0;

      
    // do they want to destroy the SESSION?
      
    if($_GET['d']=="d"){
      
    $_SESSION = array();
      
    session_destroy();
      
    header("location: ".$_SERVER['PHP_SELF']);
      exit;
      }
    }
    // let's see if there are any values to read ...
        
    if(isset($_POST['total'])){
    $error=0;
    // see if any of them are blank or non-integers ...
    foreach($_POST['value'] as $val){
      if(!
    is_numeric($val)){
      
    $_SESSION['error']="Blank or non-integer ... try again";
      
    $error=1;
      }
    }
    // write the textbox array to the session array and rerun the script.
    // when it reruns, they are no longer a first time visitor.
    if($error==0){
            
    $_SESSION['values']=$_POST['value'];
    unset(
    $_SESSION['error']);
    header("location: ".$_SERVER['PHP_SELF']);
    exit;
    }
    // no errors so process as normal.
    header("location: ".$_SERVER['PHP_SELF']);
    exit;
    }

    // There is no reason to use a function ... so it's commented-out here
    /*PHP function Definition*/
    //function add($val1,$val2){
    //$total=$val1+$val2;
    //return $total;
    //}

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Numbers</title>
    </head>

    <body>
    <a href="<?php echo $_SERVER['PHP_SELF']."?d=d";?>">Destroy</a>
    <form action="" method="post" name="numbers">
    <table>
    <?php
    // are they first time visitors?
    if($flag==1){
    echo
    "<tr>
            <td>Enter 1st number:</td>
            <td><input type=\"text\" name=\"value[]\" value=\"\"/></td>
        </tr>
        <tr>
            <td>Enter 2nd number:</td>
            <td><input type=\"text\" name=\"value[]\" value=\"\"/></td>
        </tr>
        <tr>
            <td><input type=\"submit\" name=\"total\" value=\"Total\" /></td>
        </tr>
    "
    ;
    }
    else{
    // they must have already visited the site, so we'll give them a different form ...
    $c=1;
    $total=0;
    foreach(
    $_SESSION['values'] as $value){
    // let's add each number
    $total=$total+$value;
    echo
    "
        <tr>
            <td>Value 
    $c:</td>
            <td><input type=\"text\" name=\"value[]\" value=\"
    $value\" readonly /></td>
        </tr>
    "
    ;
    $c++;
    }
    // have they decided to add another variable?
    if($_POST['addvar']){
    echo
    "
        <tr>
            <td>New Value:</td>
            <td><input type=\"text\" name=\"value[]\" value=\"\"/></td>
        </tr>
    <tr>
    <td colspan=\"2\">The current TOTAL is 
    $total</td>
    </tr>
    <tr>
            <td colspan=\"2\"><input type=\"submit\" name=\"total\" value=\"Total the New Variable\" /></td>
        </tr>
    "
    ;
    $c++;
    }
    else{
    echo
    "
    <tr>
    <td>The TOTAL is</td>
    <td>
    $total</td>
    </tr>
        <tr>
    <td colspan=\"2\"><input type=\"submit\" name=\"addvar\" value=\"Add Another Variable\" /></td>
        </tr>
        <tr>
    "
    ;
    }
    }
      
    // are there any errors?
      
    if(isset($_SESSION['error'])){
      echo 
    "<tr><td colspan=\"2\"><br />".$_SESSION['error']."<br /></td></tr>";
      }
        
    ?>
        </table>
    </form>
    </body>
    </html>


  4. #13
    Junior Member
    Join Date
    Jun 2012
    Location
    India
    Posts
    11
    Member #
    32049
    Thanks a ton.


Page 2 of 2 FirstFirst 1 2

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search tags for this page

disable textbox in php

,

display values of table in text boxes of form in disabled using php

,

how to disable numbers in textbox php

,

how to disable textbox in php

,
how to disabled textbox can post php
,
php code to disable textbox
,
php disable edit textbox
,
php enabled textbox disabled
,

php textbox array

,

textboxt enable fals in php

Click on a term to search for related topics.
All times are GMT -6. The time now is 05:15 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com