Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need quick help!

    i am very new to php, and i am trying to put this code into a button.
    I had posted yesterday about the code itself, but i have that now. i am just trying to put it into a button now. I obviously had help on the code, and im just trying to tailor this block of code for my specific field, so i can edit it and make it for the rest.

    script:
    i have a db row displaying name & quantity, and i have a script that will -1 from the quanitity and post a message on another table - all from the click of a single button!... I just dont know how to assign it to the proper field so it -1's from that designated quanitity field.

    My fields are:
    $school1/////$VL1
    $school2/////$VL2
    $school3////$VL3
    etc... all the way to $$school10///$VL10.

    Just do $VL1, so i can see how to do it for the rest.

    the set up example:
    PHP Code:
    <table width="566" border="1">
      <
    tr>
        <
    td width="300">School name 1</td>
        <
    td width="130"><label>
          <
    input name="$VL1" type="text" id="$VL1" value="15" size="10" maxlength="10" />
        </
    label></td>
        <
    td width="114"><a href="-1 code">DEDUCT -1</a></td>
      </
    tr>
      <
    tr>
        <
    td>School name 2</td>
        <
    td><input name="$VL2" type="text" id="$VL2" value="13" size="10" maxlength="10" /></td>
        <
    td><a href="-1 code">DEDUCT -1</a></td>
      </
    tr>
    </
    table
    the code to run in each link, needs to be tailored to the $VL1
    PHP Code:
    <?php
        
        
    if ( isset($_GET['action'], $_GET['field']) && $_GET['action'] == 'subtract' ) { 
             
             
    $field mysql_real_escape_string(urldecode($_GET['field'])); 
        
            if ( !
    mysql_query("UPDATE virtual_left SET $field = $field - 1") ) { 
                echo 
    "problem executing query: " mysql_error() . "<p />";  
            }  
        
            if ( !
    mysql_query("INSERT INTO audit (message) VALUES ('school1 -1 apple')") ) { 
                echo 
    "problem executing query: " mysql_error() . "<p />"
            }  
        
             
    // We are done, redirect.. 
             
    header("Location: view.php"); 
        } 
    ?>
    if someone can tailor that code for the first one ($vl1), and show me how to set up that form so it'll run correctly that would be great, and i can tailor each one to it after. i just need the first one set up to see how its done.

    thanks in advance!
    and goodmorning!

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Start with #2 from the forum guidelines:

    2) Type in a subject that summarizes your question- A great way to turn off other members wanting to help you is to type an incomplete or silly subject for your post. Examples of poor subject titles include:

    - "Help!"
    - "I'm a newbie...be gentle"
    - "How can I..."
    - "Urgent...deadline tomorrow!"

    The above subjects either have absolutely nothing to do with the question itself, or are grossly incomplete (ie: "How can I..."). When asking for help, enter a subject that summarizes your question, period! Don't use silly, incomplete, or "bait" subjects. Some examples of good titles are:

    - "How do I round a number to 2 decimal places using JavaScript?"
    - "What's the difference between require() and include() in PHP?"
    - "Can someone suggest a good, free HTML editor?"
    Are you a Help Vampire?


  •  

    Posting Permissions

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