2023-09-10, 10:14 PM
Currently trying to build a plugin and while all other parts are working as expected to the edit script, which is supposed to update the database table, is not.
When clicking submit after making changes I get the redirect success message. However, when I look at the database and go to edit or view this particular one no changes were made to the field I updated. If anyone has any idea why I'd greatly appreciate feedback.
I'm also throwing "Trying to access array offset on value of type null" error for the following that I'm not sure why?:
postingtables_usercp_edit Template
$mybb->get_input("action") == "postingtables-edit" PHP
When clicking submit after making changes I get the redirect success message. However, when I look at the database and go to edit or view this particular one no changes were made to the field I updated. If anyone has any idea why I'd greatly appreciate feedback.
I'm also throwing "Trying to access array offset on value of type null" error for the following that I'm not sure why?:
- line 355: $lang->postingtables_editing = $lang->sprintf($lang->postingtables_editing, $ptable['name']);
- line 356-360: $mybb->input['ptname'] = $ptable['name']; $mybb->input['ptheader'] = $ptable['header']; $mybb->input['ptfooter'] = $ptable['footer']; $mybb->input['ptspeech'] = $ptable['speech']; $mybb->input['ptspeechalt'] = $ptable['speech_alt'];
postingtables_usercp_edit Template
<html>
<head>
<title>{$lang->user_cp} - {$lang->postingtables_edit}</title>
{$headerinclude}
</head>
<body>
{$header}
<table width="100%" border="0" align="center">
<tr>
{$usercpnav}
<td valign="top">
{$errors}
<form action="usercp.php" method="post">
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
<input type="hidden" name="action" value="postingtables-edit" />
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder">
<tr>
<td class="thead" colspan="50"><strong>{$lang->postingtables_editing}</strong></td>
</tr>
<tr>
<td class="tcat" colspan="50">{$lang->postingtables_create_warning}</td>
</tr>
<tr>
<td class="trow1" width="40%" valign="top"><strong>{$lang->postingtables_table_name}</strong><br /><span class="smalltext">{$lang->postingtables_table_name_desc}</span></td>
<td class="trow1" valign="top"><input type="text" name="ptname" class="textbox" maxlength="250" value="{$mybb->input['ptname']}" style="width: 99%;" /></td>
</tr>
<tr>
<td class="trow2" width="40%" valign="top"><strong>{$lang->postingtables_table_header}</strong><br /><span class="smalltext">{$lang->postingtables_table_header_desc}</span></td>
<td class="trow2" valign="top"><textarea name="ptheader" rows="10" cols="50" style="width: 99%;">{$mybb->input['ptheader']}</textarea></td>
</tr>
<tr>
<td class="trow1" width="40%" valign="top"><strong>{$lang->postingtables_table_footer}</strong><br /><span class="smalltext">{$lang->postingtables_table_footer_desc}</span></td>
<td class="trow1" valign="top"><textarea name="ptfooter" rows="10" cols="50" style="width: 99%;">{$mybb->input['ptfooter']}</textarea></td>
</tr>
<tr>
<td class="trow1" width="40%" valign="top"><strong>{$lang->postingtables_table_speech}</strong><br /><span class="smalltext">{$lang->postingtables_table_speech_desc}</span></td>
<td class="trow1" valign="top"><input type="text" name="ptspeech" class="textbox" value="{$mybb->input['ptspeech']}" style="width: 99%;" /></td>
</tr>
<tr>
<td class="trow1" width="40%" valign="top"><strong>{$lang->postingtables_table_speech_alt}</strong><br /><span class="smalltext">{$lang->postingtables_table_speech_alt_desc}</span></td>
<td class="trow1" valign="top"><input type="text" name="ptspeechalt" class="textbox" value="{$mybb->input['ptspeechalt']}" style="width: 99%;" /></td>
</tr>
</table>
<br />
<div class="float_right">
<input type="submit" class="button" name="submit" value="Submit & Save" />
</div>
</form>
</td>
</tr>
</table>
{$footer}
</body>
</html>
$mybb->get_input("action") == "postingtables-edit" PHP
global $mybb, $db, $theme, $templates, $header, $headerinclude, $footer, $usercpnav, $lang, $errors;
$lang->load("postingtables");
$ptableid = intval($mybb->input['ptid']);
add_breadcrumb($lang->nav_usercp,"usercp.php");
add_breadcrumb("$lang->postingtables_name","usercp.php?action=postingtables");
add_breadcrumb("$lang->postingtables_edit","usercp.php?action=postingtables-edit");
$fetch_query = $db->simple_select("postingtables", "*", "ptid = $ptableid");
$ptable = $db->fetch_array($fetch_query);
$lang->postingtables_editing = $lang->sprintf($lang->postingtables_editing, $ptable['name']);
$mybb->input['ptname'] = $ptable['name'];
$mybb->input['ptheader'] = $ptable['header'];
$mybb->input['ptfooter'] = $ptable['footer'];
$mybb->input['ptspeech'] = $ptable['speech'];
$mybb->input['ptspeechalt'] = $ptable['speech_alt'];
if ($mybb->request_method == "post") {
verify_post_check($mybb->input['my_post_key']);
$dataupdates = array(
"name" => $db->escape_string($mybb->get_input("ptname")),
"header" => $db->escape_string($mybb->get_input("ptheader")),
"footer" => $db->escape_string($mybb->get_input("ptfooter")),
"speech" => $db->escape_string($mybb->get_input("ptspeech")),
"speech_alt" => $db->escape_string($mybb->get_input("ptspeechalt"))
);
$db->update_query("postingtables", $dataupdates, "ptid = $ptableid");
redirect("usercp.php?action=postingtables", $lang->postingtables_edit_success_redirect);
}