Jump to content

Problem with updating database


phpnewbie1979

Recommended Posts

Hi Forum

 

I'm creating a script for  my websites where I add, edit, delete messages from the site. I'm using php functions to do it. The problem I'm running into is getting the edit function to work properly. The information is not posting to the edit form nor is it updating the database. I included both functions I'm using. The first function displays the list of messages and places a link to either edit or delete the message. The second function is suppose to edit the message. If anyone can help me out with this it would be great.

 

Thanks.

 

 

function show_list () {
$admincheck = login::loginCheck('Admin', true);
if($admincheck !== true) {
//DO NOTHING: ADMIN NOT LOGGED
} else {
global $config, $conn, $jscript;
//	$jscript .= '<link href="' . $config['baseurl'] . '/addons/announcement/announcement.css" rel="stylesheet" type="text/css" />' . "\r\n";
require_once($config['basepath'].'/include/misc.inc.php');
$misc = new misc();

// SELECT: LIST OF MESSAGES FROM DATABASE
	$sql = 'SELECT announcementdb_id, announcementdb_date, announcementdb_subject, announcementdb_message FROM ' . $config['table_prefix'] . 'announcementdb ORDER BY announcementdb_date ASC';
$recordSet = $conn->Execute($sql) or DIE("Could not perform requested task");
$display .='<a href="index.php?action=addon_announcement_newmessage">Add new message</a>';
while (!$recordSet->EOF) {
$display .= '<table>';
      $display .= '<tr>';
      $display .= '<td>'.$recordSet->fields['announcementdb_date'].'</td><td><a href="index.php?action=announcement_message&announcementdb_id='.$recordSet->fields['announcementdb_id'].'">'.$recordSet->fields['announcementdb_subject'].'</a></td>
      <form id="announcement_edit" name= announcement_edit" method="post" action="index.php?action=addon_announcement_edit"><td><input type="hidden" name="announcementdb_id" 
      value="'.$recordSet->fields['announcementdb_id'].'"><input type="submit" value="edit">
      </td></form>

      <form id="announcement_delete" name= announcement_delete" method="post" action="index.php?action=addon_announcement_deletemessage"><td><input type="hidden" name="announcementdb_id" value="'.$recordSet->fields['announcementdb_id'].'"><input type="submit" value="delete">
      </td></form>';
      $display .= '</tr>';
$recordSet->MoveNext();
}
}
      $display .= '</table>';
      
return $display;
}

 

function announcement_edit() {
$admincheck = login::loginCheck('Admin', true);
if($admincheck !== true) {
//DO NOTHING: ADMIN NOT LOGGED
} else {
global $config, $conn;
//    $jscript .= '<link href="' . $config['baseurl'] . '/addons/announcement/announcement.css" rel="stylesheet" type="text/css" />' . "\r\n"; 
    require_once($config['basepath'].'/include/misc.inc.php'); 
    $misc = new misc(); 
if(!isset($_POST['submit'])) {
$self = $SERVER['PHP_SELF'];
$id = $_POST['announcementdb_id']; 
$date = $_POST[''.$recordSet->fields['announcementdb_date'].''];
$subject = $_POST[''.$recordSet->fields['announcementdb_subject'].''];
$message = $recordSet->fields['announcementdb_message']; 
$sql = 'SELECT announcementdb_id, announcementdb_date, announcementdb_subject, announcementdb_message FROM ' . $config['table_prefix'] . 'announcementdb WHERE announcementdb_id = '.$recordSet->fields['announcementdb_id'].'';
$recordSet = $conn->Execute($sql);
$display .= '<form id="editmessage name="editmessage" method="post" action="'.$self.'">';

$display .= '<fieldset>';
$display .= '<legend>Edit Message</legend>';
$display .= '<table>';
$display .= '<tr>';
$display .= '<td>Date</td><td><input type="text" name="announcementdb_date" value="'.$date.'"></td>';
$display .= '</tr>';
$display .= '<tr>';
$display .= '<td>Subject</td><td><input type="text" name="announcementdb_subject" value="'.$subject.'"></td>';
$display .= '</tr>';
$display .= '<tr>';
$display .= '<td>Message</td><td><textarea name="announcementdb_messge" cols= 80 rows=10 value="$message"></textarea></td>';
$display .= '</tr>';
$display .= '<tr>';
$display .= '<td><input type="submit" name="submit" id="submit" value="submit"></td>';
$display .= '</tr>';
$display .= '</table>';
$display .= '</fieldset>';
$display .= '</form>';
return $display;
} else {
global $config, $conn;
//    $jscript .= '<link href="' . $config['baseurl'] . '/addons/announcement/announcement.css" rel="stylesheet" type="text/css" />' . "\r\n"; 
    require_once($config['basepath'].'/include/misc.inc.php'); 
    $misc = new misc(); 
$announcementdb_date = $_POST['announcementdb_date']; 
$announcementdb_subject = $_POST['$subject']; 
$annuoncementdb_message = $_POST['announcementdb_message']; 
$sql2= 'UPDATE  ' . $config['table_prefix'] . 'announcementdb SET announcementdb_date=\' '.$announcementdb_date.' \', announcementdb_subject=\' '.$announcementdb_subject.' \', announcementdb_message =\' '.$announcementdb_message.' \' WHERE annoucementdb_id = \' '.$announcementdb_id.' \'';
$recordSet = $conn->Execute($sql2);
$display .= 'message updated';
return $display;
}
}
}

Link to comment
https://forums.phpfreaks.com/topic/200187-problem-with-updating-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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