首页 > 解决方案 > MySQLi插入查询正在执行但未进入数据库

问题描述

在过去的两天里,我一直在尝试在我的数据库中进行插入操作,但这不仅可以正常工作,而且我没有收到任何错误。最有趣且可能最令人沮丧的是,这在我的笔记本电脑 Wamp 服务器上完美运行,但在我上传到互联网时却无法运行。

<?php

error_reporting;
$mysqli = new mysqli("localhost", "dbuser", "dbpass", "dbname");
if($mysqli->connect_errno > 0)
{
  echo"Failed to connect to MySQL ".$mysqli->connect_error."";
  exit();
}


if($_POST["submit"])
{
$errors=array();
if(isset($_FILES["file"]))
{
$funame=preg_replace('/[^a-zA-Z0-9-_\.]/i',' ',cleanvalues2($_FILES["file"]["name"]));
$dir="../attachment/";
if($funame)
{$frand=rand(0000, 9999);
$funame=$frand.$funame;
$valid_exts=array("jpeg","png","jpg");
$ext=end(explode(".",strtolower($funame)));
$size=$_FILES["file"]["size"];
$type=$_FILES["file"]["type"];
if($size<10)
{
$errors[]="File must be larger than 10Bytes!";
}
if($size>50000000)
{
$errors[]="size too larg!";
}
if(!in_array($ext,$valid_exts))
{
$errors[]="invalid file extension!";}

if(file_exists("$dir.$funame"))
{
$errors[]="File exists please rename this file !";
}
}
}

$name=$_POST["name"];
$email=$_POST["email"];
$clientphonenumber=$_POST["clientphonenumber"];
$parcel=$_POST["parcel"];
$parceldetails=$_POST["parceldetails"];
$phase1=$_POST["phase1"];
$phase1con=$_POST["phase1con"];
$phase2con=$_POST["phase2con"];
$phase2=$_POST["phase2"];
$phase2date=$_POST["phase2date"];
$phase3=$_POST["phase3"];
$phase3con=$_POST["phase3con"];
$phase3date=$_POST["phase3date"];
$save=cleanvalues($_POST["save"]);
//clean
if(empty($parcel)|| strlen($parcel)<2)
{
$errors[]="Package should have a title/name (Will be useful for your tracking)";
}
if(count($errors)==0)
{
$date=time();
$dir=$dir.$funame;
$fin=move_uploaded_file($_FILES["file"]["tmp_name"], $dir);
$query="INSERT INTO track SET `email`=?, `name`=?, `clientphonenumber`=?, `parcel`=?, `parceldetails`=?, `phase1`=?, `phase1con`=?, `phase2`=?, `phase2con`=?, `phase3`=?, `phase3con`=?, `date`=?, `lastdate`=?, `file`=?";
$stmt=$mysqli->prepare($query);
if(!$stmt)
{
$msg="An error occured while uploading package, please contact Developer";
}
else
{
$msg='Package was uploaded Successfully';
$stmt->bind_param('ssssssssssssss', $email,$name,$clientphonenumber,$parcel,$parceldetails,$phase1,$phase1con,$phase2,$phase2con,$phase3,$phase3con,$date,$date,$funame);
$stmt->execute();
$stmt->close();
$last=$mysqli->insert_id;
$iv="SELECT * FROM track WHERE `id`='$last'";
$ivquer=$mysqli->query($iv);
$tt=$ivquer->fetch_array();
$tid=cleanvalues2($tt["id"]);
$tol=time();
$dyear=gmdate('Y', $tol);
$dday=gmdate('d', $tol);
$sentcustom=cleanvalues2($tt["sentcustom"]+1);
$ivquery="UPDATE track SET `packageid`=?, `sentcustom`=? WHERE `id`=?";
$ivstmt=$mysqli->prepare($ivquery);
$ivcode="JIROL-TRACK$dyear$tid$dday";
$ivstmt->bind_param('sss', $ivcode,$sentcustom,$last);
$ivstmt->execute();
$ivstmt->close();
$to="book@domain.com, info@domain.com, domain@yahoo.com";
$subject="Newly Uploaded Package";
$messagel="Hello,
On the website, a package has just been uploaded and its tracking code is $ivcode, You/or your team can forward this to the appropiate quarters and also save/bookmark email for future references
Few Details:
Package: $parcel
Details: $parceldetails
Client Phone Number: $clientphonenumber
For more details on this package or client, Please visit the Website and Click on the appropiate links.

Thanks";
$headers='From: New Uploaded Package Alert - noreply@domain.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

$admin=mail($to, $subject, $messagel, $headers);

if(!empty($email))
{
$tou= "$email";
$subjectu="Order has been Fulfilled - Jiro Logistics";
$messageu="Hello $clientname,
We thank you for using our service

Your order [$parcel] has been fulfilled and you can now track and check its status.
Please note that we will likely call you or email you when your package has been fully delivered (or for whatever reason that arises) so we ask that you check your email constantly and therefore remain open for further messages.
Thanks";
$headersu= 'From: Fulfilled Order info@domain.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

$participant=mail($tou, $subjectu, $messageu, $headersu);
}
}
if($save=="Come")
{
header("location: $config->url/pages/uploadpackage.php?msg=$msg");
?>
<script>
location.replace("<?php echo"$config->url";?>/pages/uploadpackage.php?msg=<?php echo"$msg";?>")
</script>
<?php
die;
}
elseif($save=="Gopackages")
{header("location: $config->url/pages/showallpackages.php?msg=$msg");
?>
<script>
location.replace("<?php echo"$config->url";?>/pages/showallpackages.php?msg=<?php echo"$msg";?>")
</script>
<?php
die();
}
elseif($save=="Gohome")
{header("location: $config->url");
?>
<script>
location.replace("<?php echo"$config->url";?>")
</script>
<?php
die;
}
elseif($save=="Gocomplete")
{
header("location: $config->url/pages/showallcompleted.php?msg=$msg");
?>
<script>
location.replace("<?php echo"$config->url";?>/pages/showallcompleted.php?msg=<?php echo"$msg";?>")
</script>
<?php
die;
}
}
else
{
foreach($errors as $error)
{
?>
<script>
location.replace('#error')
</script>
<?php
$string.="&bull; $error<br/>";
}
}
}
if($string!==" "){
echo"<a id='error'></a><div class='w3-container w3-red' align='center' style='padding:10px'>$string</div>";
}
echo"";
?>
<form method="post" autocomplete="on" action="#" enctype="multipart/form-data">
<?php 
echo"
<div class='w3-container'>
<div class='w3-row'><div class='w3-third'>Name <b>(recommended)</b></div>
<div class='w3-twothird'><input type='text' name='name' class='w3-input w3-border w3-round' value='$name' placeholder='E.g: Cute Ejiro'></div></div>
<br>
<div class='w3-row'><div class='w3-third'>Email <b>(recommended)</b></div>
<div class='w3-twothird'><input type='email' name='email' class='w3-input w3-border w3-round' value='$email' placeholder='E.g: jiro@domain.com'></div></div>
<br>
<div class='w3-row'><div class='w3-third'>Client Phone Number <b>(recommended)</b></div>
<div class='w3-twothird'><input type='number' name='clientphonenumber' class='w3-input w3-border w3-round' value='$clientphonenumber' placeholder='E.g: 08130444444'></div></div>
<br>
<div class='w3-row'><div class='w3-third'>Parcel <font color='red'>*</font></div>
<div class='w3-twothird'><input type='text' name='parcel' class='w3-input w3-border w3-round' value='$parcel' placeholder='E.g: Nokia 3310'></div></div>
<br>
<div class='w3-row'><div class='w3-third'>Parcel Details <font color='red'>*</font></div>
<div class='w3-twothird'><textarea rows='3' cols='3' name='parceldetails' class='w3-input w3-border w3-round' placeholder='Details about the package...'>$parceldetails</textarea>
</div></div>
<br>
<div class='w3-center'><b>Tick the box, if, at the time you are uploading this package, the package has gotten to the phase you are writing on</b></div>
<div class='w3-row'><div class='w3-third'>Phase1</div>
<div class='w3-twothird'> <input type='checkbox' name='phase1con' value='1' style='display:inline-block'> <input type='text' name='phase1' class='w3-input w3-border w3-round' value='$phase1' placeholder='E.g: Chinese Port' style='display:inline-block;width:250px'></div></div>
<br>
<div class='w3-row'><div class='w3-third'>Phase2</div>
<div class='w3-twothird'><input type='checkbox' style='display:inline-block' name='phase2con' value='1'>
<input type='text' style='display:inline-block;width:250px' name='phase2' class='w3-input w3-border w3-round' value='$phase2' placeholder='E.g: Ken Atlantic Airport'></div></div>
<br>
<div class='w3-row'><div class='w3-third'>Phase3</div>
<div class='w3-twothird'><input type='checkbox' style='display:inline-block' name='phase3con' value='1'> <input type='text' name='phase3' class='w3-input w3-border w3-round' style='display:inline-block;width:250px' value='$phase3'></div></div>
<br>
<div class='w3-row'><div class='w3-third'>
Attach Photo of product</div><div class='w3-twothird'><font color='black'><strong>Allowed Extension: .png, .jpg, .jpeg</strong></font><br>
<input type='file' name='file' size='9'></div></div><br>";

echo"<center>
   <table border='0' cellpadding='5' cellspacing='0' style='border:none'>
    <tr style='background:none;border:none'>
        <td style='border:none' valign='middle' nowrap='nowrap'>
<i class='fa fa-check-square'></i> <b>Save and then</b>
        </td>
        <td style='border:none' valign='middle' nowrap='nowrap'>
<select name='save' style='width:220px'>
<option value='Gohome'>Go to Homepage</option>
<option value='Gopackages'>Go to page that shows all packages</option>
<option value='Come' selected='selected'>Come back to this page</option>
<option value='Gocomplete'>Go to page that shows all completed packages</option>
</select>        </td>
    </tr>
</table>
</center>";
echo"<input type='submit' name='submit' class='w3-btn w3-osblue' value='Upload'></div></form>
<br/>";
?>

“跟踪”表比这更长,但我认为这不是原因。整个数据库是 MyISAM

我尝试了几件事: - 添加了 $mysqli->commit; 并且仍然不起作用 - 在我的 PHPMYADMIN 中运行查询(并且它起作用了 - 进入数据库) - 将代码更改为 Procedural 并且仍然不起作用。

我在 Stack Overflow 上看到过类似的问题,我已经尝试了所有可能的方法。请检查并查看是否有任何错误或错误代码。PS:此代码在我的笔记本电脑 wamp 服务器上完美运行并插入我的数据库(没有互联网),但当我在互联网上上传到我的网站时不起作用。

我做错了什么,我该纠正什么?

标签: phpmysqlinsert

解决方案


推荐阅读