doukucai0099 2017-07-04 12:08
浏览 65
已采纳

数据没有上传到mysql

I'm learning how to integrate php scripts into wordpress.

I've created a function:

function sollicitatie_formulier() { 
ob_start(); 
include 'scripts/solliciteer-form.php'; 
return ob_get_clean(); 
} 
add_shortcode( 'sollicitatie_formulier', 'sollicitatie_formulier' );

The script that I'm calling looks like this:

<?php

global $wpdb; 

if(isset($_POST['btn-upload'])) 
{ 
$table = sollicitaties; 
$file = rand(1000,100000)."-".$_FILES['afile']['name']; 
$file_size = $_FILES['afile']['size']; 
$file_type = $_FILES['afile']['type']; 
$file_loc = $_FILES['afile']['tmp_name']; 
$folder="wp-content/themes/jobify-extended/uploads/"; 
$data = array( 
'voornaam' => $_POST['avoornaam'], 
'familienaam' => $_POST['afamilienaam'], 
'comment' => $_POST['amsg'], 
'afile' => rand(1000,100000)."-".$_FILES['afile']['name'], 
'size' => $_FILES['afile']['size'], 
'type' => $_FILES['afile']['type'], 



); 

// new file size in KB 
$new_size = $file_size/1024; 
// new file size in KB 

// make file name in lower case 
$new_file_name = strtolower($file); 
// make file name in lower case 

$final_file=str_replace(' ','-',$new_file_name); 

$format = array( 
'%s', 
'%s',
'%s',
'%s',
'%s',
'%s',
); 

if(move_uploaded_file($file_loc,$folder.$final_file)) 
{ 
$success=$wpdb->insert( $table, $data, $format,$folder); 
if($success){ 
?> 
<script> 
alert('successfully uploaded'); 
window.location.href='sollicitatie-formulier?success'; 
</script> 
<?php 

} 
} 
} 


else { 
?> 

<form action="" method="post" enctype="multipart/form-data"> 
<label for="voornaam">Voornaam: </label><input type="text" name="avoornaam" required=""> 
<label for="familienaam">Familienaam: </label><input type="text" name="afamilienaam" required=""> 
<label for="comment">bericht: </label><textarea type="text" name="amsg"></textarea> 
<input type="file" name="afile" accept=".pdf, .doc, .docx" /> 
<input type="submit" name="btn-upload" value="upload"</input> 
</form> 

<?php 
if(isset($_GET['success'])) 
{ 
?> 
<label>Kandidaat succesvol toegevoegd... <a href="/bekijk/">click hier om kandidaten te bekijken.</a></label> 
<?php 
} 
else if(isset($_GET['fail'])) 
{ 
?> 
<label>Oeps...een probleem! Probeer opnieuw</label> 
<?php 
} 
else 
{ 
?> 
<label>Try to upload any files(PDF, DOC, DOCX)</label> 

<?php } } 

?>

My file gets uploaded to my folder but no data is being sent to my database. I'm trying to understand what the issue is but I can't figure it out. I hope you don't mind explain aswel what I'm doing wrong than just giving the correct answer.

  • 写回答

1条回答 默认 最新

  • duandi6531 2017-07-04 12:53
    关注

    You forgot to add $wpdb->prefix.

    Example

    global $wpdb;
    
    $table = $wpdb->prefix.'sollicitaties';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?