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 5 of 5
  1. #1
    mwm
    mwm is offline
    Regular Coder
    Join Date
    Oct 2005
    Posts
    174
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't see values in array! Please Correct Me

    I'm pulling info from a table in mysql that has notes on customers. I can see the values being pulled by echoing them on the edit1.php page. But when the array is sent to editfinal.php I do not see the values of the array. What i want to do is update the note_tbl. What am I doing wrong? Am I not doing a step?

    Thanks


    ###### This is edit1.php
    PHP Code:
    <?
    session_start
    ();
    include 
    "conn.php";
    $id=$_GET['id'];

    echo 
    "<input type=hidden name=id value=$id>";
    ?>
        


    <html>
    <body>

    <h1><p align="center"></center></h1>
    <head><link rel=stylesheet type=text/css href=menu.css></HEAD>
    <h3><p align="center"><font color=red>Edit Contact</font></center></a></h3>
    <p align="center"><a href="search.php?"><img src="search.gif" width='14' height='14' border="0"></a> 
    <a href="addressbook.php?"><img src="home.gif" width='14' height='14' border="0"></a></center>
     <FORM ACTION="editfinal.php" METHOD="POST">
    <p align="center"><input type="submit" name="submit" value="Save"> 
    </center>

    <?
    $mysql 
    " select note from note_tbl where id ='$id'";
    echo 
    $mysql;

    $resultmysql_query($mysql) or die ("Can't connect");


    while(
    $row mysql_fetch_array($result)) {
    echo 
    "<br>";
    echo 
    $row['note'];
    echo 
    "<input type=hidden name=note[] value='".$note[$i]."'>";
    }




    ?>
    ####### This is editfinal.php

    PHP Code:
    <?
    session_start
    ();
    include 
    "conn.php";

    echo 
    $id;



    echo 
    "<pre>";
    print_r($_POST);
    echo 
    "</pre>";


    $sql="UPDATE note_tbl SET note = '$note' where id = '$id'  ";
    $result=mysql_query($sql) or die ("Could Not Update");


    header("Location:addressbook.php");

    ?>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The two obvious problems I can see is your "id" hidden input is not inside the <form> tags, and you are missing a </form> tag. Always validate your HTML markup.

    Other issues you should fix are:

    -Use <?php rather than <?

    -Don't assume register_globals is turned on. Use $_POST['notes'] rather than $notes.

    -Also, if you have more than one row in your note_tbl with the same id, your update query is going to write the same note to all rows, and you are ambiguous as to which value in your $_POST['note'] array you are using (You did build an array in your first script).

  • #3
    mwm
    mwm is offline
    Regular Coder
    Join Date
    Oct 2005
    Posts
    174
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. made changes you suggested and i can now see the array values on the editfinal.php page. But I still can't up date the table. What do you all think.

    ###edit1.php
    PHP Code:
    <?
    session_start
    ();
    include 
    "conn.php";
    $id=$_GET['id'];


    ?>
        


    <html>
    <body>

    <h1><p align="center"></center></h1>
    <head><link rel=stylesheet type=text/css href=menu.css></HEAD>
    <h3><p align="center"><font color=red>Edit Contact</font></center></a></h3>
    <p align="center"><a href="search.php?"><img src="search.gif" width='14' height='14' border="0"></a> 
    <a href="addressbook.php?"><img src="home.gif" width='14' height='14' border="0"></a></center>
     <FORM ACTION="editfinal.php" METHOD="POST">
    <p align="center"><input type="submit" name="submit" value="Save"> 
    </center>

    <?
    $mysql 
    " select noteid,note from note_tbl where id ='$id'"



    $resultmysql_query($mysql) or die ("Can't connect");
    echo 
    "<p align = center>";
    echo 
    "</center>";
    echo 
    "<table border=\"0\">";
    echo 
    "<th></th>";

    if (
    mysql_num_rows($result) == 0)
    {
    echo 
    "<center><font color = red>None!</font></center>";

    else
    {


    $j 0;

    while (
    $row mysql_fetch_array($result)) {

    $note$row['note'];
    $noteid$row['noteid'];

    for (
    $i0$i<count($note); $i ++) {

    }

        echo (
    $j++%2==0) ? '<tr bgcolor="#FFFFCC">' '<tr bgcolor="#FFFFCC">';
    print 
    '  
        <td>
    <input type="text" name="note[]" value="'
    .$row['note'].'">

        </td>
        '
    ;
    echo 
    "<td>" .($row['noteid']) . "</td>";
    echo 
    "<input type= hidden name=noteid[] value=$noteid>";
    print 
    '  
        <td>

    <a href="addtouch.php?id='
    .$row['id'].'"></a>

        </td>
        '
    ;

    }
    }
    echo 
    '</table>';
    echo 
    "</center>";

    echo 
    "<hr>";

    ?>

    </body>
    </form>
    </html>
    ####editfinal.php
    PHP Code:
    <?
    session_start
    ();
    include 
    "conn.php";

    echo 
    $id;

    $noteid $_POST['noteid'];

    echo 
    "<pre>";
    print_r($_POST);
    echo 
    "</pre>";




        
         
    $query1  "update note_tbl 
                      set note = '{$_POST['note']}'
                      where noteid   = '{$_POST['noteid']}'"
    ;
                     

          
    $result1 mysql_query($query1) or die ("Could not close"); 


    ?>

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    It looks like you are just about there. As you have it set up, you have created a couple of 2-level arrays $_POST['note'] and $_POST['noteid'], so you need to create a loop to update each row in your table, rather than performing only one update query as you are doing right now.

    PHP Code:
    for ($i 0$i count($_POST['note']); $i++) {
         
    $query1  "update note_tbl 
                      set note = '{$_POST['note'][$i]}'
                      where noteid   = '{$_POST['noteid'][$i]}'"

          
    $result1 mysql_query($query1) or die ("Bad update query, sql = ".$query1." and error is ".mysql_error()); 


  • #5
    mwm
    mwm is offline
    Regular Coder
    Join Date
    Oct 2005
    Posts
    174
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yep that worked great. Thank You


  •  

    Posting Permissions

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