drls2738 2014-01-28 10:02
浏览 60

警告:mysql_fetch_array()期望参数1是资源,布尔[重复]

currently I'm having a big issue with my php code. What I'm trying to create a page to add users (done), now the problem is that I want a script that gives you the freedom to change user information. Now to the issue:

.

Pressing "ändra användare".

enter image description here

Pressing "ändra" button (problem error)

enter image description here

Edit.php

    <!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title> Edit - Reset UF </title>
<link rel="shortcut icon" href="images/icon.ico" >
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<link href='http://fonts.googleapis.com/css?family=Days+One' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>

</head>
<body>

<div id="content">

<div id="header">

<div id="position">
<div id="logo" onclick="location.href='index.html';">
</div>

<div id="meny">
<br>
<a class="menyfix" href="index.html"> Start </a>
<a class="menyfix" href="kontakt.html"> Kontakt </a>
<a class="menyfix" href="oppettider.html"> Öppettider </a>
<a class="menyfix" href="om.html"> Om oss </a>
<a class="menyfix" href="programbanken.html"> Programbanken </a>
<a class="menyfix" href="klara.php"> Färdiga datorer </a>
</div>
</div>
</div>
<div id="midcontent">
</div>
<div class="arrow-up"></div>
</div>

<div id="bottomcontent">
<p class="Article">
LÄGG TILL ELLER TA BORT
</p>
<?php
    include 'connection.php';

    $query = "SELECT * FROM kunder";

    $result = mysql_query($query);

while($kunder = mysql_fetch_array($result)) {
 echo "<p><b>". $kunder['Name'] . "</b>-" . $kunder['Description']. " </p>";
 echo"<a href=\"modify.php?id=" . $kunder['ID'] . "\">Ändra Användare</a> <br />";
 echo"<a href=\"modify.php?id=" . $kunder['ID'] . "\">Radera Användare</a>";

 }

?>
<h1> Lägg till en person</h1>
<form action="create.php" method="post">
Namn: <input type="text" name="inputName" value=""/> <br />
Problem: <input type="text" name="inputDesc" value=""/><br />
<br />
<input type="submit" name="submit"/>


</form>

</div>
</div>


</body>
</html>

_________________


*Modify.php

<?php
    include 'connection.php';

    if(isset($_GET['id'])){
    $id = $_GET['id'];
    }

    else{

    $id = $_POST['id'];

    }

    $q = "SELECT * FROM kunder WHERE ID = $id";
    $result = mysql_query($q);
    $kunder = mysql_fetch_array($result);

    ?>
    <h1>Du ändrar en användares information</h1>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Namn: <input type="text" name="inputName" value="<?php echo $kunder['Name']; ?>"/> <br />

Problem: <input type="text" name="inputDesc" value="<?php echo $kunder['Description']; ?>"/><br />
<br />
<input type="hidden" name="id" value="<?php $id ; ?>" />
<input type="submit" name="submit" value="Ändra" />



</form>
    <?php

    if(isset($_POST['submit'])){
    $u = "UPDATE kunder SET Name='$_POST[inputName]' , Description='$_POST[inputDesc]' WHERE ID = $id";
    mysql_query($u) or die (mysql_error());

    echo "Användaren har ändrats!";
    header("Location: edit.php");

    }
    else{

    }

    ?>*
</div>
  • 写回答

2条回答 默认 最新

  • douqing0713 2014-01-28 10:07
    关注

    This error means mysql_query returned false, which means something went wrong with the query.

    To find out what the error is, you could use:

    $result = mysql_query($query) or die(mysql_error());
    

    The or die part is only executed when mysql_query returns false and gives you the error message returned from mysql.

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法