gpt4 book ai didi

php - 将数据插入数据库不起作用

转载 作者:行者123 更新时间:2023-11-29 01:23:34 26 4
gpt4 key购买 nike

我有点卡住了,我可以手动更新数据库,但是通过 PHP 它不起作用。

数据库字段:

Column     Type          Collation          Attributes   Null  Default  Extra
id int(10) UNSIGNED No auto_increment
addedby varchar(100) latin1_swedish_ci No
location text latin1_swedish_ci No
details text latin1_swedish_ci No
deadline text latin1_swedish_ci No
datefixed int(200) No 0
completed int(11) No 0

Add_jobs.php:

<?php

$pagetitle = "Add Job";

$checkrank = 3;

include ($_SERVER['DOCUMENT_ROOT'].'/header.inc.php');


$helpfaerie = mysql_fetch_array(mysql_query("SELECT * FROM helpfaerie WHERE page = 'reportbug'"));
$helpfaerie2 = mysql_fetch_array(mysql_query("SELECT * FROM members WHERE username = '$username'"));

if ($helpfaerie2[helpfaerie] == 1)
{
echo "<div id=\"helpfaerie\" style=\"overflow: auto; position:fixed; bottom:0; right:0; \"><table width=\"200\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\" style=\"border-top: 1pt solid black;border-bottom: 1pt solid black;border-left: 1pt solid black;border-right: 1pt solid black; background-color:#ffffff;\">
<tr>
<td><center><img src=\"http://images.neopets.com/items/toy_faerie_psellia.gif\" border=\"0\"></center></td>
</tr>
<tr>
<td><p>$helpfaerie[text]</p></td>
</tr>
<tr>
<td style=\"text-align: right;\">[<a href=\"$baseurl/closehelp.pro.php\">x</a>]</td>
</tr>
</table></div>";
}





ECHO <<<END






<center>
<FORM ACTION="add_jobs.pro.php" enctype="multipart/form-data" METHOD=POST>
<table width="366" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><center>Add Job<p></center></td>
</tr>
<tr>
<td width="118">Job Location (If any):</td>
<td width="249"><textarea name="page" cols="20" rows="1" value="" ></textarea></td>
</tr>
<tr>
<td width="118">Details::</td>
<td width="249"><textarea name="wrong" cols="20" rows="10" value="" ></textarea></td>
</tr>

<tr>
<td width="118">Deadline::</td>
<td width="249"><textarea name="line" cols="20" rows="1" value=""></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2"><center><font size="-1"><i>
<input type=submit name=Submit value="Add Jobs">
</i></font></center></td>
</tr>
</table></FORM>
<p>&nbsp;</p></center>









END;




include ($_SERVER['DOCUMENT_ROOT'].'/footer.inc.php');


?>

注意:dblink(链接到我的数据库,工作正常,)插件,主要用于笑脸和语法。

基本上这是一个工作页面,我们用我们需要在网站上完成的工作更新它。

add_jobs.pro.php:

<?php

$pagetitle = "Add Jobs";

$checkrank = 3;

include ($_SERVER['DOCUMENT_ROOT'].'/addon.php');

include ($_SERVER['DOCUMENT_ROOT'].'/dblink.php');

include ($_SERVER['DOCUMENT_ROOT'].'/security/stripusers.php');




$page = $_POST['page'];
$wrong = $_POST['wrong'];
$line = $_POST['line'];



$page = mysql_real_escape_string($page);
$page = stripslashes($page);
$page = stripusers($page);


$wrong = mysql_real_escape_string($wrong);
$wrong = stripslashes($wrong);
$wrong = stripusers($wrong);

$line = mysql_real_escape_string($line);
$line = stripslashes($line);
$line = stripusers($line);

if ((!$page) OR (!$wrong) OR (!$line))

{

die(header("Location: $baseurl/add_jobs.php?error=Please+do+not+leave+any+info+blank."));

}





else

{

mysql_query("INSERT INTO assignments (addedby,location,details,deadline,datefixed) VALUES ('$username','$page','$wrong','$line','$timestamp','0')");

header("Location: add_jobs.php?error=Thank+you.+Your+Job+has+been+submitted.");

}



?>

我刚进入另一个问题。

提交工作后,他们将在此列出

<?php



$pagetitle = "Active Jobs";

$checkrank = 0;


include ($_SERVER['DOCUMENT_ROOT'].'/header.inc.php');


$view=$_GET['view'];

$num = mysql_num_rows(mysql_query("SELECT * FROM `assignments` WHERE 1"));



if ($num <= 0)
{
echo "


<p><center>

There are no active jobs :D";
}



$sort = mysql_query("SELECT * FROM `assignments` WHERE 1");
while($sort2 = mysql_fetch_array($sort))


{





if($sort2[id])


{

$tym = date("H:i",$sort2[date]);
$wcd = date("M j Y",$sort2[date]);

echo("
<center>
<table width=\"607\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\" style=\"border-top: 1pt solid black;border-bottom: 1pt solid black;border-left: 1pt solid black;border-right: 1pt solid black; \">
<tr>
<td width=\"139\" valign=\"top\" style=\"border-bottom: 1pt solid black;border-right: 1pt solid black; background-color:#5eaed4;\">Submitted By:</td>
<td width=\"450\" valign=\"top\" style=\"border-bottom: 1pt solid black;background-color:#f4f4f4;\">$sort2[addedby]</td>
</tr>
<tr>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;border-right: 1pt solid black; background-color:#8cc7e3;\">Date Submitted:</td>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;background-color:#f4f4f4;\"> $wcd @ $tym NST</td>
</tr>
<tr>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;border-right: 1pt solid black; background-color:#5eaed4;\">Job Location:</td>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;background-color:#f4f4f4;\">$sort2[location] [<a href=\"$sort2[location]\">View</a>]</td>
</tr>
<tr>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;border-right: 1pt solid black; background-color:#8cc7e3;\">Job Description:</td>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;background-color:#f4f4f4;\">$sort2[details]</td>
</tr>
<tr>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;border-right: 1pt solid black; background-color:#8cc7e3;\">Deadline:</td>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;background-color:#f4f4f4;\">$sort2[deadline]</td>
</tr>
<tr>
<td valign=\"top\" style=\"border-right: 1pt solid black; background-color:#5eaed4;\">completed?:</td>
<td valign=\"top\" style=\"background-color:#f4f4f4;\">Click When Completed [<a href=\"$baseurl/staff/submitted/completed_job.pro.php?id=$sort2[id]\">x</a>]</td>
</tr>
</table>
<p>&nbsp;</p></center>



"); }







}




echo "<p></center>\n";

echo "</center>\n";


include ($_SERVER['DOCUMENT_ROOT'].'/footer.inc.php');


?>

然后您单击 X,然后将它们归类为已完成,这意味着将它们从页面中删除,但它并没有这样做,它们只是保持在列表中,

但他们也注册了他们的修复,并显示在完成的工作页面上。

completed_jobs.php

    <?php



$pagetitle = "Active Jobs";

$checkrank = 0;


include ($_SERVER['DOCUMENT_ROOT'].'/header.inc.php');


$view=$_GET['view'];

$num = mysql_num_rows(mysql_query("SELECT id FROM assignments WHERE completed =1"));


if ($num <= 0)
{
echo "


<p><center>

There are no complete Jobs at this time.";
}




$sort = mysql_query("SELECT * FROM assignments WHERE completed =1");
while($sort2 = mysql_fetch_array($sort))


{





if($sort2[id])


{

$tym = date("H:i",$sort2[date]);
$wcd = date("M j Y",$sort2[date]);

$ftym = date("H:i",$sort2[datefixed]);
$fwcd = date("M j Y",$sort2[datefixed]);

echo("
<center>
<table width=\"607\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\" style=\"border-top: 1pt solid black;border-bottom: 1pt solid black;border-left: 1pt solid black;border-right: 1pt solid black; \">
<tr>
<td width=\"139\" valign=\"top\" style=\"border-bottom: 1pt solid black;border-right: 1pt solid black; background-color:#5eaed4;\">Submitted By:</td>
<td width=\"450\" valign=\"top\" style=\"border-bottom: 1pt solid black;background-color:#f4f4f4;\">$sort2[addedby]</td>
</tr>
<tr>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;border-right: 1pt solid black; background-color:#8cc7e3;\">Date Submitted:</td>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;background-color:#f4f4f4;\"> $wcd @ $tym NST</td>
</tr>
<tr>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;border-right: 1pt solid black; background-color:#5eaed4;\">Job Location:</td>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;background-color:#f4f4f4;\">$sort2[location] [<a href=\"$sort2[location]\">View</a>]</td>
</tr>
<tr>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;border-right: 1pt solid black; background-color:#8cc7e3;\">Job Description:</td>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;background-color:#f4f4f4;\">$sort2[details]</td>
</tr>
<tr>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;border-right: 1pt solid black; background-color:#8cc7e3;\">Deadline:</td>
<td valign=\"top\" style=\"border-bottom: 1pt solid black;background-color:#f4f4f4;\">$sort2[deadline]</td>
</tr>
<tr>
<td valign=\"top\" style=\"border-right: 1pt solid black; background-color:#5eaed4;\">Completed On:</td>
<td valign=\"top\" style=\"background-color:#f4f4f4;\">$fwcd @ $ftym NST</td>
</tr>
</table>
<p>&nbsp;</p></center>



"); }







}




echo "<p></center>\n";

echo "</center>\n";


include ($_SERVER['DOCUMENT_ROOT'].'/footer.inc.php');


?>

and then completed_job.pro.php


<?php


$pagetitle = "Completed Jobs";

$checkrank = 30;
include ($_SERVER['DOCUMENT_ROOT'].'/addon.php');

include ($_SERVER['DOCUMENT_ROOT'].'/dblink.php');


$id=$_GET['id'];





mysql_query("UPDATE assignments SET completed = '1' WHERE id = '$id'");
mysql_query("UPDATE assignments SET datefixed = '$timestamp' WHERE id = '$id'");



header("Location: completed_jobs.php?error=Job+has+been+updated+to+complete+:)");



?>

最佳答案

不要在调用mysql_real_escape_string()之后调用stripslashes()! 事实上,除非magic_quotes_gpc() 打开(不推荐这样做),根本不要调用 stripslashes()。通过在 mysql_real_escape_string() 之后调用它,您可以撤消该函数提供的转义。

您在插入列列表中指定了 5 列,但在 VALUES() 列表中提供了 6 列。根据您的表结构,我猜测您也打算包含 completed

mysql_query("INSERT INTO assignments (addedby,location,details,deadline,datefixed) VALUES ('$username','$page','$wrong','$line','$timestamp','0')");
//-------------------------------------------------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

我们假设变量 $username$timestamp 已经在包含的文件之一中定义并且已经正确转义。

一些错误检查会揭示查询错误的来源:

$result = mysql_query("INSERT INTO assignments (addedby,location,details,deadline,datefixed) VALUES ('$username','$page','$wrong','$line','$timestamp','0')");
if (!$result) {
echo mysql_error();
}

关于php - 将数据插入数据库不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10075443/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com