Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.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 html_Php_Html_Mysql_Database - Fatal编程技术网

编辑数据库PHP html

编辑数据库PHP html,php,html,mysql,database,Php,Html,Mysql,Database,我有一个数据库,其中有一个名为Stock的表,到目前为止,我可以打开我的view.php查看该表,并使用insert.php文件向该表添加行 我还添加了Edit和Delete,但是,您可以在下面看到的Edit.php文件不允许我编辑表中的任何数据。我似乎想不出问题出在哪里。如果能提供一些帮助,我将不胜感激 <?php function valid($id, $ProductName, $Quantity,$Price, $error) { ?> <!DOCTYPE HTML

我有一个数据库,其中有一个名为Stock的表,到目前为止,我可以打开我的view.php查看该表,并使用insert.php文件向该表添加行

我还添加了Edit和Delete,但是,您可以在下面看到的Edit.php文件不允许我编辑表中的任何数据。我似乎想不出问题出在哪里。如果能提供一些帮助,我将不胜感激

<?php
function valid($id, $ProductName, $Quantity,$Price, $error)
{
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<title>Edit Records</title>
</head>

<body>
<?php

 if ($error != '')
 {
  echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
 }
?>

<form action="" method="post">


<table border="1">
<tr>
<td colspan="2"><b><font color='Red'>Edit Records </font></b></td>
</tr>

<tr>
<td width="179"><b><font color='#663300'>Product Name<em>*</em></font></b></td>
<td><label>
<input type="text" name="ProductName" value="<?php echo $ProductName; ?>" />
</label></td>
</tr>

<tr>
<td width="179"><b><font color='#663300'>Quantity<em>*</em></font></b></td>
<td><label>
<input type="text" name="Quantity" value="<?php echo $Quantity; ?>" />
</label></td>
</tr>

<tr>
<td width="179"><b><font color='#663300'>City<em>*</em></font></b></td>
<td><label>
<input type="text" name="Price" value="<?php echo $Price; ?>" />
</label></td>
</tr>

<tr align="Right">
<td colspan="2"><label>
<input type="submit" name="submit" value="Edit Records">
</label></td>
</tr>
</table>
</form>
</body>

</html>
 <?php
 }

 include('config.php');

 if (isset($_POST['submit']))
{

$ProductName = mysql_real_escape_string(htmlspecialchars($_POST['ProductName']));
$Quantity = mysql_real_escape_string(htmlspecialchars($_POST['Quantity']));
$Price = mysql_real_escape_string(htmlspecialchars($_POST['Price']));


if ($ProductName == '' || $Quantity == '' || $Price == '')
{

$error = 'ERROR: Please fill in all required fields!';


valid($id, $ProductName, $Quantity,$Price, $error);
}
else
{

mysql_query("UPDATE Stock SET ProductName='$ProductName', Quantity='$Quantity' ,Price='$Price' ")
or die(mysql_error());

header("Location: view.php");
}
}
else 
{

echo 'Error!';
}


if($row) 
{

$ProductName = $row['ProductName'];
$Quantity = $row['Quantity'];
$Price = $row['Price'];

valid($ProductName, $Quantity,$Price,);
}
else
{
echo "No results!";
}
}
else

{
echo 'Error!';
}
}
?>

编辑记录
编辑记录
产品名称*

这行有错误

    valid($ProductName, $Quantity,$Price,);
应该是

   valid($ProductName, $Quantity,$Price,$error);
else
station中也有一个错误,您正在使用另外两个

应该是

 if( .....

 else if ( ....

 else { ...
编辑:

试试这个

    <?php
  function valid($id, $ProductName, $Quantity,$Price, $error)
  {
  ?>

  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <html>

 <head>
 <title>Edit Records</title>
 </head>

 <body>
<?php

 if ($error != '')
 {
  echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
 }
?>

<form action="" method="post">


<table border="1">
<tr>
<td colspan="2"><b><font color='Red'>Edit Records </font></b></td>
</tr>

<tr>
<td width="179"><b><font color='#663300'>Product Name<em>*</em></font></b></td>
<td><label>
<input type="text" name="ProductName" value="<?php echo $ProductName; ?>" />
</label></td>
</tr>

<tr>
<td width="179"><b><font color='#663300'>Quantity<em>*</em></font></b></td>
<td><label>
<input type="text" name="Quantity" value="<?php echo $Quantity; ?>" />
</label></td>
</tr>

<tr>
<td width="179"><b><font color='#663300'>City<em>*</em></font></b></td>
<td><label>
<input type="text" name="Price" value="<?php echo $Price; ?>" />
</label></td>
</tr>

<tr align="Right">
<td colspan="2"><label>
<input type="submit" name="submit" value="Edit Records">
</label></td>
 </tr>
</table>
</form>
</body>

</html>
 <?php
}

 include('config.php');

 if (isset($_POST['submit']))
{

$ProductName = mysql_real_escape_string(htmlspecialchars($_POST['ProductName']));
$Quantity = mysql_real_escape_string(htmlspecialchars($_POST['Quantity']));
$Price = mysql_real_escape_string(htmlspecialchars($_POST['Price']));


 if ($ProductName == '' || $Quantity == '' || $Price == '')
 {

 $error = 'ERROR: Please fill in all required fields!';


 valid($id, $ProductName, $Quantity,$Price, $error);
 }
 else
 {

 mysql_query("UPDATE Stock SET ProductName='$ProductName', Quantity='$Quantity'  ,Price='$Price' ")
 or die(mysql_error());

header("Location: view.php");
}
}
else 
{

echo 'Error!';
 }

 $query = mysql_query(" select * from Stock");
 $row = mysql_fetch_array($query) ;  


 if ( mysql_num_rows($query) == 0)
 {
 echo "No results!";
 }

 else if (mysql_num_rows($query) == 1)
  { 

 $ProductName = $row['ProductName'];
  $Quantity = $row['Quantity'];
  $Price = $row['Price'];
 valid($ProductName, $Quantity,$Price,$error);
  echo "echo what you like here".
 }
 else
 {
 echo 'Error!';
 }

 ?>

编辑记录
编辑记录
产品名称*

您使用mysql_query有什么原因吗?如果可能的话,我强烈建议您转换为mysqli或PDO,因为mysqli函数很快就会被弃用。有关
UPDATE
命令中的two.no
WHERE
语句的更多信息,请参阅第108行的/home/k1012904/www/EditDatabase/edit.php中的Parse error:syntax error,意外的T_ECHO。。。。这是我在观看时看到的。我的代码的这一部分如下所示:if($row){$ProductName=$row['ProductName'];$Quantity=$row['Quantity'];$Price=$row['Price'];valid($ProductName,$Quantity,$Price,$error);}如果{echo“没有结果!”;}}如果}其他{echo“错误!”;}请尝试我编辑过的答案。