Jump to content

PHP to update mysql database


jbdesign

Recommended Posts

Hello all, first post here so i hope i'm doing this right and am putting this into the right place.

Im in the process of integrating a blog into my website, mostly it's set up however i'm currently working on the code to update the posts (theres only 2 parts a title and a comments[which is in actual fact the post content itself]). The code succsefully completes without any errors but for some reason it does not actually update the mysql database.. the code i'm using is as follows:

 

<?php
require_once('header.php');
include "../blog/blogconfig.php";

if(isset($_POST['submit'])){
$update="UPDATE eq_blogarticle SET title='".$_POST['title']."',comments='".$_POST['comment']."' WHERE artid='$aid'";
if(!mysql_query($update)){
echo mysql_error();
}else{
header("location:blog.php?action=listmsgs");
exit;
}
}
?>
<?php
// get value of aid that sent from address bar by blog.php?action=listmsgs
$aid=$_GET['aid'];

// Retrieve data from database
$sql="SELECT * FROM eq_blogarticle WHERE artid='$aid'";
$result=mysql_query($sql);

$row=mysql_fetch_array($result);
?>

<form name="form2" method="post" action="update.php">
<script type="text/javascript">var SITE_URL="<?php echo SITE_URL;?>";</script>
<script type="text/javascript" src="<?php echo SITE_URL;?>/includes/js/nicEdit.js"></script>
<script type="text/javascript">
	//<![CDATA[
		bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
		//]]>
</script>
<body>
<table width="100%" border="0" cellspacing="1">
  <tr>
    <td colspan="2" class="temptitle">Equidisc Blog</td>
  </tr>
  <tr>
    <td width="74%" valign="top">
<table>
Edit Blog Post
<br>
<br>
Title:
<br>
<input name="title" type="text" class="input" id="title" value="<? echo $row['title']; ?>">
<br>
<br>
<span class="style1 style2 style3">Blog Post:</span>
<br>
<br>
<textarea name="comments" cols="55" rows="12" class="input" id="comments"><? echo stripslashes($row['comments']); ?></textarea>
<br>
<br>
<input name="aid" type="hidden" id="aid" value="<? echo $row['artid']; ?>">
<input type="submit" name="submit" value="Submit">
</form>
</table>
</td>
    <td width="26%" valign="top"><table width="100%" border="0" cellspacing="1">
      <tr>
        <td colspan="2"><img src="../blog/images/fb.gif" width="16" height="16" /> <strong>Blog Menu</strong></td>
        </tr>
       <tr>
        <td><a href="blog.php">Home</a></td>
       </tr>
      <tr>
        <td><a href="blog.php?action=newblogpost">New Post </a></td>
        </tr>
      <tr>
        <td><a href="blog.php?action=listmsgs">Manage Posts </a></td>
        </tr>
    </table></td>
  </tr>
</table>
</body>
<?php
require_once('footer.php');
?>

 

Explanation: header/footer.php obvious

../blog/blogconfig.php holds my mysql connection settings and connects to the sql, this is the same config as is used for creating the new posts which i have no issues with so i dont think the issue lays there. If i run the query on phpmyadmin with dummy data it works fine and updates the entry..

Any help would be very much appreciated as i'm at the end of my tether with this!.

Thanks in advance.

Jo

Link to comment
Share on other sites

Thanks so much, didnt think of doing that! after spending hours staring at it trying to figure it out echoing helped me track down the issue in no time! Turns out it wasnt passing the id number through properly from my post, changing the query to:

$update="UPDATE eq_blogarticle SET title='".$_POST['title']."',comments='".$_POST['comments']."' WHERE artid='".$_POST['aid']."'";

solved it

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.