Я работаю на веб-сайте, управляемом базой данных, на котором есть обычные пользовательские страницы, страницы пользователей и страницы администратора. Все работает отлично, кроме страницы профиля пользователя. Я не могу заставить его работать правильно. Каждый раз, когда я что-то меняю, он перестает печатать правильные вещи или застревает и не добавляет его в базу данных.
Вот мой код:
<?php if(!isset($_SESSION['level']) || $_SESSION['level'] != 'Member') :?>
<div id="mainMemberProfile">
<table>
<form method='post' action='profile.php' name='profileform' id='profileform'>
<tr>
<td>
<p>
<label for='firstname'>First Name:</label><br/>
</p>
</td>
<td>
<p>
<input type='text' name='firstname' required value="<?php echo(isset($firstname['firstname'])); ?>"/>
</p>
</td>
</tr>
<tr>
<td>
<p>
<label for='lastname'>Last Name:</label><br/>
</p></td>
<td><p>
<input type='text' name='lastname' required value="<?php echo(isset($lastname['lastname'])); ?>"/>
</p></td>
</tr>
<tr>
<td>
<p>
<label for='email'>Email:</label><br/>
</p></td>
<td><p>
<input type='text' name='email' required value="<?php echo(isset($email['email'])); ?>"/>
</p></td>
</tr>
<tr>
<td>
<p>
<label for='address'>Address:</label><br/>
</p></td>
<td><p>
<input type='text' name='address' required value="<?php echo(isset($address['address'])); ?>"/>
</p></td>
</tr>
<tr>
<td>
<p>
<label for='address2'>Address 2:</label><br/>
</p></td>
<td><p>
<input type='text' name='address2' value="<?php echo(isset($address2['address2'])); ?>"/>
</p></td>
</tr>
<tr>
<td>
<p>
<label for='city'>City:</label><br/>
</p></td>
<td><p>
<input type="text" name="city" required value="<?php echo(isset($city['city'])); ?>"/>
</p></td>
</tr>
<tr><td><p>
<?php echo get_state(); ?>
</p></td>
</tr>
<tr>
<td>
<p>
<label for='zip'>Zip:</label><br/>
</p></td>
<td><p>
<input type='zip' name='zip' required value="<?php echo (isset($zip['zip'])); ?>"/>
</p></td>
</tr>
<tr>
<td>
<p>
<label for='residence'>Residence - Y or N:</label><br/>
</p></td>
<td><p>
<input type='residence' name='residence' required value="<?php echo (isset($residence['residence'])); ?>"/>
</p></td>
</tr>
<tr>
<td>
<p>
<label for='business'>Business - Y or N:</label><br/>
</p></td>
<td><p>
<input type='business' name='business' required value="<?php echo (isset($business['business'])); ?>"/>
</p></td>
</tr>
<tr>
<td><p>
<input type="submit" name="action" value="Submit"/>
</p></td>
</tr>
</form>
</table>
</div> </div>
<?php else :?>
<div id="profilesession">
<?php
if (isset($_POST['firstname'])){
$_SESSION['firstname'] = $_POST['firstname'];
$firstname = $_SESSION['firstname'];}
if (isset($_POST['lastname'])){
$_SESSION['lastname'] = $_POST['lastname'];
$lastname = $_SESSION['lastname'];}
if (isset($_POST['email'])){
$_SESSION['email'] = $_POST['email'];
$email = $_SESSION['email'];}
if (isset($_POST['address'])){
$_SESSION['address'] = $_POST['address'];
$address = $_SESSION['address'];}
if (isset($_POST['address2'])){
$_SESSION['address2'] = $_POST['address2'];
$address2 = $_SESSION['address2'];}
if (isset($_POST['city'])){
$_SESSION['city'] = $_POST['city'];
$city = $_SESSION['city'];}
if (isset($_POST['state'])){
$_SESSION['state'] = $_POST['state'];
$state = $_SESSION['state'];}
if (isset($_POST['zip'])){
$_SESSION['zip'] = $_POST['zip'];
$zip = $_SESSION['zip'];}
if (isset($_POST['residence'])){
$_SESSION['residence'] = $_POST['residence'];
$residence = $_SESSION['residence'];}
if (isset($_POST['business'])){
$_SESSION['business'] = $_POST['business'];
$business = $_SESSION['business'];}
echo print_member_profile($firstname, $lastname, $email, $address, $address2, $city, $state, $zip, $residence, $business); ?>
</div>
<?php
$idaddresses = '';
$idmembers = '';//get_members();''
$email = $_POST['email'];
$lastname = $_POST["lastname"];
$firstname = $_POST["firstname"];
$address = $_POST['address'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$residence = $_POST['residence'];
$business = $_POST['business'];
$idmembers = '';
$lastname = isset($_POST['lastname']) ? $_POST['lastname'] : '';
$firstname = isset($_POST['firstname']) ? $_POST['firstname'] : '';
function get_member_ids($lastname, $firstname) {
global $db;
$query = $db->prepare("SELECT idmembers FROM members WHERE last = '$lastname' AND first = '$firstname'");
$query->execute();
$idmembers = $query->fetch()['idmembers'];
return $idmembers;
}
function add_address($idaddresses, $idmembers, $email, $address, $address2, $city, $state, $zip, $residence, $business) {
global $db;
$lastname = isset($_POST['lastname']) ? $_POST['lastname'] : '';
$firstname = isset($_POST['firstname']) ? $_POST['firstname'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$address = isset($_POST['address']) ? $_POST['address'] : '';
$address2 = isset($_POST['address2']) ? $_POST['address2'] : '';
$city = isset($_POST['city']) ? $_POST['city'] : '';
$state = isset($_POST['state']) ? $_POST['state'] : '';
$zip = isset($_POST['zip']) ? $_POST['zip'] : '';
$residence = isset($_POST['residence']) ? $_POST['residence'] : '';
$business = isset($_POST['business']) ? $_POST['business'] : ''; $idmembers = get_member_ids($lastname, $firstname);
$query = "INSERT INTO addresses
(idaddresses, idmembers, email, address, address2, city, state, zip, residence, business)
VALUES
('$idaddresses', '$idmembers', '$email', '$address', '$address2', '$city', '$state', '$zip', '$residence', '$business')";
// var_dump($query);
// var_dump($db);
$db->exec($query);
}add_address($idaddresses, $idmembers, $email, $address, $address2, $city, $state, $zip, $residence, $business);?> <?php endif;?>
Я думаю, что это не работает из-за синтаксической ошибки в 169 строке:
$ idmembers = $ query-> fetch ();
Других решений пока нет …