Jump to content

Updating Script Not Working


neverforget98

Recommended Posts

Hello. I have my main page (index.php) which lists all of our Social Update Requests and add request page (add.php) which you can add a request from all done and properly functioning, but it came time to do the updating request page (viewer.php) and I just can't get it to work. It pulls the data correctly and puts them into the fields, but it doesn't actually update the database or put any messages on the page.

 

Please help!

 

This is the code:

 

<?php
session_start();
require("../inc/mysql.php");
require("../inc/Membership.class.php");
$Member = new Membership($DBH);
require("../inc/membership.php");
//test user permissions
if(!$Member->test_perms(2))
{
//No perms, echo error or forward or something
header( 'Location: ../nopermission.php' ) ;
}
?>

<html>
<head>
<title>Social Update Request | OUB's Integrated Services</title>
<meta name="description" content="">
<meta name="author" content="Brandin Arsenault, OUB">
   <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
   <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<script src="./ajax/libs/jquery/1/jquery.min.js"></script>
<link rel="stylesheet" href="css/960.css" />
<link rel="stylesheet" href="style.css" />
<script src="js/scripts.js"></script>
<script type="text/javascript" language="javascript" src="jquery-1.2.6.min.js"></script>
<div id="message_box">
 <?php {
echo "Hello, " . $Member->get_field("real_name");

}?>
</div>
</head>
<body>
<br /><br /><br /><br />
<?php
include 'header.php';
?>
<br /><br />
<center><h5>SOCIAL UPDATE REQUEST EDITOR</center>
<br />
<?php
require("db.php");
$id =$_REQUEST['id'];
$result = mysql_query("SELECT * FROM socialupdate WHERE id  = '$id'");
$test = mysql_fetch_array($result);
if (!$result)
 {
 die("Error: Data not found..");
 }
   $requestee=$test['requestee'] ;
   $type=$test['type'] ;	
   $category=$test['category'] ;
   $content=$test['content'] ;
   $status=$test['status'] ;
if(isset($_POST['save']))
{

   $requestee_save=$_POST['requestee'] ;
   $type_save=$_POST['type'] ;	
   $category_save=$_POST['category'] ;
   $content_save=$_POST['content'] ;
   $status_save=$_POST['status'] ;
    if(empty($requestee) || empty($type) || empty($category) || empty($content) || empty($appnoapp))
 if(empty($requestee))
 {
  echo "<font color='red'>Requestee field is empty but report added sucessfully. Please update on the Incident List to include this.</font><br/>";
 }
 if(empty($type))
 {
  echo "<font color='red'>Type field is empty but report added sucessfully. Please update on the Incident List to include this.</font><br/>";
 }
 if(empty($category))
 {
  echo "<font color='red'>Category field is empty but report added sucessfully. Please update on the Incident List to include this.</font><br/>";
 }
 if(empty($content))
 {
  echo "<font color='red'>Content field is empty but report added sucessfully. Please update on the Incident List to include this.</font><br/>";
 }
 if(empty($status))
 {
  echo "<font color='red'>Status field is empty.</font><br/>";
 }
else
{

$result=mysql_query("UPDATE incidents SET requestee='$requestee_save', type='$type_save',
  category='$category_save',content='$content_save',status='$status_save' WHERE id = '$id'");

if(!$result){
    // query failed with an error of some kind, do some error reporting here -
    die('UPDATE query failed. ' . mysql_error());
} else {
    // query executed, test if it actually updated the row
    if(!mysql_affected_rows()){
		    // row was not updated. This is rare and would generally require the use of the IGNORE keyword in the query to cause a query error to become a warning only.
		    die('UPDATE query ran, but did not update the row.');
    } else {
		    // query ran and did update the row -
		    echo "<font color='green'>Request updated successfully.</font>";
		    echo "<br/><a href='index.php'>Return to Request List</a>";
    }
}
}

header("Location: index.php");  
}
mysql_close($conn);
?>
<center><form method="post">
<table>
<tr>
 <td>Requestee:</td>
 <td><input type="text" name="requestee_save" value="<?php echo $requestee ?>" /></td>
</tr>
<tr>
 <td>Type:</td>
 <td>
  <?php
   // This value is supposed to have whatever stored in the database. I am just using it here to
   // set it to the value I need in order to demonstrate the concept for you
   $yesNoValue = "$type";
  ?>
  <select name="type_save">
   <option value="/" <?php echo ($yesNoValue=="/") ? 'selected="selected"': '' ?> ></option>
   <option value="Quote" <?php echo ($yesNoValue=="Quote") ? 'selected="selected"': '' ?> >Quote</option>
   <option value="Video" <?php echo ($yesNoValue=="Video") ? 'selected="selected"': '' ?> >Video</option>
   <option value="Image" <?php echo ($yesNoValue=="Image") ? 'selected="selected"': '' ?> >Image</option>
   <option value="Website" <?php echo ($yesNoValue=="Website") ? 'selected="selected"': '' ?> >Website</option>
   <option value="Other" <?php echo ($yesNoValue=="Other") ? 'selected="selected"': '' ?> >Other</option>
  </select>
 </td>
</tr>
<tr>
 <td>Category:</td>
 <td>
  <?php
   // This value is supposed to have whatever stored in the database. I am just using it here to
   // set it to the value I need in order to demonstrate the concept for you
   $yesNoValue = "$category";
  ?>
  <select name="category_save">
   <option value="/" <?php echo ($yesNoValue=="/") ? 'selected="selected"': '' ?> ></option>
   <option value="Anti-Bullying" <?php echo ($yesNoValue=="Anti-Bullying") ? 'selected="selected"': '' ?> >Anti-Bullying</option>
   <option value="Self-Esteem/Self-Worth" <?php echo ($yesNoValue=="Self-Esteem/Self-Worth") ? 'selected="selected"': '' ?> >Self-Esteem/Self-Worth</option>
   <option value="Song/Music" <?php echo ($yesNoValue=="Song/Music") ? 'selected="selected"': '' ?> >Song/Music</option>
   <option value="Other" <?php echo ($yesNoValue=="Other") ? 'selected="selected"': '' ?> >Other</option>
  </select>
 </td>
</tr>
<tr>
 <td>Content/Link<br />Images can be uploaded <br />to www.TinyPic.com<br />Max 250 characters. Exceeding must<br />be uploaded to www.PasteBin.com and<br />insert the link here.</td>
 <td><textarea input type="text" name="content_save" cols="25" rows="5"><?php echo $content ?></textarea></td>
</tr>
<tr>
 <td>Status:</td>
 <td>
  <?php
   // This value is supposed to have whatever stored in the database. I am just using it here to
   // set it to the value I need in order to demonstrate the concept for you
   $yesNoValue = "$status";
  ?>
  <select name="status_save">
   <option value="/" <?php echo ($yesNoValue=="/") ? 'selected="selected"': '' ?> ></option>
   <option value="Pending" <?php echo ($yesNoValue=="Pending") ? 'selected="selected"': '' ?> >Pending</option>
   <option value="Approved" <?php echo ($yesNoValue=="Approved") ? 'selected="selected"': '' ?> >Approved</option>
   <option value="Not Approved" <?php echo ($yesNoValue=="Not Approved") ? 'selected="selected"': '' ?> >Not Approved</option>
  </select>
 </td>
</tr>
<tr>
 <td> </td>
 <td><input type="submit" name="update" value="Update Request" /></td>
</tr>
</form></table></center>
<?php
include 'logout.php';
?>
</body>
</html>

Link to comment
Share on other sites

The name of your form field is not 'save', so $_POST['save'] will never be true.

 

I was able to determine this by looking at your logic, but you should have been able to determine this by troubleshooting what your code and data are doing. If you expect your code to take a specific execution path, put in echo statements to check to make sure it is. If you expect variables to exist and have specific values, put in echo/print_r/var_dump statements to check exactly what they contain.

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.