vendredi 8 mai 2015

PHP - return to another page using header

I was trying to update data in database using oop php but after I call function update I should return the user to view all page , so i used header but then whenever i try to view update page, it views view all page. what should i do?

<body>

    <form  method='POST'>
<table>
<tr>
<td>id</td>
<td>
<input type='text' name='id' value='' ></td>
</tr>
<tr>
<td>price</td>
<td>
<input type='text' name='price' value='' ></td>
</tr>
<tr>
<td></td>
<td>
<input type='submit' name='commit' value='Submit'>
</td>
</tr>

</table>
</form> 
</body>
</html>

<?php
require_once ('database.php');
require_once ('admin.php');
$object= new admin();
if (isset($_POST['commit'])) {
$id    = $object->clean($_POST['id']);
$price = $object->clean($_POST['price']);
$object->update_sport($id ,$price);
}
header("C:\wamp\www\omnia\viewsports.php");

this is viewsports.php

<head>
        <title>Sports</title>
    </head>

    <body>
         <h1>Sports</h1>
         <h3>Use ID to update</h3>
        <?php 
        require_once 'database.php';
        $obj=new databaseClass();
        echo '<table>';
        echo '<tr bgcolor="white">';
        echo ' <td>ID</td><td>Name</td><td>Price</td>';
        echo ' </tr>';
        $sql="SELECT sport.id, sport.name, sport.price FROM sport";

        $result=  mysql_query($sql);
        $i=0;
        while($row =  mysql_fetch_assoc($result)){
            echo  '<tr><td>' .$row['id'].'</td><td>'
            .$row['name'].'</td><td>'
            .$row['price'].'</td>'
            .'<td><a href="delete_sport.php?id=' . $row['id'].'">Delete</a></td>'
            .'<td><a href="update_sport.php?id=' . $row['id'].'">Update</a></td></tr>';
            $i++;
        }
        echo'</table>';
        ?>
         <a href="add_sport.php">Add</a>
    </body>
</html>

Aucun commentaire:

Enregistrer un commentaire