使用url varible通过Php更新phpmyadmin表

时间:2015-04-22 19:46:29

标签: php mysql phpmyadmin edit

我在尝试在php中实现编辑页面时遇到问题。

从数据库doesent获取项目会造成任何问题,但尝试更新它会告诉我,我错过了一个字段并试图跳过检查,只留下一张未经编辑的表。

为了解释更多,有一个页面指向这个页面,同时传递一个可验证的id(propertyID),我们用它来获取所需的变量。

任何人都可以查看代码并告诉我我做错了什么,我已经得到了一个类似的页面工作,并且变得非常慌张,试图弄清楚为什么这个。

<?php


// Start sessions
include('includes/security.inc.php');
authorise();



if (!isset($_GET['propertyID']) || !is_numeric($_GET['propertyID']))
{
    header('Location:./houselist.php');
}
else
{
// Include connection file
include('includes/connection.inc.php');

    // Get  details
    connect();


    $propertyID = $_GET['propertyID'];

    $sql = "SELECT * FROM Properties WHERE propertyID='$propertyID' LIMIT 1";
    $result = @mysql_query($sql) or die('Unable to run query');
    $record = mysql_fetch_object($result);

    mysql_close();      

    // Check to see if the form has been submitted
    if (isset($_POST['submit']))
    {
        // Check to see all fields have been completed
    $address = $_POST['address'];
    $categoryID = $_POST['categoryID'];
    $price = $_POST['price'];
    $landlordName = $_POST['landlordName'];
    $img = $_POST['img'];
    $description= $_POST['description'];


    if (!empty($address) && !empty($categoryID) && !empty($price) && !empty($landlordName) && !empty($img) && !empty($description))
        {
            // Create an SQL query to add the comment


            $sql = "UPDATE property SET propertyID = '$propertyID', img = '$img', address = '$address', price = '$price', landlordName = '$landlordName', description = '$description' WHERE propertyID = $propertyID";

            // Connect to the database
            connect();

            // Run the query and store the result in a variable
            $result = mysql_query($sql) or die("Could not run query1");

            // Close connection to the database
            mysql_close();

            // Check if query was successful
            if ($result)
            {
                $message = '<div class="success"><p>You have successfully edited Article details.</p><p>Please <a href="Animal_Manage.php">Click Here</a> to view the Animal list.</p></div>';
            }
            else
            {
                $message = '<div class="error"><p>There was an error editing details, please try again</p></div>';
            }
        }
        else
        {
            $message = '<div class="error"><p>Please make sure you fill all fields in before submitting the form.</p></div>';
        }
    }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="css/960.css"/>
    <link rel="stylesheet" type="text/css" href="css/demo.css"/>
    <link rel="stylesheet" type="text/css" href="css/960_24_col.css"/>
    <link rel="stylesheet" type="text/css" href="css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="css/text.css"/>
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <title>Complete Property Solutions</title>
<title>Homescreen - Complete Property Solutions</title>
</head>

<body>

<div class="container_24" id="container">
    <div class="grid_24" id="banner">
        <a href="home.php"><img src="img/banner.png" width="960" height="92" /></a>
    </div>
    <div class="grid_18" id="nav" align="right">
        <ul id="topnav">
            <li><a href="home.php">Home</a></li>
            <li><a href="categories.php">Properties</a></li>
            <li><a href="landloeds.php">Landlords</a></li>
            <li><a href="tenants.php">Tenants</a></li>
            <li><a href="logout.php">Logout</a></li>
        </ul>
    </div>
    <div class="grid_6" id="search" align="right">
    <form action="search.php" method="GET"> 
        <input type="text" name="term" size="15">
          <input type="submit" value="Search"> 
    </form>
    </div>

</div>
<div class="container_24" id="container" align="center">
<div id="container">
  <form id="PropertyEdit" name="PropertyEdit" method="post" action="<? echo $_SERVER['PHP_SELF'] . "?propertyID=" . $propertyID; ?>">
  <input type="hidden" name="propertyID" id="propertyID" value="<?php echo $propertyID; ?>" />

<?php
    if (isset($message))
    {
        echo $message;  
    }
    else
    {
?>


 <div class="label"><label for="propertyID"></label></div>
  <div class="input"><input type="hidden" name="propertyID" id="propertyID" tabindex="1" value="<? echo $record->propertyID; ?>" /></div>  
  <br />

     <div class="label"><label for="categoryID">Category</label></div>
  <div class="input"><input type="text" name="categoryID" id="categoryID" tabindex="1" value="<? echo $record->categoryID; ?>" /></div>  
  <br />

    <div class="label">
      <label for="address">Address:</label></div>
  <div class="input"><input type="text" name="address" id="address" tabindex="1" value="<? echo $record->address; ?>" /></div>  
  <br />

 <div class="label"><label for="price">Price:</label></div>
  <div class="input"><input type="text" name="Price" id="price" tabindex="3" value="<? echo $record->price; ?>" /></div>


  <div class="label"><label for="landlordName">Landlord</label></div>
  <div class="input"><input type="text" name="landlordName" id="landlordName" tabindex="1" value="<? echo $record->landlordName; ?>" /></div>  
  <br />
   <div class="label"><label for="img">Image</label></div>
  <div class="input"><input type="text" name="img" id="img" tabindex="1" value="<? echo $record->img; ?>" /></div>  
  <br />
<div class="label"><label for="description">Description:</label></div>
  <div class="input"><textarea name="description" id="description" cols="50" rows="10" tabindex="5"><? echo $record->description; ?></textarea></div>
  <br />
  <div class="label">&nbsp;</div>
  <div class="input">
    <input type="reset" name="reset" id="reset" value="Reset" tabindex="6" />
    <input type="submit" name="submit" id="submit" value="Submit" tabindex="7" />
  </div>
  <p class="normal"><a href="index.php">Click Here</a> to Return to the Home page</p>
<?php
    }
?>
</form> </div>
</div>

</body>
</html>
<?php
}
?>

我对问题的最佳猜测将围绕

// Check to see if the form has been submitted
    if (isset($_POST['submit']))
    {
        // Check to see all fields have been completed
    $address = $_POST['address'];
    $categoryID = $_POST['categoryID'];
    $price = $_POST['price'];
    $landlordName = $_POST['landlordName'];
    $img = $_POST['img'];
    $description= $_POST['description'];


    if (!empty($address) && !empty($categoryID) && !empty($price) && !empty($landlordName) && !empty($img) && !empty($description))
        {
            // Create an SQL query to add the comment


            $sql = "UPDATE property SET propertyID = '$propertyID', img = '$img', address = '$address', price = '$price', landlordName = '$landlordName', description = '$description' WHERE propertyID = $propertyID";

            // Connect to the database
            connect();

            // Run the query and store the result in a variable
            $result = mysql_query($sql) or die("Could not run query1");

            // Close connection to the database
            mysql_close();

            // Check if query was successful
            if ($result)
            {
                $message = '<div class="success"><p>You have successfully edited Article details.</p><p>Please <a href="Animal_Manage.php">Click Here</a> to view the Animal list.</p></div>';
            }
            else
            {
                $message = '<div class="error"><p>There was an error editing details, please try again</p></div>';
            }
        }
        else
        {
            $message = '<div class="error"><p>Please make sure you fill all fields in before submitting the form.</p></div>';
        }
    }

以下部分,我的问题是我不确定究竟在哪里

<div class="container_24" id="container" align="center">
<div id="container">
  <form id="PropertyEdit" name="PropertyEdit" method="post" action="<? echo $_SERVER['PHP_SELF'] . "?propertyID=" . $propertyID; ?>">
  <input type="hidden" name="propertyID" id="propertyID" value="<?php echo $propertyID; ?>" />

<?php
    if (isset($message))
    {
        echo $message; 
    }
    else
    {
?>


 <div class="label"><label for="propertyID"></label></div>
  <div class="input"><input type="hidden" name="propertyID" id="propertyID" tabindex="1" value="<? echo $record->propertyID; ?>" /></div>  
  <br />

     <div class="label"><label for="categoryID">Category</label></div>
  <div class="input"><input type="text" name="categoryID" id="categoryID" tabindex="1" value="<? echo $record->categoryID; ?>" /></div>  
  <br />

    <div class="label">
      <label for="address">Address:</label></div>
  <div class="input"><input type="text" name="address" id="address" tabindex="1" value="<? echo $record->address; ?>" /></div>  
  <br />

 <div class="label"><label for="price">Price:</label></div>
  <div class="input"><input type="text" name="Price" id="price" tabindex="3" value="<? echo $record->price; ?>" /></div>


  <div class="label"><label for="landlordName">Landlord</label></div>
  <div class="input"><input type="text" name="landlordName" id="landlordName" tabindex="1" value="<? echo $record->landlordName; ?>" /></div>  
  <br />
   <div class="label"><label for="img">Image</label></div>
  <div class="input"><input type="text" name="img" id="img" tabindex="1" value="<? echo $record->img; ?>" /></div>  
  <br />
<div class="label"><label for="description">Description:</label></div>
  <div class="input"><textarea name="description" id="description" cols="50" rows="10" tabindex="5"><? echo $record->description; ?></textarea></div>
  <br />
  <div class="label">&nbsp;</div>
  <div class="input">
    <input type="reset" name="reset" id="reset" value="Reset" tabindex="6" />
    <input type="submit" name="submit" id="submit" value="Submit" tabindex="7" />

0 个答案:

没有答案