SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 40 of 40
  1. #26
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change this line :
    PHP Code:
      echo "        <td><input type='checkbox' name='remove[" .$k"]' value=" .$k" /></td>\n"
    To this :
    PHP Code:
      echo "        <td><input type='checkbox' name='remove[" .$i"]' value=" .$i" /></td>\n"
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  2. #27
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array Manipulation

    Byron,

    Upon selecting a record and clicking submit, i get greeted with more error message:

    array(1) { [0]=> string(1) "0" }
    Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Documents and Settings\It's Dale\Desktop\xampplite\htdocs\frm_handler.php on line 13

    Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\Documents and Settings\It's Dale\Desktop\xampplite\htdocs\frm_handler.php on line 13
    Could not remove : Leighton
    Error Number : 1045

    Warning: Cannot modify header information - headers already sent by (output started at C:\Documents and Settings\It's Dale\Desktop\xampplite\htdocs\frm_handler.php:9) in C:\Documents and Settings\It's Dale\Desktop\xampplite\htdocs\frm_handler.php on line 22

    Code:
    <?php
    
    session_start();
    
    $con = mysql_connect("localhost","peter","abc123");
    
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    
    mysql_select_db("WB", $con);
    
    $item = 0;
    $line = 0;
    
    $result = mysql_query("SELECT * FROM Birds");
    
    if(mysql_error() != 0 || mysql_num_rows($result) == 0)
    {
      die("No database, or no data");
    }
    
    $records = array();
    $temp = array();
    while($row = mysql_fetch_object($result))
    {
      array_push($records, $row);
      echo $records[$line]->Name;
      echo $records[$line]->Species;
      echo $records[$line]->Sex. "<br />";
      $line++;
    }
    
    $_SESSION['records'] =& $records;
    $i = 0;
    echo "<form method='post' action='frm_handler.php' name='Birds'>\n";
    echo "<table>\n";
    foreach( $records as $k )
    {
      echo "    <tr>\n";
      echo "        <td>" .$k->Name. "</td>";
      echo "        <td>" .$k->Species. "</td>>";
      echo "        <td>" .$k->Sex. "</td>";
      echo "        <td><input type='checkbox' name='remove[" .$i. "]' value=" .$i. " /></td>\n"; 
      echo "    </tr>\n";
      $i++;
    }
    
    echo "    <tr>\n";
    echo "          <td><input type='submit' value='Submit' /></td>\n";
    echo "    </tr>\n";
    echo "</table>\n";
    echo "</form>\n"; 
    ?>
    Code:
    <?php
    
    session_start();
    
    if ( isset( $_POST['remove'] ))
    {
      $tmp = $_SESSION['records'];
      $remove = $_POST['remove'];
      var_dump( $remove );
      foreach ($remove as $K => $V)
      {
        $query = "delete from Birds where Name='" .$tmp[$V]->Name. "'";
        mysql_query( $query );
        if (mysql_errno())
        {
          echo "Could not remove : " .$tmp[$K]->Name. "<br />\n";
          echo "Error Number : " .mysql_errno(). "<br />\n";
        }
        unset( $tmp[$V] );
      }
      $_SESSION['records'] =& $tmp;
      header("Location: 1.php");
    }
    ?>
    Many Thanks,

  3. #28
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will need to open your connection and select a database in your form handler.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  4. #29
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by byron3@earthlink View Post
    You will need to open your connection and select a database in your form handler.
    Byron,

    I now get the following error message:

    array(1) { [0]=> string(1) "0" }
    Warning: Cannot modify header information - headers already sent by (output started at C:\Documents and Settings\It's Dale\Desktop\xampplite\htdocs\frm_handler.php:18) in C:\Documents and Settings\It's Dale\Desktop\xampplite\htdocs\frm_handler.php on line 31

    Code:
    <?php
    
    session_start();
    
    $con = mysql_connect("localhost","peter","abc123");
    
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    
    mysql_select_db("WB", $con);
    
    if ( isset( $_POST['remove'] ))
    {
      $tmp = $_SESSION['records'];
      $remove = $_POST['remove'];
      var_dump( $remove );
      foreach ($remove as $K => $V)
      {
        $query = "delete from Birds where Name='" .$tmp[$V]->Name. "'";
        mysql_query( $query );
        if (mysql_errno())
        {
          echo "Could not remove : " .$tmp[$K]->Name. "<br />\n";
          echo "Error Number : " .mysql_errno(). "<br />\n";
        }
        unset( $tmp[$V] );
      }
      $_SESSION['records'] =& $tmp;
      header("Location: 1.php");
    }
    ?>
    Many Thanks,

  5. #30
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Byron,

    I've just noticed, this isn't quite what I need.

    How do I load the data into an array ($records) and display the contents of the $records array with individual check boxes next to each record. Upon a check box being checked and a delete button being clicked, all records not including the selected one should be copied into a separate array ($temp). The contents of the $temp array should be copied into the database/table overwriting any existing data present.

    Instead of deleting from the table, and updating the array. Is this possible?

    Many Thanks,

  6. #31
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Salchester View Post
    Byron,
    The contents of the $temp array should be copied into the database/table overwriting any existing data present.

    Instead of deleting from the table, and updating the array. Is this possible?

    Many Thanks,
    Where is this existing data and how is it stored ?
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  7. #32
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array Manipulation

    Byron,

    What do you mean?

    Many Thanks,

  8. #33
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What existing data do you want to overwrite ?
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  9. #34
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array Manipulation

    Byron,

    Existing records (Name, Species, Sex).
    May I ask why?

    Many Thanks,

  10. #35
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Salchester View Post
    Existing records (Name, Species, Sex).
    May I ask why?
    You have not changed any values in the above records, simply deleted the ones marked for deletion. Why overwrite data that exist with the same values ?
    I do not think I quite understand what you are trying to accomplish.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  11. #36
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array Manipulation

    Byron,

    The database/table won't contain exactly the same records, as the deleted record will not be inside the $temp array to be copied inside the database/table.

    Make sense?

    Many Thank,

  12. #37
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What makes sense is to delete the records marked from the data base, as the code in my form handler does. The results are going to be the same with a lot less effort.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  13. #38
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array Manipulation

    Quote Originally Posted by byron3@earthlink View Post
    You have not changed any values in the above records, simply deleted the ones marked for deletion. Why overwrite data that exist with the same values ?
    I do not think I quite understand what you are trying to accomplish.
    Byron,

    The end result will be different due to "Numeric Array Store" values being used to identify check boxes with each records.

    The trouble is not all the birds will have names, thats why I want to try and use arrays & use "Numeric Array Store" values to identify check boxes with records. This will also come in useful later for more functionality.

    Go to the following URL Address I have uploaded a kind of diagram, on what I need?

    http://www.freewebs.com/mail2go/WB/Diagram.jpg

    As it's quite difficult to explain any further.

    Many Thanks,

  14. #39
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I looked and you have the code.....
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  15. #40
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array Manipulation

    Quote Originally Posted by byron3@earthlink View Post
    I looked and you have the code.....
    Byron,

    Where abouts?

    Many Thanks,


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
  •