Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MYSQLI与INSERT的关系不太好 请原谅,如果它不完全达到标准,但我刚刚得到了MySQL的挂起,AM切换到mySQL(过程中我发现它更容易,因为我还没有学会面向对象,我是新的)。 我的问题是,我在一个小网站上有一个简单的“发票”页面,它与MYSQL完美配合。当我切换到MYSQLI(我肯定我遗漏了一些明显的东西)时,我可以回显所有变量,检查数据库连接是否正确,但它不会在数据库中插入任何内容。 这就是所讨论的函数,它是在提交“填写发票”表单后调用的,同样,所有$\u POST变量都可以在函数中正确地回显 function createinvoice($billto,$cust,$addr,$desc,$desccost,$labcost,$comment){ $taxrate=".13"; $kaboom=str_replace(array("\r\n","\r","\n"),"<br />",$desccost); //keep original desccost for database $kaboom=mysqli_real_escape_string(nl2br($kaboom)); $kaboom=nl2br($kaboom); $lines=explode("<br />",$kaboom); $matcost=0; for($i=0;$i < count($lines);$i++) { $matcost=$matcost+$lines[$i]; } $fullcost=$matcost+$labcost; $taxdue = $fullcost*$taxrate; $totaldue=$fullcost+$taxdue; $desc=mysqli_real_escape_string($desc); mysqli_query($con,"INSERT INTO invoice(customerID,customerName,customerAddr,description,desccost,material,labour,taxdue,totaldue,comment) VALUES('$billto','$cust','$addr','$desc','$desccost','$matcost','$labcost','$taxdue','$totaldue','$comment')"); mysqli_free_result($result); mysqli_close($con); }_Mysql - Fatal编程技术网

MYSQLI与INSERT的关系不太好 请原谅,如果它不完全达到标准,但我刚刚得到了MySQL的挂起,AM切换到mySQL(过程中我发现它更容易,因为我还没有学会面向对象,我是新的)。 我的问题是,我在一个小网站上有一个简单的“发票”页面,它与MYSQL完美配合。当我切换到MYSQLI(我肯定我遗漏了一些明显的东西)时,我可以回显所有变量,检查数据库连接是否正确,但它不会在数据库中插入任何内容。 这就是所讨论的函数,它是在提交“填写发票”表单后调用的,同样,所有$\u POST变量都可以在函数中正确地回显 function createinvoice($billto,$cust,$addr,$desc,$desccost,$labcost,$comment){ $taxrate=".13"; $kaboom=str_replace(array("\r\n","\r","\n"),"<br />",$desccost); //keep original desccost for database $kaboom=mysqli_real_escape_string(nl2br($kaboom)); $kaboom=nl2br($kaboom); $lines=explode("<br />",$kaboom); $matcost=0; for($i=0;$i < count($lines);$i++) { $matcost=$matcost+$lines[$i]; } $fullcost=$matcost+$labcost; $taxdue = $fullcost*$taxrate; $totaldue=$fullcost+$taxdue; $desc=mysqli_real_escape_string($desc); mysqli_query($con,"INSERT INTO invoice(customerID,customerName,customerAddr,description,desccost,material,labour,taxdue,totaldue,comment) VALUES('$billto','$cust','$addr','$desc','$desccost','$matcost','$labcost','$taxdue','$totaldue','$comment')"); mysqli_free_result($result); mysqli_close($con); }

MYSQLI与INSERT的关系不太好 请原谅,如果它不完全达到标准,但我刚刚得到了MySQL的挂起,AM切换到mySQL(过程中我发现它更容易,因为我还没有学会面向对象,我是新的)。 我的问题是,我在一个小网站上有一个简单的“发票”页面,它与MYSQL完美配合。当我切换到MYSQLI(我肯定我遗漏了一些明显的东西)时,我可以回显所有变量,检查数据库连接是否正确,但它不会在数据库中插入任何内容。 这就是所讨论的函数,它是在提交“填写发票”表单后调用的,同样,所有$\u POST变量都可以在函数中正确地回显 function createinvoice($billto,$cust,$addr,$desc,$desccost,$labcost,$comment){ $taxrate=".13"; $kaboom=str_replace(array("\r\n","\r","\n"),"<br />",$desccost); //keep original desccost for database $kaboom=mysqli_real_escape_string(nl2br($kaboom)); $kaboom=nl2br($kaboom); $lines=explode("<br />",$kaboom); $matcost=0; for($i=0;$i < count($lines);$i++) { $matcost=$matcost+$lines[$i]; } $fullcost=$matcost+$labcost; $taxdue = $fullcost*$taxrate; $totaldue=$fullcost+$taxdue; $desc=mysqli_real_escape_string($desc); mysqli_query($con,"INSERT INTO invoice(customerID,customerName,customerAddr,description,desccost,material,labour,taxdue,totaldue,comment) VALUES('$billto','$cust','$addr','$desc','$desccost','$matcost','$labcost','$taxdue','$totaldue','$comment')"); mysqli_free_result($result); mysqli_close($con); },mysql,Mysql,每次加载页面时,我都会收到一条消息“DB file connected”,显示它读取了dbinvoice.php文件,而connect没有收到错误消息。我已使用phpinfo()验证mysqli是否在我的计算机上(webmatrix测试)。您应该验证查询是否成功。至少,检查mysqli\u query是否返回TRUE或FALSE。如果FALSE,您将通过获取有关错误的信息。如果我添加If(!mysqli…){echo“Some error:”.mysqli_error($con);}我将从mys

每次加载页面时,我都会收到一条消息“DB file connected”,显示它读取了dbinvoice.php文件,而connect没有收到错误消息。我已使用phpinfo()验证mysqli是否在我的计算机上(webmatrix测试)。

您应该验证查询是否成功。至少,检查
mysqli\u query
是否返回
TRUE
FALSE
。如果
FALSE
,您将通过获取有关错误的信息。如果我添加If(!mysqli…){echo“Some error:”.mysqli_error($con);}我将从mysqli_错误中获取一些错误的输出,但没有任何结果。我真的开始怀疑我是否真的没有DB连接,即使一切都说我有:(旁注:
$kaboom
怎么了?你做了看起来像是手动版本的
nl2br
,然后做了两次
nl2br
实际的函数,然后使用结果的中断标记进行
分解
。你看起来也在逃逸
$kaboom
,但只在数学运算中使用它进行分解,而
$desccost
本身被插入到查询中,但没有转义。您所说的“一切都说明您在做什么”是什么意思?能否显示建立连接的代码,并验证
mysqli_connect
的结果是否也是
TRUE
?mysqli不会自动获取它作为mysql_query()找到的第一个打开的连接可以。您必须在变量
$con
中传递资源,但该变量不在函数的作用域内。您必须将其传递给函数,或使用
全局
,但最好是传递它。
if(include("/../dbinvoice.php")){echo "DB file connected";}
$con = mysqli_connect($dbhostname, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno($con)){echo "No MYSQL connection: ".mysqli_connect_error();exit();}