Results 1 to 5 of 5

Thread: [RESOLVED] passing variables from db to update.php

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Resolved [RESOLVED] passing variables from db to update.php

    ok this is getting me quite stuck and its real important i fix it. this is whats goin on...

    i have a page called 'skills.php'

    Code:
    <p>Modify the skills table</p>
    
    <form action="addskill.php" method="post">
    Skill name: <input type="text" name="skillname"><br />
    Skill description: <input type="textarea" rows="5" cols="20" name="description"><br />
    <input type="Submit">
    </form>
    
    <br />
    
    <?php
    include("config.php");
    
    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    
    $query="SELECT * FROM Skills";
    $result=mysql_query($query) or die( "Unable to do query");
    
    $num=mysql_num_rows($result);
    mysql_close();
    if ($num==0) {
    echo "The database contains no skills";
    } else {
    echo "<b><center>Skills table</center></b><br /><br /><table><form><tr><td>id</td><td>name</td><td>description</td><td>update</td><td>delete</td></tr>";
    
    $i=0;
    while ($i < $num) {
    
    $skillid=mysql_result($result,$i,"skillid");
    $skillname=mysql_result($result,$i,"skillname");
    $description=mysql_result($result,$i,"description");
    
    echo "<tr>
    <td>$skillid</td>
    <td><input type='text' input value='$skillname' name='formname'></td>
    <td><input type='textarea' rows='1' cols='100' input value='$description' name='formdescription'></td>
    <td><a href='updateskill.php'>U</a></td>
    <td><a href='killskill.php'>D</a></td>
    </tr>";
    
    $i++;
    }
    
    echo "</form></table>";
    
    }
    
    ?>

    ok so basically its got the add thing at the top and the table below. im gonna use this in my admin section so i can add new skills.

    however next to each record there is 'U' which means i can type something in that box and click U to update that record.

    it does this [updateskill.php]:

    Code:
    <?php
    include("config.php");
    
    $_GET['skillid2'];
    $_GET['name'];
    $_GET['description'];
    
    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    
    $query="UPDATE Skills SET skillname='$name', description='$description' WHERE skillid=$skillid";
    mysql_query($query);
    
    mysql_close();

    Problem is this just won't work! when i click on the U it clears the record and thats it - doesnt add or update anything!!! Whats going on please help!!

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: passing variables from db to update.php

    It's not working because you're never submitting a form. You're just following a link. You either need an update button that submits the form, or you need to use javascript on the link to submit the form.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Re: passing variables from db to update.php

    ok u know where it says :

    Code:
    <td><a href='updateskill.php'>U</a></td>
    someone has recommended i do:

    updateskill.php?id=$skillid

    so how can i change that to pass the 3 variables i need - skillid, skillname and description??

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: passing variables from db to update.php

    On the link, you can have:

    Code:
    <a href="#" onclick="document.forms[1].submit();">U</a>
    But you also need to set the action of the form to be updateskills.php, and you need to develop someway of telling it which record you are trying to update. IE, you need to pass an id.

    If you have a hidden field called skill_id, you can do:

    Code:
    <a href="#" onclick="document.forms[1].skill_id.value='4'; document.forms[1].submit();">U</a>
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Re: passing variables from db to update.php

    Lol ok after messing about with this loads i decided to go with just clicking update and showing a new form rather than using the same form to view and update everything... hopefully that willwork for now so this thread can be closed....

Posting Permissions

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



Click Here to Expand Forum to Full Width