gpt4 book ai didi

php - 更新数据库表行

转载 作者:行者123 更新时间:2023-11-29 11:30:59 25 4
gpt4 key购买 nike

我尝试更新数据库表行。当用户选择选项"is"时,但我收到错误

Notice: Trying to get property of non-object

使用此行$queryOptionId = $wpdb->query($wpdb->prepare("UPDATEresume_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

关于php - 更新数据库表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37430396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com