私はこれに本当に苦労しています。viewdetails.php ページ、addnew.php ページ、および php.php があります。php.php ページには、両方のページに対するクエリがあります。まず、viewdetails.php に結果を表示するクエリがあり、2 つ目は addnew.php ページに結果を表示するクエリです。私が抱えている問題は、ブラウザーで addnew.php を開くと、dbandpassword.php へのパスと、viewdetails.php のクエリ内の他の項目に関するエラーが表示されることです。
これらのすべてのクエリを 1 つのページ (php.php) に保持し、それらを別々に保持してエラーが発生しないようにするにはどうすればよいですか? 2 つのクエリを組み合わせる必要がありますか、それとも一部だけを組み合わせる必要がありますか? コードをクリーンアップする必要があることはわかっていますが、今は心配していません。また、独自のファイル (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;
}