PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Tue Aug 11, 2020 5:34 pm

All times are UTC - 5 hours

Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Update database issue
PostPosted: Tue Mar 31, 2015 3:30 am 
Forum Newbie

Joined: Tue Mar 31, 2015 3:24 am
Posts: 5
Hi all, I'm having some difficulty as to why my code is not working. No errors appear, data is pulled from the table in the database, but dows not update. I think it is something to do with the post but I am unsure. It's only 3 fields at the moment to update.

Can anyone help? Thanks.

Syntax: [ Download ] [ Hide ]


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="/styles/style.css">
<link rel="stylesheet" href="/styles/responsive.css">
<script src=""></script>
<div class="container">
        <div class="admin_header">
        <?php include('includes/header.php'); ?>
        <div class="main_nav">
        <?php include('includes/admin_nav.php'); ?>
        <div class="content">
<div class="news">
<div class="heading">
        echo "
        Hello again, "
                header ("location: login.php");

<div class="article_wrap">
<div class="articles"><div class="articles_heading_wrap"><div class="articles_heading">
  <h4>Edit Snippet</h4></div></div><div class="update"> (random)</div></div>
include ('../db/db_connection.php');
include ('../db/security.php');

// if the form was submitted/posted, update the record
    //write query
    $sql = "UPDATE
                Title = ?,
                Link = ?,
                Text = ?
                id= ?"
    $stmt = $db->prepare($sql);
    // you can bind params this way,
    // if you want to see the other way, see our add.php
        mysqli_stmt_bind_param($stmt, 'sssi', $Title, $Link, $Text, $id);
    // execute the update statement
        echo "Entry Updated.";
        // close the prepared statement
        die("Unable to update.");
 * select the record to be edited,
 * you can also use prepared statement here,
 * but my hosting provider seems it does not support the mysqli get_result() function
 * you can use it like this one
 * so it I'm going to use $mysqli->real_escape_string() this time.

$sql = "SELECT
            id, Title, Link, Text
            id = \""
. $db->real_escape_string($_GET['id']) . "\"
// execute the sql query
$result = $db->query( $sql );
//get the result
$row = $result->fetch_assoc();
// php's extract() makes $row['Title'] to $Title automatically
//disconnect from database
<!--we have our html form here where new user information will be entered-->
<form action='edit.php?id=<?php echo $id; ?>' method='post' border='0'>
            <td><input name='Title' type='text' value='<?php echo $Title;  ?>' size="80" /></td>
            <td><input name='Link' type='text' value='<?php echo $Link;  ?>' size="80" /></td>
            <td><textarea name="Text" cols="80" rows="6"><?php echo $Text;  ?></textarea></td>
                <!-- so that we could identify what record is to be updated -->
                <input type='hidden' name='id' value='<?php echo $id ?>' />
                <input type='submit' value='Update!' />
                <a href='index.php'>Back to index</a>

        <div class="footer">
        <?php include('/includes/footer.php'); ?>
        $('.handle').on('click', function(){
                $('main_nav ul').toggleClass('showing');

PostPosted: Tue Mar 31, 2015 3:56 am 
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
Syntax: [ Download ] [ Hide ]
mysqli_stmt_bind_param($stmt, 'sssi', $Title, $Link, $Text, $id);

That line does not belong there. Take a look at the rest of the code around it and you'll see that it doesn't fit in.

PostPosted: Tue Mar 31, 2015 6:45 am 
Forum Newbie

Joined: Tue Mar 31, 2015 3:24 am
Posts: 5
Thanks for that, I knew that was going to be something really stupid (usually is). Good spot ;)

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: No registered users and 8 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group