SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    here
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Edit one set of multiple records

    $query = "SELECT * FROM table1 WHERE number=5";
    $result=mysql_query($query);
    $num=mysql_numrows($result);
    mysql_close();
    if ($num > 0)
    {

    echo "<b><center>Player's numbers</center></b>";
    $i=0;

    while ($i < $num) {
    $playersname mysql_result($result,$i,"name");
    $anumber=mysql_result($result,$i,"number");
    i++;

    echo " <tr><td> Name: </td><td colspan='3'>$playersname";
    echo " <tr><td> Number/td><td colspan='3'>$number<br>";


    _______________________________________________

    this will display:

    Joe 5
    James 5
    Lil 5

    How do I get it so I can just edit James 5 with an edit2.php?

    If you need more info, please let me know!!

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    before your loop do:
    PHP Code:
    echo '<form action='edit2.php' method='post'><div>'
    in your loop do:
    PHP Code:
     $id mysql_result($result,$i,"id");
    //...
    echo " <tr><td> Name: </td><td colspan='3'>$playersname";
    echo 
    " <tr><td> Number:</td><td colspan='3'><input type='text' name='num$id' value='$number' />";
    echo 
    "<input type='hidden' name='process[]' value=$id' /></td></tr>"
    after the loop do:
    PHP Code:
    echo '</table><input type="submit" value="Update" /></div></form>'
    in edit2.php

    do
    PHP Code:
    foreach($_POST['process'] as $id) {
      
    $sql='update table1 set number = '.(int)$_POST['num'.$id] .' where id = '.(int)$id;
    //run the $sql

    }
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    here
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So this will allow me to change $number in "edit2.php"

    what changes would I make to change name and number?


    Thank you for the code provided...much appreciated

  4. #4
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by linuxnewb
    So this will allow me to change $number in "edit2.php"

    what changes would I make to change name and number?
    in the original script:
    PHP Code:
    echo " <tr><td> Name: </td><td colspan='3'><input type='text' name='name$id' value='$playersname' /></td>"
    and in edit2.php:
    PHP Code:
      $sql='update table1 set '
    .' number = '.(int)$_POST['num'.$id
    .
    ' ,name="' $_POST['name'.$id] . '"'
    .' where id = '.(int)$id
    Note that there is no sanitizing of the raw $_POST values for the 'name' values, a potentially dangerous script.


Bookmarks

Posting Permissions

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