Jump to content

Table not updating


graham23s

Recommended Posts

Hi GUys,

 

this simple script won't seem to update the table, when i echo it out it looks fine , it even says its updated but still nothing in mysql.

 

code is:

 

<?php
     // Get the users details from mysql...//////////////////////////////////////////////
     $query_1 = "SELECT * FROM `membership` WHERE `username`='$member'";
     $result_1 = mysql_query($query_1) or die (mysql_error());
     $row = mysql_fetch_array($result_1);
     
     $id = $row['id'];
     $username = $row['username'];
     $user_class = $row['user_class'];
     
     ## if the user isnt an admin no further ############################################
     if($user_class != "Site Administrator") {
     
     echo "<br /><span class=\"error\">Sorry, Only Admins Can Post Announcements.</span><br /><br />";
     include("includes/footer.php");
     exit;
     
     }
         
     if(isset($_POST['submit'])) {  
     
     ## the post data ###################################################################
     $announce_2 = CleanPosts($_POST['announce_body'], 1);
     $user_id_from_post = $_POST['secret'];
     
     if(empty($announce_2)) {
     
     echo "<br /><span class=\"error\">Sorry, Please Don't Leave The Announcement Field Blank.</span><br /><br />";
     include("includes/footer.php");
     exit;
     
     }
         
     $query_update = "UPDATE `announcements` SET `user_id`='$user_id_from_post',`announcement`='$announce_2' WHERE `id`='$id'";
     $result_update = mysql_query($query_update) or die (mysql_error());
     
     echo $query_update;
     
     if($result_update) {
     
     echo "<br /><span class=\"success\">Thank You, New Announcement Added.</span><br /><br />";
     include("includes/footer.php");
     exit;     
     
     }
          
     
     } else {
     
     ## get the announcements ###########################################################
     $query_ann = "SELECT * FROM `announcements`";
     $result_ann = mysql_query($query_ann) or die (mysql_error());
     $rows = mysql_fetch_array($result_ann) or die (mysql_error());
     $users_id = $rows['user_id'];
     $announce = $rows['announcement'];
     
     echo "<br /><h3 align=\"center\"> Hi, <a href=\"user_details.php?id=$id\">$username</a></h3>";
     echo '<br />
           <table width="400" border="1" bordercolor="#000000" cellspacing="0" cellpadding="3" />
           <form action="announcement.php" method="POST" enctype="multipart/form-data" />
           <th bgcolor="#004E98"><font color="#ffffff">Add An Anouncement</font></th>
           <tr>
           <td align="center"><textarea name="announce_body" rows="10" cols="30"/>'.$announce.'</textarea></td>
           </tr>
           <tr>
           <td bgcolor="#004E98" align="right"/><input type="submit" name="submit" value="Update Signature >>>" />
                                                <input type="hidden" name="secret" value="'.$users_id.'" />
           </td>
           </table>
           </form>
           <br />';     
     
     }
?>

 

im totally stumped lol

 

cheers

 

Graham

Link to comment
Share on other sites

Have you got access to running MySQL commands via an interface such as phpMyAdmin / MySQL Front / Shell Access?

 

If so, copy the query once it's been echoed out and try it using one of those interfaces mentioned above. Let me know if that works ok.

 

Ed.

Link to comment
Share on other sites

If the code is not throwing errors then that simply means there's no errors in the syntax. But, I think your problem lies in the sequence of events. For example, your first bit of code is executed before the submit button is pressed. You then 'exit' from that which may clear the variables you'd laid out there. Especially the one for $id which you use later in the script in your 'IF' statement for updating. That variable is vital in identifying the record to update. Your IF statement for the 'submit' should probably be the first item in your script.

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.