PHP的更新查询失败my_fetch_array [英] php UPDATE QUERY fail my_fetch_array

查看:106
本文介绍了PHP的更新查询失败my_fetch_array的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在表单中更新我的供应商信息。

下面是我的我的code为editsupplier形式

 < PHP
$供应商ID = $ _GET ['供应商ID'] = $行['供应商ID'];
//连接并选择数据库
mysql_connect(localhost的根,);
mysql_select_db(supplierdetails);
//运行查询
$ RESULT1 =的mysql_query(SELECT * FROM供应商WHERE供应商id = $供应商ID);
而($行= mysql_fetch_array($ RESULT1)){
$供应商ID = $ _GET ['供应商ID'] = $行['供应商ID'];
$ SupplierName = $行['SupplierName'];
$货币= $行['货币'];
$位置= $行['位置'];
$ ContactNumber = $行['ContactNumber'];
$电子邮件= $行[电子邮件];
  }
?>
!< D​​OCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0 Strict标准// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1- strict.dtd>
< HTML的xmlns =htt​​p://www.w3.org/1999/xhtmlXML:LANG =ENLANG =ENGT&;
< HEAD>
< META HTTP-EQUIV =内容类型内容=text / html的;字符集= UTF-8/>
 < META NAME =说明内容=/>
 < META NAME =关键词内容=/>
< META NAME =作者内容=/>
 <链接rel =stylesheet属性类型=文/ CSS的href =style.css文件媒体=屏幕/>
 <标题>哈里森·斯平克斯< /标题>
  < /头>
   <身体GT;
   < D​​IV ID =包装>
 < PHP的包括:(包括/ header.php文件'); ?>
 < PHP的包括:(包括/ nav.php'); ?>
 < D​​IV ID =内容>
 < H3><中心>编辑供应商信息< /中心及GT;< / H3 GT&;
< P>请输入以下所有细节编辑供应商< / P>
 < / DIV>
< D​​IV>
 < BR>
 < / BR>
<形式的行动=Edit_Supp.php方法=后>
 < BR>
 < / BR>
 <输入类型=隐藏的名字=供应商IDVALUE =< PHP的echo $供应商ID;>中/> 供应商名称:<输入类型=文本名称=SupplierNameVALUE =?< PHP的echo $ SupplierName;>? />
 < BR>
 < / BR>
 货币:<输入类型=文本名称=货币值=< PHP的echo $货币;>有 />
 < BR>
 < / BR>
  位置:其中,INPUT TYPE =文本名称=位置值=< PHP的echo $位置;>有 />
  < BR>
  < / BR>
 联系电话:LT;输入类型=文本名称=ContactNumberVALUE =?< PHP的echo $ ContactNumber;>中/>
< BR>
< / BR>
 电子邮件:;?< PHP的echo $电子邮件;>中和LT输入类型=文本名称=电子邮件值= />
 < BR>
 < / BR>
 <输入类型=提交值=编辑供应商信息/> < /表及GT;
 < / DIV>
< /身体GT;
 < / HTML>

错误是:

 注意:未定义的变量:行E:\\ XAMPP \\ htdocs中\\ EditSupForm.php第2行
警告:mysql_fetch_array()预计参数1是资源,布尔在E中给出:\\ XAMPP \\ htdocs中\\ EditSupForm.php第8行

这是在形式背后的code:

 < PHP
 $ CON = mysql_connect(localhost的根,);
    mysql_select_db(supplierdetails);
      如果(!$ CON)
          {
        死亡(无法连接:'mysql_error());
         }
  //运行查询
    $供应商ID = $ _ POST ['供应商ID'] = $行[供应商ID];
$ RESULT1 =的mysql_query(SELECT * FROM供应商WHERE供应商id =$供应商ID。')或死亡(mysql_error());
$行= mysql_fetch_array($ RESULT1);
$供应商ID = $ _ POST ['供应商ID'] = $行[供应商ID];
$ SupplierName = $ _ POST ['SupplierName'];
$货币= $ _ POST ['货币'];
$位置= $ _ POST ['位置'];
$ ContactNumber = $ _ POST ['ContactNumber'];
$电子邮件= $ _ POST [电子邮件];
$供应商ID = $行['供应商ID'];
    $查询=更新供应商SET供应商id ='。$供应商ID。',SupplierName ='。$ SupplierName。',货币='。$货币。',位置='。$位置。' ,ContactNumber ='。$ ContactNumber',电子邮件='。$电子邮件'WHERE供应商id ='的$ id。';
$ RESULT1 =的mysql_query($查询);
//检查查询是否成功与否
 如果($ RESULT1)
 {
 回声供应商更新了;
 标题(位置:Supplier.php);
 }
其他
{
 死(查询失败);
  }
 ?>


解决方案

在这两个你使用 $行[供应商ID]你的code的; 前执行MySQL查询,`$行[供应商ID];这就是为什么你越来越错误。

I am trying to update my supplier information within a form

Here is my my code for the editsupplier form

<?php   
$SupplierID = $_GET['SupplierID'] = $row['SupplierID'];
//Connect and select a database
mysql_connect ("localhost", "root", "");
mysql_select_db("supplierdetails");
//Run query
$result1 = mysql_query("SELECT * FROM suppliers WHERE SupplierID=$SupplierID"); 
while($row = mysql_fetch_array($result1)){
$SupplierID = $_GET['SupplierID'] = $row['SupplierID']; 
$SupplierName = $row['SupplierName'];
$Currency = $row['Currency'];
$Location = $row['Location'];
$ContactNumber = $row['ContactNumber'];
$Email = $row['Email'];
  }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-    strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
 <meta name="description" content="" />
 <meta name="keywords" content="" />
<meta name="author" content="" />
 <link rel="stylesheet" type="text/css" href="style.css" media="screen" />
 <title>Harrison Spinks</title>
  </head>
   <body>
   <div id="wrapper">
 <?php include('includes/header.php'); ?> 
 <?php include('includes/nav.php'); ?>
 <div id="content">
 <h3><center>Edit Supplier Information</center></h3>
<p>Please enter all the following details to edit a supplier</p>
 </div>
<div>
 <br>
 </br>
<form action="Edit_Supp.php" method="post">
 <br>
 </br>
 <input type="hidden" name="SupplierID" value="<?php echo $SupplierID;?>"/> 

 Supplier Name: <input type="text" name="SupplierName" value="<?php echo $SupplierName ;?>" />
 <br>
 </br>
 Currency: <input type="text" name="Currency" value="<?php echo $Currency ;?>" />
 <br>
 </br>
  Location: <input type="text" name="Location" value="<?php echo $Location ;?>" />
  <br>
  </br>
 Contact Number:<input type="text" name="ContactNumber" value="<?php echo $ContactNumber ;?>" /> 
<br>
</br>
 Email:<input type="text" name="Email" value="<?php echo $Email ;?>" />
 <br>
 </br>
 <input type="submit" value= "Edit Supplier Information"/>

 </form>
 </div>
</body>
 </html> 

Errors are:

Notice: Undefined variable: row in E:\xampp\htdocs\EditSupForm.php on line 2
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in E:\xampp\htdocs\EditSupForm.php on line 8

This is the code behind the form:

<?php
 $con = mysql_connect("localhost", "root", "");  
    mysql_select_db("supplierdetails");   
      if (!$con)     
          {       
        die('Could not connect: ' . mysql_error());        
         }    
  //Run a query        
    $SupplierID= $_POST['SupplierID'] = $row ["SupplierID"];
$result1 = mysql_query ("SELECT * FROM suppliers WHERE SupplierID= '".$SupplierID."'")         or die(mysql_error());     
$row = mysql_fetch_array($result1); 
$SupplierID = $_POST['SupplierID'] = $row ["SupplierID"];
$SupplierName = $_POST['SupplierName'];
$Currency = $_POST['Currency'];
$Location = $_POST['Location'];
$ContactNumber = $_POST['ContactNumber'];
$Email = $_POST['Email'];  
$SupplierID = $row['SupplierID'];         
    $query = "UPDATE suppliers SET SupplierID = '".$SupplierID."', SupplierName= '".$SupplierName."', Currency = '".$Currency."', Location = '".$Location."', ContactNumber = '".$ContactNumber."', Email = '".$Email."' WHERE SupplierID = '".$id."'";     
$result1 = mysql_query($query);           
//Check whether the query was successful or not    
 if($result1) 
 {          
 echo "Supplier Updated"; 
 header ("Location: Supplier.php");    
 }
else 
{        
 die ("Query failed");    
  }    
 ?>

解决方案

In both of your code you are using $row ["SupplierID"]; before performing mysql query, `$row ["SupplierID"];' thats why your are getting errors.

这篇关于PHP的更新查询失败my_fetch_array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆