I am building a dashboard with custom User Data. Each element on the dashboard goes into the loop and shows the related information regarding that user.I am able to show the the custom field using session and loops but i need to update the information as well, somehow it is not updating. Please help with this:
<?php
global $wpdb;
$table_name = $wpdb->prefix . 'contract';
$wsid = $_SESSION['wedding-values'];
$results = $wpdb->get_results( "SELECT * FROM $table_name WHERE id=$wsid " );
if ( $results ) {
foreach ( $results as $result ){
$wcname=$result->cname;
$wctname=$result->ctname;
$waddress=$result->address;
$wmobile=$result->mobile;
$wemail=$result->email;
$wdate=$result->Date;
$id=$result->id;
}
}
if ( isset( $_POST['submit'] ) ){
$wpdb->update($table_name,array(
'cname'=>$_POST['cname'],array('id'=>$wsid))
);
}
?>
Html:
<div id="col-md-9">
<form action="" method="post">
<table>
<tr>
<td><p style="color: red"> Couple Name </p></td>
<td><input type=text name=cname placeholder=<?php echo $wcname;?>></td>
</tr>
<tr>
<td><p style="color: red"> Contact Name </p></td>
<td><?php echo $wctname;?></td>
</tr>
<tr>
<td><p style="color: red"> Address </p></td>
<td><?php echo $waddress;?></td>
</tr>
<tr>
<td><p style="color: red"> Mobile </p></td>
<td><?php echo $wmobile;?></td>
</tr>
<tr>
<td><p style="color: red"> Email</p></td>
<td><?php echo $wemail;?></td>
</tr>
<tr>
<td><p style="color: red"> Date Submitted</p></td>
<td><?php echo $wdate;?></td>
</tr>
<tr>
<td><input type="submit" name="editsave" value="Edit and Save" ></td>
</tr>
</table>
</form>
</div>