SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php > edits mysql table information

    Ok im on the last part of my project before i can make it look pretty
    and im stuck!
    i need fresh eyes on this
    (let me know if there are other mistakes as well there is always room for improvement right!!)

    so my whole app works ok except for the last part i want users to be able to edit or update info in mysql table in this case ONLY the last row "Notepad"
    users will be able to type any information re: that "cust/account/student/" w/e...
    everything works ok but the information is not being updated in the table and i get the following error at the end when trying to update the info

    "you have connected successfullyERROR"


    Thanks in advance sorry for posting so much code


    data
    table name=clbacks

    final.php

    PHP Code:
    ////this part works ok 
    while ($row mysqli_fetch_array($resultMYSQLI_ASSOC)) {

        echo 
    "<tr><td>";
        echo 
    $row['CustCl'];
        echo 
    "</td> <td>";
        echo 
    $row['CustInfo'];
        echo 
    "</td><td>";
        echo 
    $row['CustNumber'];
        echo 
    "</td><td>";
        echo 
    $row['CSR'];
        echo 
    "</td><td>";
        echo 
    $row['Time'];
        echo 
    "</td><td>";
        echo 
    $row['ID'];
        echo 
    "</td><td>";
        echo 
    $row['Notepad'];
        echo 
    "</td><td>";
        echo 
    "<a href=\"update2.php?id=" $row['ID'] . "\">Update Notepad</a>";
        
        echo 
    "</td></tr>";

    }
    echo 
    "</table>";

    // end of main if statement
    ?> 


    update2.php

    PHP Code:
    <?php

    //connect to the database
    include('connect.php');


    // get value of id that sent from address bar

    $id=$_GET['id'];


    // Retrieve data from database 
    $sql="SELECT * FROM clbacks WHERE id='$id'";
    $result=mysql_query($sql);

    $rows=mysql_fetch_array($result);
    ?>
    <table width="400" border="1" cellspacing="1" cellpadding="0">
    <tr>
    <form name="form1" method="post" action="update_ac.php">
    <td>
    <table width="100%" border="1" cellspacing="1" cellpadding="0">
    <tr>
    <td>&nbsp;</td>
    <td colspan="3"><strong>Update Notepad</strong> </td>
    </tr>

    <tr>
    <td align="center">&nbsp;</td>

    <td align="center"><strong>Notepad</strong></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td align="center"><input name="name" type="text" id="name" value="<? echo $rows['Notepad']; ?>"></td>

    <tr>

    <td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"></td>
    <td align="center"><input type="submit" name="Submit" value="Submit"></td>

    </tr>
    </table>
    </td>
    </form>
    </tr>
    </table>

    <?

    // close connection 
    mysql_close();

    ?>
    update_ac.php
    PHP Code:
    <?php

    //connect to the database
    include('connect.php');


    // update data in mysql database 
    $sql="UPDATE clbacks SET Notepad='$Notepad' WHERE id='$id'";
    $result=mysql_query($sql);

    // if successfully updated. 
    if($result){
    echo 
    "Successful";
    echo 
    "<BR>";
    echo 
    "<a href='final.php'>View result</a>";
    }

    else {
    echo 
    "ERROR";
    }

    ?>

  2. #2
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by davidmp3 View Post
    update_ac.php
    PHP Code:
    <?php

    //connect to the database
    include('connect.php');


    // update data in mysql database 
    $sql="UPDATE clbacks SET Notepad='$Notepad' WHERE id='$id'";
    $result=mysql_query($sql);

    // if successfully updated. 
    if($result){
    echo 
    "Successful";
    echo 
    "<BR>";
    echo 
    "<a href='final.php'>View result</a>";
    }

    else {
    echo 
    "ERROR";
    }

    ?>
    It'd probably help if $Notepad and $id had values!

  3. #3
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the quick reply Jay P.
    Not home at the moment. but does this looks right ?

    PHP Code:
    <?php 

    //connect to the database 
    include('connect.php'); 


    // update data in mysql database  

    $Notepad $_POST['Notepad'];
    $id $_POST['id'];

    $sql="UPDATE clbacks SET Notepad='$Notepad' VALUES ('$Notepad', '$ID') WHERE id='$id'" 

    $result=mysql_query($sql); 

    // if successfully updated.  
    if($result){ 
    echo 
    "Successful"
    echo 
    "<BR>"
    echo 
    "<a href='final.php'>View result</a>"


    else { 
    echo 
    "ERROR"


    ?>


Tags for this Thread

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
  •