Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.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
PHP脚本-执行时不更新数据库_Php_Mysql_Sql - Fatal编程技术网

PHP脚本-执行时不更新数据库

PHP脚本-执行时不更新数据库,php,mysql,sql,Php,Mysql,Sql,我已经玩了好几个小时了,但没有用,我一直在构建一个脚本,允许我在管理中编辑网页上的信息,通过在表格中编辑它。我使用了一些教程等,但现在它只是不想更新数据库 我有三个要素: 第一个:列表表-工作正常 require_once("models/config.php"); if (!securePage($_SERVER['PHP_SELF'])){die();} require_once("models/header.php"); // Connects to your Database

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

我有三个要素:

第一个:列表表-工作正常

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”);
如果(!securePage($_SERVER['PHP_SELF']){die();}
需要_一次(“models/header.php”);
//连接到您的数据库
mysql_connect(“localhost”、“cl52 abcdef”、“abcdef”)或die(mysql_error());
mysql_选择_db(“cl52 abcdef”)或die(mysql_error());
$tbl_name=“DealOne”;
$sql=“从$tbl\U名称中选择*”;
$result=mysql\u查询($sql);
?>
列出mysql中的数据
Desc
Dest
RRP
价格输入
条目可用
更新
第二个:表单用于更新数据的位置

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”);
如果(!securePage($_SERVER['PHP_SELF']){die();}
需要_一次(“models/header.php”);
//连接到您的数据库
mysql_connect(“localhost”、“cl52 abcdef”、“abcdef”)或die(mysql_error());
mysql_选择_db(“cl52 abcdef”)或die(mysql_error());
$tbl_name=“DealOne”;
//获取从地址栏发送的id的值
$id=$_GET['id'];
//从数据库检索数据
$sql=“从$tbl\U名称中选择*,其中id='$id';
$result=mysql\u查询($sql);
$rows=mysql\u fetch\u数组($result);
?>
在mysql中更新数据
Desc
Dest
RRP
价格输入
条目可用

这里的问题是,您正在呈现一个表单来更新多个条目,所有条目都使用相同的
id
HTML属性共享属性。更新脚本无法区分具有相同
id
的DOM元素,因此,即使通过将
id
作为隐藏属性传递来标识每个条目,也无法正确更新记录

一种可能的解决方案是将条目的唯一ID作为该条目的每个属性的一部分传递:

<input name="Price per Entry" type="text" id="cpe1_<? echo $rows['id']; ?>" value="<? echo $rows['cpe1']; ?>">

您的$tbl\u名称未被引用

你有

$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'";

echo$sql;在调用mysql\u查询并验证字符串是否包含您认为应该包含的值之前,它当然不起作用。您没有提交表单。$\u POST?$id?你从哪里得到的?它显示成功,但数据库中的数据尚未更新。我再看一遍谢谢你的回答,我有一个剧本,从不同的角度攻击它!助教
$sql="UPDATE '$tbl_name' SET holdesc1='$holdesc1', holdest1='$holdest1', rrp1='$rrp1', cpe1='$cpe1', ea1='$ea1' WHERE id='$id'";