$ row错误一直说未定义?我找不到错误

时间:2016-01-31 15:05:23

标签: php html mysql database localhost

<?php
$con = mysql_connect("localhost","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }




mysql_select_db("database", $con);
if(isset($_GET['id']))
{
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM pleasework WHERE ID= $_GET[id]");
$row = mysql_fetch_array($result);
}
if(isset($_POST['New']))
{
    $New= $_POST['New'];
    $id= $_POST['id'];
    $sql = "UPDATE pleasework SET Name = '$New' WHERE id='$id'";
    $result = mysql_query($sql) or die("could not update" . mysql_error);

}

?>

 <form action="edit.php" id="form2" method="post" name="form2">
<img id="close1" src="X.png" width="25" height="25" onclick ="div_hide1()">
<h2><font size="6">Please change existing data</font></h2>
<hr>

     <font color="yellow">Change Name to: </font><input type="text" name="New" value="<?php echo $row['Name'];?>"/><br><br>
      <font color="yellow"> Change Cause to: </font> <input type="text" name="New1" value="<?php echo $row['Cause'];?>"/><br><br>
 <font color="yellow">Change Symptom to:  </font><input type="text" name="New2" value="<?php echo $row['Symptom'];?>"/><br><br>
      <font color="yellow"> Change Gene_affected to:  </font><input type="text" name="New3"value="<?php echo $row['Gene_affected'];?>" /><br><br>
      <input type="hidden" name="id" value="<?php echo $row['id'];?>"/>
    <input type="submit" onclick="clicked(event)" />
</form>

<?php
if(isset($_POST['submit'])){
    $u = "(UPDATE pleasework SET Name='$_POST[New]' , '$_POST[New1]' ,     '$_POST[New2]' , '$_POST[New3]'  WHERE ID=$_POST[id]";
    mysql_query($u) or die(mysql_error());

    echo"User has been modified";
    header("Location: databse.php");
} 

?>

每当我点击edit.php文件上的提交时,此错误就会一直弹出。我以为我已经宣布$row了?

所有输入类型都会出现同样的错误...

<br /><b>Notice</b>:  Undefined variable: row in <b>E:\XAMPP\htdocs\database\edit.php</b> on line <b>34</b><br />

1 个答案:

答案 0 :(得分:0)

试试这个:

 <?php
    $submit=isset($_POST['submit']);
    $id=isset($_POST['id']);

    if($submit)
    {
        $New= $_POST['New'];
        $id= $_POST['id'];
      //insert db configurations
        $sql = "UPDATE pleasework SET Name = '$New' WHERE id='$id'";
        $result = mysql_query($sql) or die("could not update" . mysql_error);
    }
    else if($id)
    {
    $id= $_POST['id'];
      //insert db configurations
    $result = mysql_query("SELECT * FROM pleasework WHERE ID= $_GET[id]");
    $row = mysql_fetch_array($result);
    ?>

     <form action="edit.php" id="form2" method="post" name="form2">
    <img id="close1" src="X.png" width="25" height="25" onclick ="div_hide1()">
    <h2><font size="6">Please change existing data</font></h2>
    <hr>

         <font color="yellow">Change Name to: </font><input type="text" name="New" value="<?php echo $row['Name'];?>"/><br><br>
          <font color="yellow"> Change Cause to: </font> <input type="text" name="New1" value="<?php echo $row['Cause'];?>"/><br><br>
     <font color="yellow">Change Symptom to:  </font><input type="text" name="New2" value="<?php echo $row['Symptom'];?>"/><br><br>
          <font color="yellow"> Change Gene_affected to:  </font><input type="text" name="New3"value="<?php echo $row['Gene_affected'];?>" /><br><br>
          <input type="hidden" name="id" value="<?php echo $row['id'];?>"/>
        <input type="submit" onclick="clicked(event)" />
    </form>

    <?php
    }
    else
    {
    echo"anything";
    }
    ?>