在数据库中保存数据时出错

时间:2014-11-26 04:59:18

标签: php mysql

我可以使用唯一名称上传目录中的文件,但不会在数据库中保存任何内容。请帮我指出代码中的错误。

<?php 
function findext ($filename) 
{ 
$filename = strtolower($filename); 
$exts = split("[/\\.]", $filename); 
$n = count($exts)-1; 
$exts = $exts[$n]; 
return $exts; 
}

$ext=findext($_FILES['photo']['name']);
$name=basename($_FILES['photo']['name'],$ext).'_'.rand(1000,9999).'.'.$ext;
$target='Resume/'.$name;

//This gets all the other information from the form 

$Name=$_POST['Name'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$CV='________/'.$target;

// Connects to your Database 
mysql_connect("localhost", "", "") or die(mysql_error()) ; 
mysql_select_db("database") or die(mysql_error()) ; 

//Writes the information to the database 
mysql_query("INSERT INTO `candidate` VALUES ('$Name','$phone','$email','$CV')") ; 

//Writes the photo to the server 
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
{ 
echo "Thank You for submitting your CV. We or Employers would revert to you shortly."; 
} 
else 
{  
echo "Thank You for submitting your information. However, you didn't upload your CV."; 
} 
?> 

1 个答案:

答案 0 :(得分:1)

必须进行适当的连接才能生成正确的查询,如果只添加更少的字段,只需说出它们是什么

mysql_query("INSERT INTO `candidate` (name,phone,email,cv) VALUES ('".$Name."','".$phone."','".$email."','".$CV."')") ;