"无法连接到MySQL服务器",尽管连接正在进行测试

时间:2014-12-16 20:25:00

标签: php mysql database jotform

我在000webhost服务器上的thankyou.php文件夹中存储了以下public_html,以及我要连接的MySQL数据库。该页面是一个表单,它是从jotform嵌入的,在提交时我希望将答案发布到MySQL数据库。

我已经测试了一百万次代码,它看起来运行正常,但我仍然得到错误:

  

感谢您输入销售详细信息无法连接到mysql6.000webhost.com上的MySQL服务器' (4)

我已经创建了另一个test.php来测试连接,它提供了连接。你认为这是jotform的问题吗?我已经读过其他用户设法获得连接工作,所以我认为这可能是mysql6000webhost的一个问题?

<?php
$fullname = $_POST['clientmanager'];

print "<p><p>";

print " Thankyou $fullname for entering your sales details";


// This function will run within each post array including multi-dimensional arrays 
function ExtendedAddslash(&$params)
{ 
        foreach ($params as &$var) {
            // check if $var is an array. If yes, it will start another ExtendedAddslash() function to loop to each key inside.
            is_array($var) ? ExtendedAddslash($var) : $var=addslashes($var);
        }
}

// Initialize ExtendedAddslash() function for every $_POST variable
ExtendedAddslash($_POST);      

$submission_id = $_POST['submission_id']; 
$formID = $_POST['formID'];
$IP = $_POST['ip'];
$Placement = $_POST['selectplacement4'];
$Client_Name= $_POST['name7'];
$Client_Address= $_POST['address'][0] ."-". $_POST['address'][1]."-". $_POST['address'][2]."-". $_POST['address'][3]."-". $_POST['address'][4]."-". $_POST['address'][5];
$Client_Phone= $_POST['phonenumber'][0] ."-". $_POST['phonenumber'][1];
$Attn_Name1= $_POST['name'];
$Attn_Email1= $_POST['email15'];
$Attn_Name2= $_POST['name2'];
$Attn_Email2= $_POST['email2'];
$Candidate_Name= $_POST['candidatename'];
$Position= $_POST['position'];
$Start_Date= $_POST['startdate'][0] ."-". $_POST['startdate'][1]."-". $_POST['startdate'][2];
$frequency= $_POST['frequency'];
$rate= $_POST['rate24'];
$Units= $_POST['noof'];
$Salary= $_POST['salary'];
$feepercent= $_POST['fee'];
$Reason= $_POST['input33'];
$feeamt= $_POST['feeamt'];
$RecruiterName= $_POST['recruitername'];
$NewRecName= $_POST['entername'];
$RecruiterPercent= $_POST['recruiter'];
$ClientMgrName= $_POST['clientmanager'];
$ClientMgrPercent= $_POST['clientmanager36'];
$TotalFeePercent= $_POST['associatefees37'];
$TotalFee= $_POST['associatefees'];


$db_host = 'mysql6.000webhost.com';
$db_username = 'a8748341_blt';
$db_password = '******';
$db_name = 'a8748341_bltrec';

mysql_connect( $db_host, $db_username, $db_password) or die(mysql_error());
mysql_select_db($db_name); 

// search submission ID

$query = "SELECT * FROM bltrecruiting where submission_id = $submission_id";
$sqlsearch = mysql_query($query);
$resultcount = mysql_numrows($sqlsearch);

if ($resultcount > 0) {

    mysql_query("UPDATE `bltrecruiting` SET 
                                `Placement` = '$Placement',
                                `Client_Name` = '$Client_Name',
                                `Client_Address` = '$Client_Address',
                                `Client_Phone` = '$Client_Phone',
                                `Attn_Name1` = '$Attn_Name1',
                                `Attn_Email1` = '$Attn_Email1',
                                `Attn_Name2` = '$Attn_Name2',
                                `Attn_Email2` = '$Attn_Email2'

                             WHERE `submission_id` = '$submission_id'") 
     or die(mysql_error());

} else {

    mysql_query("INSERT INTO `bltrecruiting` (submission_id, formID, IP, Placement, Client_Name, Client_Address, Client_Phone, Attn_Name1, Attn_Email1, Attn_Name2, Attn_Email2, Candidate_Name, Position, Start_Date, frequency, rate, Units, Salary, feepercent, Reason, feeamt, RecruiterName, NewRecName, RecruiterPercent, ClientMgrName, ClientMgrPercent, TotalFeePercent, TotalFee) 
                               VALUES ('submission_id, formID, IP, Placement, Client_Name, Client_Address, Client_Phone, Attn_Name1, Attn_Email1, Attn_Name2, Attn_Email2, Candidate_Name, Position, Start_Date, frequency, rate, Units, Salary, feepercent, Reason, feeamt, RecruiterName, NewRecName, RecruiterPercent, ClientMgrName, ClientMgrPercent, TotalFeePercent, TotalFee) ") 
    or die(mysql_error());  

}
?>

1 个答案:

答案 0 :(得分:0)

你的插入查询VALUES对我来说很奇怪:
一个开头的单引号从未关闭,
没有使用php变量,你可以初步推广上面的一些行...

也许你的意思是

VALUES ('$submission_id', '$formID', '$IP', '$Placement', ...., '$TotalFeePercent', '$TotalFee')