Jump to content

pezzie

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Posts posted by pezzie

  1. Thanks for that.

    [color=red]index.php[/color]


    <?php
    session_start();

    if (!$_SESSION["valid_user"])
    {
    // User not logged in, redirect to login page
    Header("Location: login.php");
    }



    // Display Member information
    echo "<p>User ID: " . $_SESSION["valid_id"];
    echo "<p>Username: " . $_SESSION["valid_user"];
    echo "<p>Logged in: " . date("m/d/Y", $_SESSION["valid_time"]);

    // Display Delete, Edit and add article links
    echo "<p><a href=\"articles.php\">VIEW all Articles</a></p>";
    echo "<p><a href=\"add.php\">Add New Article</a></p>";

    echo"<br>";
    // Display logout link
    echo "<p><a href=\"logout.php\">Click here to logout!</a></p>";
    ?>




    [color=red]edit.php[/color]

    <?
    // Connect database
    include("dbConfig.php");

    // Get all records in all columns from table and put it in $result.
    $result=mysql_query("select * from articles ORDER BY id");

    /*Split records in $result by table rows and put them in $row.
    Make it looping by while statement. */
    while($row=mysql_fetch_assoc($result)){

    // Output
    echo "ID : {$row['id']} <br/>";
    echo "Title : {$row['title']} <br/>";
    echo "Content : {$row['content']} <br/>";
    echo "Filename : {$row['filename']} <hr>";

    // Add a link with a parameter(id) and it's value.
    echo '<a href="update.php?id='.$row['id'].'">Update</a>';
    echo "<HR>";

    }

    mysql_close();
    ?>


    [color=red]update.php[/color]

    <?php
    // Connect database.
    include("dbConfig.php");

    if($_POST['Submit']){
    // Get parameters from form.
    $id=$_POST['id'];
    $title=$_POST['title'];
    $content=$_POST['content'];
    $filename=$_POST['filename'];
    //mysql_query("update articles set title='$title', content='$content', filename='$filename' where id='$id'");
    $q="UPDATE `articles` SET title='$title', content='$content', filename='$filename' where id='$id'";
    $r = mysql_query($q);
    if ( !$r )
      {
     
      echo "ERROR Please try again";
    }
    else
    {

    header("location:edit.php");
    exit;
    }
    }

    // Get id parameter (GET method) from edit.php
    $id=$_GET['id'];


    // Get records in all columns from table where column id equal in $id and put it in $result.
    $result=mysql_query("select * from articles where id='$id'");

    // Split records in $result by table rows and put them in $row.
    $row=mysql_fetch_assoc($result);
    echo $id;



    ?>


    <html>
    <body>
    <form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
    <p>Name :
    <input name="name" type="text" id="title" value="<? echo $row['title']; ?>"/>
    <br />
    Email :
    <input name="email" type="text" id="content" value="<? echo $row['content']; ?>"/>
    <br />
    Tel :
    <input name="tel" type="text" id="filename" value="<? echo $row['filename']; ?>"/>
    </p>
    <p>
    <input type="submit" name="Submit" value="Submit" />
    </p>
    </form>
    </body>
    </html>

  2. Hi

    i want to get data from mySQL and wish to delete or update it.

    The delete is fine but when it comes to update, nothing happens at all.

    i want the data to be present in the textboxes so that the user does not have to type the whole thing in again.  [color=red]PLEASE PLEASE help. i need it by tomorrow.[/color]

    Thank you.

    this is my code:

    [color=red]edit.php[/color]

    <?
    // Connect database
    include("dbConfig.php");

    // Get all records in all columns from table and put it in $result.
    $result=mysql_query("select * from articles ORDER BY id");

    /*Split records in $result by table rows and put them in $row.
    Make it looping by while statement. */
    while($row=mysql_fetch_assoc($result)){

    // Output
    echo "ID : {$row['id']} <br/>";
    echo "Title : {$row['title']} <br/>";
    echo "Content : {$row['content']} <br/>";
    echo "Filename : {$row['filename']} <hr>";

    // Add a link with a parameter(id) and it's value.
    echo '<a href="update.php?id='.$row['id'].'">Update</a>';
    echo "<HR>";

    }

    mysql_close();
    ?>
    //------------------------------------------------------------------------------------------



    [color=red]update.php[/color]

    <?
    // Connect database.
    include("dbConfig.php");
    if($Submit){
    // Get parameters from form.
    $id=$_POST['id'];
    $title=$_POST['title'];
    $content=$_POST['content'];
    $filename=$_POST['filename'];
    mysql_query("update articles set title='$title', content='$content', filename='$filename' where id='$id'");
    header("location:edit.php");


    // Get id parameter (GET method) from edit.php
    $id=$_GET['id'];

    // Get records in all columns from table where column id equal in $id and put it in $result.
    //$result=mysql_query("select * from articles where id='$id'");

    // Split records in $result by table rows and put them in $row.
    $row=mysql_fetch_assoc($result);
    }
    ?>
    <html>
    <body>
    <form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
    <p>Name :
    <input name="name" type="text" id="title" value="<? echo $row['title']; ?>"/>
    <br />
    Email :
    <input name="email" type="text" id="content" value="<? echo $row['content']; ?>"/>
    <br />
    Tel :
    <input name="tel" type="text" id="filename" value="<? echo $row['filename']; ?>"/>
    </p>
    <p>
    <input type="submit" name="Submit" value="Submit" />
    </p>
    </form>
    </body>
    </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.