Activity Stream
48,167 MEMBERS
63679 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14
  1.     
    #11
    Respected Member
    If the id comes from the browser line it is
    $id=intval($_GET['id']);
    not
    $id=intval($_POST['id']);

  2.   Sponsored Links

  3.     
    #12
    Member
    Website's:
    epicimagehost.com
    I think you only need to update the 'update_ac.php' file:

    PHP Code: 
    <?php
    //I assume this is update_ac.php
    $host="localhost"// Host name 
    $username=""// Mysql username 
    $password=""// Mysql password 
    $db_name="test"// Database name 
    $tbl_name="test_mysql"// Table name 

    // Connect to server and select database.
    mysql_connect("$host""$username""$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");

    // update data in mysql database 
    $sql='UPDATE '.$tbl_name.' SET username="'.mysql_real_escape_string($_POST['username']).'", password="'.mysql_real_escape_string($_POST['password']).'", email="'.mysql_real_escape_string($_POST['password']).'" WHERE id='.intval($_POST['id']);

    /*
    this query might work aswell ( note the different type of quotes used ) but use the one above
    $sql="UPDATE $tbl_name SET username='mysql_real_escape_string($_POST['username'])', password='mysql_real_escape_string($_POST['password'])', email='mysql_real_escape_string($_POST['password'])' WHERE id=intval($_POST['id'])";

    */

    /*
        In php these are thesame:

        $cool = "awesome";

        echo "lol this is $cool";  <- this shows : lol this is awesome
        echo 'lol this is '. $cool;  <- this shows : lol this is awesome
    */

    /*
        the dot ( . ) acts as glue.
        For example:

        $this = 'Hi';
        $still = ', how';
        $works = ' are you';

        echo $this . $still . $works . 'doing?'; <- This shows : Hi, how are you doing?
        
        so does this btw:
        echo $this.$still.$works.'doing?'; ( the space doesn't matter )
    */

    /*
        Now about the $_POST[''] variable I used in your query ( line 14 )
        
        Whenever you submit a form [ remember the <form method="post".. u used in your HTML ? ] to a script, the data you send
        gets stored in the $_POST array.
        
        For example:
        <input type="text" name="KWWHunction" /> ( let's assume you entered sucks and pressed submit )
        
        it will be handled in the script with:
        $_POST['KWWHunction']
        
        So if you do this in your script:
        
        echo $_POST['KWWHunction'];
        
        That will show the word sucks
    */

    $result=mysql_query($sql);

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

    else {
    echo 
    "ERROR";
    }

    ?>
    edit:
    Added a bit of info as it seems you are quite new with this.
    Not sure if what I said is correct, i'm really tired atm

  4.     
    #13
    Member
    I started writing this for my site.


    Just adapt it for you DB, it seems odd to use three files.

    PHP Code: 
    <?
        $query 
    "SELECT * FROM site WHERE active=1";
        
    $result mysql_query($query) or trigger_error("SQL"E_USER_ERROR);
        echo 
    "<form action='' method='POST'>"
            
    ."<table cellpadding=2 cellspacing=1 border=1 bgcolor=white align=center width=850>"
            
    ."<tr style='background:lightblue'><th>Project ID</th><th>Project Name</th><th>Total Hits Paid</th><th>Hits Sent</th><th>Site URL</th><th>Active</th><th>Select</th></tr>";

        while(
    $row mysql_fetch_assoc($result))
            {
            
    extract($row);
            echo 
    "<tr><td>$id</td><td>$sitename</td><td>$maxhits</td><td>$totalhits</td><td>$siteurl</td><td>$active</td><td><input type='checkbox' name='id' value='$id'></input></td></tr>";
            }
        echo
    "<tr><td colspan='7' align='right'><input type='submit' name='edit' value='Edit'/></td></tr>";

        if (isset(
    $_POST['edit']))
            {
            
    $editid $_POST['id'];
            
    $query "SELECT * FROM site WHERE id=$editid";
            
    $result mysql_query($query) or trigger_error("SQL"E_USER_ERROR);
            while(
    $row mysql_fetch_assoc($result))
                {
                
    extract($row);
                echo 
    "<tr><td>$id</td><td><input type='hidden' name='id' value='$id'><input type=text name=sitename value='$sitename'/></td><td><input type='text' name='maxhits' value='$maxhits'/></td><td><input type=text name='totalhits' value='$totalhits'/></td><td><input type=text name='siteurl' value='$siteurl'/></td><td><input size='2' type=text name='active' value='$active'></td><td></input></td></tr>";
                }
            echo 
    "<tr><td colspan='7' align='right'><input type='submit' name='update' value='Update'/></td></tr>";
            }

        if (isset(
    $_POST['update']))
            {
            
    $id $_POST['id'];
            
    $sitename $_POST['sitename'];
            
    $maxhits $_POST['maxhits'];
            
    $totalhits $_POST['totalhits'];
            
    $siteurl $_POST['siteurl'];
            
    $active $_POST['active'];
            
    mysql_query("UPDATE site SET sitename='$sitename', maxhits='$maxhits', totalhits='$totalhits', siteurl='$siteurl', active='$active' WHERE id='$id'");
            echo 
    "<meta http-equiv='refresh' content='0;url=''/>";
              }

        echo 
    "</table>";
    ?>

  5.     
    #14
    Member
    Website's:
    itleech.com fixdownloads.com downtoolz.com itcoder.us
    Thx guys i will try and let u now what happens
    Signature too big, removed by Staff

Page 2 of 2 FirstFirst 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

BE SOCIAL