gpt4 book ai didi

PHP SCRIPT - 执行时不更新数据库

转载 作者:行者123 更新时间:2023-11-29 13:19:20 25 4
gpt4 key购买 nike

我已经玩了好几个小时了,但没有效果,我一直在构建一个脚本,该脚本允许我通过在表格中编辑来编辑管理员中网页上的信息。我使用了一些教程等,但现在它只是不想更新数据库。

我有三个要素:

第一个:列表 - 工作正常

require_once("models/config.php");
if (!securePage($_SERVER['PHP_SELF'])){die();}
require_once("models/header.php");


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


$tbl_name="DealOne";
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>


<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from mysql </strong> </td>
</tr>

<tr>
<td align="center"><strong>Desc</strong></td>
<td align="center"><strong>Dest</strong></td>
<td align="center"><strong>RRP</strong></td>
<td align="center"><strong>Price Entry</strong></td>
<td align="center"><strong>Entries Avail</strong></td>
<td align="center"><strong>Update</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td><? echo $rows['holdesc1']; ?></td>
<td><? echo $rows['holdest1']; ?></td>
<td><? echo $rows['rrp1']; ?></td>
<td><? echo $rows['cpe1']; ?></td>
<td><? echo $rows['ea1']; ?></td>

<td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td>
</tr>

<?php
}
?>

</table>
</td>
</tr>
</table>

<?php
mysql_close();
?>

第二个:表单更新数据的地方

require_once("models/config.php");
if (!securePage($_SERVER['PHP_SELF'])){die();}
require_once("models/header.php");


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


$tbl_name="DealOne";


// get value of id that sent from address bar
$id=$_GET['id'];

// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>

<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>Desc</strong></td>
<td align="center"><strong>Dest</strong></td>
<td align="center"><strong>RRP</strong></td>
<td align="center"><strong>Price Entry</strong></td>
<td align="center"><strong>Entries Avail</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center"><input name="desc" type="text" id="holdesc1" value="<? echo $rows['holdesc1']; ?>" size="35">
</td>
<td align="center">
<input name="Destination" type="text" id="holdest1" value="<? echo $rows['holdest1']; ?>" size="35">
</td>
<td>
<input name="RRP" type="text" id="rrp1" value="<? echo $rows['rrp1']; ?>" size="8">
</td>
<td align="center">
<input name="Price per Entry" type="text" id="cpe1" value="<? echo $rows['cpe1']; ?>">
</td>
<td align="center">
<input name="Entries Available" type="text" id="ea1" value="<? echo $rows['ea1']; ?>" size="8">
</td>


</tr>
<tr>
<td>&nbsp;</td>
<td>
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
</td>
<td align="center">
<input type="submit" name="Submit" value="Submit">
</td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>

<?php
// close connection
mysql_close();
?>

最后是第三个,我相信它会更新数据库,但它没有:

require_once("models/config.php");
if (!securePage($_SERVER['PHP_SELF'])){die();}
require_once("models/header.php");


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


$tbl_name="DealOne";

// update data in mysql database
$sql="UPDATE $tbl_name SET holdesc1='$holdesc1', holdest1='$holdest1', rrp1='$rrp1', cpe1='$cpe1', ea1='$ea1' WHERE id='$id'";
$result=mysql_query($sql);

// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='view_posts.php'>View result</a>";
}

else {
echo "ERROR";
}

?>

关于如何让它发挥作用有什么想法或建议吗?提前致谢!!

最佳答案

您的 $tbl_name 未加引号。

你有

$sql="UPDATE $tbl_name SET holdesc1='$holdesc1', holdest1='$holdest1', rrp1='$rrp1', cpe1='$cpe1', ea1='$ea1' WHERE id='$id'";

我认为应该是:

$sql="UPDATE '$tbl_name' SET holdesc1='$holdesc1', holdest1='$holdest1', rrp1='$rrp1', cpe1='$cpe1', ea1='$ea1' WHERE id='$id'";

关于PHP SCRIPT - 执行时不更新数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21057373/

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