dqxboe2628 2015-04-22 19:46
浏览 40

使用url变量通过Php更新phpmyadmin表

im having a problem when trying to implement a edit page in php.

Getting items from the database doesent pose any problem, yet trying to update it tells me that i have missed a field and trying to skip the check just leaves me with a unedited table.

To explain more, there is a page that directs to this one while passing on a id (propertyID) veriable and from that we use it to grab the desired variables.

Can anyone look at the code and tell me what i have done wrong, i have prevously got a similar page working and am getting quite flustered trying to figure out why this one isent.

<?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
}
?>

my best guess for the problem would revolve around

// 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>';
        }
    }

And the below section, my problem is that im not sure where exactly

<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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
    • ¥15 C# datagridview 单元格显示进度及值
    • ¥15 thinkphp6配合social login单点登录问题
    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配