0

我真的很挣扎。我有一个 viewdetails.php 页面、addnew.php 页面和一个 php.php。php.php 页面有我对这两个页面的查询。首先,我有在 viewdetails.php 上显示结果的查询,第二个是在 addnew.php 页面上显示结果的查询。我遇到的问题是,当我在浏览器中打开 addnew.php 时,它给了我关于 dbandpassword.php 的路径和 viewdetails.php 查询中的其他项目的错误。

如何将所有这些查询保存在一个页面 (php.php) 中并将它们分开,以免出现错误?我应该将这两个查询组合在一起还是只是其中的一部分?我知道代码需要清理,我现在并不担心。我也知道,如果将查询放在自己的文件(php.php,php2.php)中,它们都可以单独工作。

 <?php

 ob_start(); 
 require("../admin/dbandpassword.php");
 ob_end_clean(); 

// FETCH LEAD INFORMATION - this is query for viewdetails.php

 $query = ("SELECT * FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND leadstatus = 'New' ORDER BY date DESC");

$result = $mysqli->query($query) or die ("Error: ".mysqli_error($mysqli,$query));
while ($row = $result->fetch_array()) {

$firstname = $row ['firstname'];     
$lastname = $row['lastname'];
$ID = $row['ID'];   
$partner  = $row['spousefirst'];   
$phonecell = $row['phonecell'];
$email = $row['email'];
$date = $row['date'];
$contacttype = $row['contacttype'];
$agentassigned = $row['agentassigned'];
$leadstatus = $row['leadstatus'];

echo'
     <table>
     <tbody>       
     <tr>
        <td width="10"><input type="checkbox" name="" id="" value="'.$ID.'"></td>
        <td><a href="/backend/leads/view/?ID='.$ID.'"><strong>'.$firstname.' '.$lastname.'</strong></a></td>
        <td><a href="/backend/leads/view/?ID='. $ID.'">'.$partner.'</a></td>
        <td>'.$phonecell.'</td>
        <td><a href="mailto:'. $email.'">'.$email.'</a></td>
        <td>'.date("M jS, g:i A", strtotime($date)).'</td>
        <td>'.$contacttype.'</td>
        <td>'.$agentassigned.'</td>
        <td>'.$leadstatus.'</td>
        <td><a href="/backend/contacts/notes.php?ID='.$ID.'">View </a>+</td>
        <td><a href="/backend/contacts/todo.php?ID='.$ID.'">View </a>+</td>
        <td><a href="/backend/contacts/deletesuccess.php?ID='.$ID.'">D</a></td>
       </tr>
       </tbody>
       </table>';
         }

// ADD LEAD - this would be for addnew.php page

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

       require("../../admin/dcandpassword.php"); // NOTE THE DIFFERENT PATH THAN ABOVE BECAUSE addnew.php IS A FOLDER DEEPER

       $ID = $_POST['ID'];
       $date = mysqli_real_escape_string($con,$_POST['NOW()']);
       $firstname = mysqli_real_escape_string($mysqli,$_POST['firstname']);
       $lastname = mysqli_real_escape_string($mysqli,$_POST['lastname']);
       $spousefirst = mysqli_real_escape_string($mysqli,$_POST['spousefirst']);
       $spouselast = mysqli_real_escape_string($mysqli,$_POST['spouselast']);
       $primarybday = mysqli_real_escape_string($mysqli,$_POST['primarybday']);
       $spousebday = mysqli_real_escape_string($mysqli,$_POST['spousebday']);
       $phonecell = mysqli_real_escape_string($mysqli,$_POST['phonecell']);
       $phonehome = mysqli_real_escape_string($mysqli,$_POST['phonehome']);
       $phoneoffice = mysqli_real_escape_string($mysqli,$_POST['phoneoffice']);
       $spousecell = mysqli_real_escape_string($mysqli,$_POST['spousecell']);
       $phoneother = mysqli_real_escape_string($mysqli,$_POST['phoneother']);
       $email = mysqli_real_escape_string($mysqli,$_POST['email']);
       $emailspouse = mysqli_real_escape_string($mysqli,$_POST['emailspouse']);
       $emailother = mysqli_real_escape_string($mysqli,$_POST['emailother']);
       $emailspouseother = mysqli_real_escape_string($mysqli,$_POST['emailspouseother']);
       $address = mysqli_real_escape_string($mysqli,$_POST['address']);
       $suite = mysqli_real_escape_string($mysqli,$_POST['suite']);
       $city = mysqli_real_escape_string($mysqli,$_POST['city']);
       $state = mysqli_real_escape_string($mysqli,$_POST['state']);
       $zipcode = mysqli_real_escape_string($mysqli,$_POST['zipcode']);
       $addressother = mysqli_real_escape_string($mysqli,$_POST['addressother']);
       $suiteother = mysqli_real_escape_string($mysqli,$_POST['suiteother']);
       $cityother = mysqli_real_escape_string($mysqli$_POST['cityother']);
       $stateother = mysqli_real_escape_string($mysqli,$_POST['stateother']);
       $zipcodeother = mysqli_real_escape_string($mysqli,$_POST['zipcodeother']);
       $agentassigned = mysqli_real_escape_string($mysqli,$_POST['agentassigned']);
       $contacttype = mysqli_real_escape_string($mysqli,$_POST['contacttype']);
       $contactstatus = mysqli_real_escape_string($mysqli,$_POST['contactstatus']);
       $leadstatus = mysqli_real_escape_string($mysqli,$_POST['leadstatus']);
       $contactsource = mysqli_real_escape_string($mysqli,$_POST['contactsource']);
       $timing = mysqli_real_escape_string($mysqli,$_POST['timing']);
       $password = mysqli_real_escape_string($mysqli,$_POST['password']);
       $subscribesearches = mysqli_real_escape_string($mysqli,$_POST['subscribesearches']);
       $subscribedrips = mysqli_real_escape_string($mysqli,$_POST['subscribedrips']);

       $query = ("INSERT INTO contacts (date, firstname, lastname, spousefirst, spouselast, primarybday, spousebday, phonecell, phonehome, phoneoffice, spousecell, phoneother, email, emailspouse, emailother, emailspouseother, address, suite, city, state, zipcode, addressother, suiteother, cityother, stateother, zipcodeother, agentassigned, contacttype, contactstatus, leadstatus, contactsource, timing, password, subscribesearches, subscribedrips) VALUES (NOW(), '$firstname', '$lastname', '$spousefirst', '$spouselast', '$primarybday', '$spousebday', '$phonecell', '$phonehome', '$phoneoffice', '$spousecell', '$phoneother', '$email', '$emailspouse', '$emailother', '$emailspouseother', '$address', '$suite', '$city', '$state', '$zipcode', '$addressother', '$suiteother', '$cityother', '$stateother', '$zipcodeother', '$agentassigned', '$contacttype', '$contactstatus', '$leadstatus', '$contactsource', '$timing', '$password', '$subscribesearches', '$subscribedrips')");

       mysqli_query($mysqli,$query) or die ("Error: ".mysqli_error($mysqli));

       header("location: http://www.mydomain.com/backend/leads/edit/?ID=".mysqli_insert_id($mysqli));

  exit;
}
4

1 回答 1

1

您确实需要担心的不仅仅是分离查询,而是它们似乎彼此独立(一个是 INSERT,一个是 SELECT,它们不是事务的一部分)。

这里真正的错误可能是您在一个页面上需要两次相同的文件,这既不必要又危险。删除第二个 require 语句。

于 2012-06-28T00:22:12.963 回答