updating database

Discussion in 'PHP' started by baris22, Nov 5, 2008.

  1. #1
    hello,

    I am trying to update database and i have got a small problem. After i press submit everything is ok but i get the page which is the one i had before the update done. I mean the database is still getting updated but on my page i see the information which is before the update.

    What can i do to get the new updated page after i press submit.

    here is the code

    
    
    <?php
    
    if($result1){
    header("location:on.php");
    }
    
    
    $host="localhost"; // Host name 
    $username="xxx"; // Mysql username 
    $password="xxx"; // Mysql password 
    $db_name="xxx"; // Database name 
    $tbl_name="xxx"; // Table name 
    
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $sql="SELECT * FROM $tbl_name LIMIT 0, 20";
    $result=mysql_query($sql);
    
    // Count table rows 
    $count=mysql_num_rows($result);
    ?>
    <table width="500" border="0" cellspacing="1" cellpadding="0">
    <form name="form1" method="post" action="">
    <tr> 
    <td>
    <table width="500" border="0" cellspacing="1" cellpadding="0">
    
    
    <tr>
    <td align="center"><strong>Id</strong></td>
    <td align="center"><strong>Name</strong></td>
    <td align="center"><strong>Lastname</strong></td>
    
    </tr>
    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td>
    <td align="center"><input name="title[]" type="text" id="title" value="<? echo $rows['title']; ?>"></td>
    <td align="center"><input name="description[]" type="text" id="description" value="<? echo $rows['description']; ?>"></td>
    </tr>
    <?php
    }
    ?>
    <tr>
    <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
    </tr>
    </table>
    </td>
    </tr>
    </form>
    </table>
    <?php
    // Check if button name "Submit" is active, do this 
    if($Submit){
    for($i=0;$i<$count;$i++){
    $sql1="UPDATE $tbl_name SET title='$title[$i]', description='$description[$i]' WHERE id='$id[$i]'";
    $result1=mysql_query($sql1);
    }
    }
    
    mysql_close();
    ?>
    
    
    
    
    PHP:
     
    baris22, Nov 5, 2008 IP
  2. GreatMetro

    GreatMetro Peon

    Messages:
    117
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $result1=mysql_query($sql1);
    }
    if($result1){
    header("location: on.php");
    }
    }
     
    GreatMetro, Nov 5, 2008 IP
  3. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    same problem, it does update but i have to refresh the page. if i do not refresh i get the old page plus i get an error now saying

    Warning: Cannot modify header information - headers already sent by (output started at /home/x/public_html/x/on/on.php:32) in /home/x/public_html/x/on/on.php on line 64
     
    baris22, Nov 5, 2008 IP