我正在检查数据是否存在而不是插入。所以我正在使用if else条件。 看一看代码。
if($_POST['save_appointment']){
if(is_user_logged_in()){
$user_appontment_sql = "select * from ".$wpdb->prefix."table where status=1 AND event_id=1 AND user_id=2";
$get_user_data_row = $wpdb->get_row($user_appontment_sql);
if(isset($get_user_data_row)){
echo '<div class="saved_thing">'.__('You have already filled form for appointment for this date').'</div>';
}
else{
$push_form_data=array();
if($_POST['username']){
$user_data=array('username'=>$_POST['username'],'usernamelabel'=>$_POST['usernamelabel']);
$user_name=array('name_data'=>$user_data);
array_push($push_form_data,$user_name);
}
$form_data_all=json_encode($push_form_data);
$done = add_appointment($_POST,$form_data_all);
if($done==true)
{
echo '<div class="saved_thing">'.__('Mange tak. Du hører fra os snarest !').'</div>';
$user_status_mail = "select * from ".$wpdb->prefix."volunteer_app_setting where meta_key='admin_email' OR meta_key='email_send_status' OR meta_key='email_template_accept'";
$get_appointment_send_mail = $wpdb->get_results($user_status_mail);
$event_metadata=unserialize($event_datas_count[0]->pstdata_value);
if($event_metadata['notification_mail']=='1')
{
require_once(dirname(dirname(dirname(dirname(__FILE__))))."/volunteer-appointment/mail/send_mail.php");
$selected_template=$event_meta_data['mail_temp_form_submission'];
$from=$get_appointment_send_mail[0]->meta_value;
$data=array('first_name'=>$_POST['username'],'send_to_admin'=>1,'event_date'=>get_post_meta($_POST['event_id'],'event-date',true),'event_name'=>get_the_title());
$current_user = wp_get_current_user();
$send_mail=mail_user($current_user->user_email,$selected_template,$from,$data);
if($send_mail){
echo '<div class="saved_thing">'.__('E-mail notifikation afsendt til administrator').'</div>';
}
else{
//echo "<script>alert('Mail not send');</script>";
}
}
}
else
{
echo '<div class="saved_thing">'.__('Fejl!!!').'</div>';
}
//}
return;
}
}
}
首先我们检查数据,如果它不存在,则转到else部分。
如果部分一直存在,即使数据不存在但保存数据也会进入。在其他部分add_appointment()
是问题所在。此功能正在保存数据。
我调试
代码正在检查条件,如果数据库中不存在数据而不是转到else部分,则使用函数add_appointment()
保存数据,并在执行函数后再转到其他条件并显示消息You have already filled form for appointment for this date
< / p>
答案 0 :(得分:0)
将您的if条件更改为
from - &gt; if(isset($get_user_data_row))
到 - &gt; if(!empty($get_user_data_row))
答案 1 :(得分:0)
如果未找到任何行,则会返回if($get_user_data_row > 0) {
// Some code here
} else {
// Some functions here
}
app = Flask(__name__)
api = Api(app)
class Analysis(Resource):
def get(self, runtime):
result2 = result1.to_json(orient='records')
return json.loads(result2)
api.add_resource(Analysis, '/sample/<runtime>')
if __name__ == '__main__':
app.run(port='8080')