User014019 User014019 - 1 year ago 68
MySQL Question

Update database table row

I tried to update a database table row. when the user choose an option "Yes", but i getting an error

Notice: Trying to get property of non-object

with this line
$queryOptionId = $wpdb->query($wpdb->prepare("UPDATE resume_databank SET = '$optionAnswer' WHERE id = %d", $optionId->id));

How to fix this?


$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 = $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));

Answer Source

Missing column name after SET statement and use $optionId instead $optionId->id

    $queryOptionId = $wpdb->query($wpdb->prepare("UPDATE resume_databank 
SET = '$optionAnswer' WHERE id = %d", $optionId->id));
 ^^^^^// missing column name

Try to add 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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download