0

我似乎在编辑用户/成员信息时遇到问题。我已向 scipt 提供了以下表格。对此的任何解决方案都非常感谢。我已经进行了验证检查以缩短脚本。

页面呈现没有错误。并显示成功消息。但是,数据库中的信息不会被更改/编辑。

来自数据库的值(对应于正在运行的第二个数据库查询)也显示在表单的字段中。但是,当我发布更改时,并未在数据库中进行更改。

**PHP scipt**

<?php
 session_start();
if (isset($_SESSION['id'])) {
$id = $_SESSION['id'];
$username = $_SESSION['username'];
}

else {
echo "You have not signed in";
}

 if (isset ($_POST['submit'])){
 $title = $_POST['title'];
 $content = $_POST['content'];
 $make= $_POST['make'];
 $model = $_POST['model'];
 $price = $_POST['price'];
 $location = $_POST['location'];

 include_once "scripts/connect_to_mysql.php";     

 $title = mysql_real_escape_string($title);
 $content = mysql_real_escape_string($content);
 $make = mysql_real_escape_string($make);
 $model = mysql_real_escape_string($model);
 $price = mysql_real_escape_string($price);
 $location = mysql_real_escape_string($location);

 $title = eregi_replace("`", "", $title);
 $content = eregi_replace("`", "", $content);
 $make = eregi_replace("`", "", $make);
 $model = eregi_replace("`", "", $model);
 $price = eregi_replace("`", "", $price);
 $location = eregi_replace("`", "", $location);

 $sql = mysql_query ("UPDATE `advertisements` SET `title`='$title',        
 `content`='$content', `make`='$make', `model`= '$model', `price`='$price', 
 `location`='$location', `id`='$id' WHERE `advertisements` . `ads_id`='$ads_id'")
 or die (mysql_error());

 $success = "You have successfuly edited your ad";
 }

 else {

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

  else {
  echo "URL not found";
   }

   include_once "scripts/connect_to_mysql.php";
   $query = mysql_query("SELECT * FROM advertisements WHERE ads_id='$ads_id'");

   while($row = mysql_fetch_assoc($query))
   {
   $title = $row["title"];
$content = $row["content"];
$make = $row["make"];   
$model = $row["model"];
$price = $row["price"];
$location = $row["location"];
$ads_id = $row ["ads_id"];
   }



   }

   ?>


   **form**

   <h1>Edit Advertisement</h1>

    <?php echo "$success";?>

<form action="edit.php" method="POST" enctype="multipart/form-data">

 Title: <input name="title" type="text" value="<?php print "$title"; ?>"/><br/>
 Content: <input name="content" type="text" value="<?php print "$content";
     ?>"/><br/>
 Make: <select name="make"> 
 <option value="<?php echo "$make"; ?>"><?php echo "$make"; ?></option> 
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
 </select> <br/>

 Model: <select name="model"> 
  <option value="<?php echo "$model"; ?>"><?php echo "$model"; ?></option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
</select> <br/>
Price: <input name="price" type="text" value="<?php print "$price"; ?>"> <br/>

Location: <select name="location"> <br/>
        <option value="<?php echo "$location"; ?>"><?php echo "$location";
                    ?></option>
        <option value="Leicester">Leicester</option>
        <option value="Loughborough">Loughborough</option>
        <option value="Nottingham">Nottingham</option>
        <option value="Derby">Derby</option>
</select> <br/> <br/>

     <input name="submit" type="submit" value="Edit ad"/>

</form>
4

1 回答 1

0

尝试移动

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

  else {
  echo "URL not found";
   }

到右上角之后

 if (isset ($_POST['submit'])){

这可能会导致问题

我猜你的表单动作必须有类似的东西

<form action ="edit.php?ads_id=the id for the page" >
于 2012-04-21T00:14:58.283 回答