1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

database does not update

Discussion in 'Web Design & Development' started by bagmaendene, Feb 20, 2013.

Thread Status:
Not open for further replies.
  1. bagmaendene

    bagmaendene Thread Starter

    Joined:
    Feb 20, 2013
    Messages:
    1
    Hej all,

    I hate a little question, this is the script i have:

    HTML:
    <?php
    session_start();
    
    include_once('../includes/connection.php');
    include_once('../includes/article.php');
    
    $article = new Article;
    
    if (isset($_SESSION['logged_in'])) {
        if (isset($_GET['id'])) {
            $id = $_GET['id'];
        $query = $pdo->prepare('SELECT FROM articles WHERE article_id =?');
        $query->bindValue(1, $id);
        $query->execute();
        
        header('Location: edit.php');
            
        }
    
        
        $articles = $article->fetch_all();
        
        
    ?>
    <html>
    <head>
    </head>
    <body>
        <h4>Edit Article</h4>
        
    <?php if (isset($error)) {  ?>
        <small style="color:#aa0000"><?php echo $error; ?>
    <?php } ?>
    
        
    
        
        <form action="edit.php" method="post">
        <?php foreach ($articles as $article) { ?>
            
            ID: <?php echo $article['article_id']; ?><br /><br />
            Article Title: <b><?php echo $article['article_title']; ?></b> <br /><br />
            Text: <br/> <textarea rows="15" name="article_content" cols="50"><?php echo $article['article_content']; ?></textarea><br /><br />
            <input type="submit" value="Edit Article"> <br/ >
            <?php } 
            
            if( isset($_POST['article_id']))
            {
                $newcontent = $_POST['article_content'];
                $id = $_POST['article_id'];
                $query = $pdo->query("UPDATE article_content SET article_content='$newcontent' WHERE article_id='$id'");
                
                
            }
            
            
            ?>
        </form>    
        
        
        
    <a href="index.php">&larr; Back</a>
    
    </body>
    </html>
    <?php
    } else {
        header('Location: index.php');
    }
    
    
    
    ?>
    Now the problem is that when i hit my edit button the database doesnt update, it just looks like the pages refreshes.
    Could somebody help me i really cant find out what the problem is.

    Thanks in advance
     
  2. JiminSA

    JiminSA

    Joined:
    Dec 15, 2011
    Messages:
    3,328
    First Name:
    Jim
    Try removing the single quotes from around $id in this update line...
    PHP:
                $query $pdo->query("UPDATE article_content SET article_content='$newcontent' WHERE article_id='$id'");
    :)
     
  3. JiminSA

    JiminSA

    Joined:
    Dec 15, 2011
    Messages:
    3,328
    First Name:
    Jim
    Did you try it that way?
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1090293

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice