我试图更新数据库表行。当用户选择一个选项“是”,但我得到一个错误
Notice: Trying to get property of non-object
用这行
$queryOptionId = $wpdb->query($wpdb->prepare("UPDATE resume_databank SET = '$optionAnswer' WHERE id = %d", $optionId->id));
如何解决?
PHP:
$result_position= $wpdb->get_results($wpdb->prepare("SELECT id, submit_time, last_name, first_name, middle_name, mobile_number, email, location, position, message, attachment_resume_id FROM resume_databank WHERE position= '" . $list_position . "' ORDER BY position ASC LIMIT $start,$end", OBJECT));
echo '<table>';
echo '<tr>';
$optionId = 0;
echo '<th>Submit Time</th>';
echo '<th>Last Name</th>';
echo '<th>First Name</th>';
echo '<th>Middle Name</th>';
echo '<th>Mobile Number</th>';
echo '<th>Email</th>';
echo '<th>Location</th>';
echo '<th>Position</th>';
echo '<th>Message</th>';
echo '<th>Resume</th>';
echo '<th>Processed?</th>';
//foreach ($result_position as $record_s){
for ($i=0;$i < $totalPosition ;++$i ){
$row = $result_position[$i];
//$optionId++;
$optionId = $result_position[0]->id;
echo '<tr>';
echo '<td id="submit_time">' . $result_position[0]->submit_time . '</td>';
echo '<td id="last_name">' . $result_position[0]->last_name . '</td>';
echo '<td id="first_name">' . $result_position[0]->first_name . '</td>';
echo '<td id="middle_name">' . $result_position[0]->middle_name . '</td>';
echo '<td id="mobile_number">' . $result_position[0]->mobile_number . '</td>';
echo '<td id="email">' . $result_position[0]->email . '</td>';
echo '<td id="location">' . $result_position[0]->location . '</td>';
echo '<td id="position">' . $result_position[0]->position . '</td>';
echo '<td id="message">' . $result_position[0]->message . '</td>';
echo '<td id="resumeFile'.$optionId.'"><a href=' . wp_get_attachment_url($result_position[0]->attachment_resume_id) . '>Download Resume</a></td>';
echo '<td id="radioOption><label for="Yes">Yes</label>
<input type="radio" id="processedOptionYes'.$optionId.'" name="processedOption" value="Yes" onclick="proccessedCheck('.$optionId.',\'Yes\')"/>
<label for="No">No</label>
<input type="radio" id="processedOptionNo'.$optionId.'" name="processedOption" value="No" onclick="proccessedCheck('.$optionId.',\'No\')"/></td>';
echo '</tr>';
}
echo '</table>';
if (isset($_POST['optionAnswer']) && $_POST['optionAnswer']){
$optionId = $_POST['optionId'];
$optionAnswer = $_POST['optionAnswer'];
echo $optionId;
$queryOptionId = $wpdb->query($wpdb->prepare("UPDATE resume_databank SET = '$optionAnswer' WHERE id = %d", $optionId->id));
}
最佳答案
SET语句后缺少列名称,请使用$optionId
代替$optionId->id
$queryOptionId = $wpdb->query($wpdb->prepare("UPDATE resume_databank
SET = '$optionAnswer' WHERE id = %d", $optionId->id));
^^^^^// missing column name
尝试添加列名
$queryOptionId = $wpdb->query($wpdb->prepare("UPDATE resume_databank
SET COLUMN_NAME= '$optionAnswer' WHERE id = %d", $optionId));
// add your table column name in place of `COLUMN_NAME` AFTER SET