Post by corwinvegas on Apr 22, 2010 18:19:07 GMT -8
Here is a login script I'm working on and I'm getting an empty query error and it's not updating the information in the rows in my database table. any ideas would be welcome.
...
<?php
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (isset($_POST['submit'])) {
$first_name = mysqli_real_escape_string($dbc, trim($_POST['firstname']));
$last_name = mysqli_real_escape_string($dbc, trim($_POST['lastname']));
$sex = mysqli_real_escape_string($dbc, trim($_POST['sex']));
$age = mysqli_real_escape_string($dbc, trim($_POST['age']));
$city = mysqli_real_escape_string($dbc, trim($_POST['city']));
$state = mysqli_real_escape_string($dbc, trim($_POST['state']));
$email = mysqli_real_escape_string($dbc, trim($_POST['email']));
$description = mysqli_real_escape_string($dbc, trim($_POST['description']));
$error = false;
if (!$error) {
if (!empty($first_name) && !empty($last_name) && !empty($gender) && !empty($birthdate) && !empty($city) && !empty($state) && !empty($email) && !empty($description)) {
$query = "UPDATE profile SET firstname = '$first_name', lastname = '$last_name', sex = '$sex', " .
" age = '$age', city = '$city', state = '$state', email = '$email', description = '$description' WHERE user_id = '" . $_SESSION['user_id'] . "'";
}
mysqli_query($dbc, $query);
echo '<p>Your profile has been successfully updated. Would you like to <a href="viewprofile.php">view your profile</a>?</p>';
mysqli_close($dbc);
exit();
}
else {
echo '<p class="error">You must enter all of the profile data.</p>';
}
}
else {
$query = "SELECT firstname, lastname, sex, age, city, state, email, description FROM profile WHERE user_id = '" . $_SESSION['user_id'] . "'";
$data = mysqli_query($dbc, $query);
$row = mysqli_fetch_array($data);
if ($row != NULL) {
$first_name = $row['firstname'];
$last_name = $row['lastname'];
$sex = $row['sex'];
$age = $row['age'];
$city = $row['city'];
$state = $row['state'];
$email = $row['email'];
$description = $row['description'];
}
else {
echo '<p class="error">There was a problem accessing your profile.</p>';
}
}
mysqli_close($dbc);
?>
<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<fieldset>
<legend><strong><font color="#000000" size="3" face="Arial, Helvetica, sans-serif">
Your Account / Profile</font></strong></legend>
<label for="firstname"><font size="2" face="Arial, Helvetica, sans-serif"><strong>First name:</strong></font></label>
<input type="text" id="firstname" name="firstname" value="<?php if (!empty($first_name)) echo $first_name; ?>" /><br />
<label for="lastname"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Last name:</strong></font></label>
<input type="text" id="lastname" name="lastname" value="<?php if (!empty($last_name)) echo $last_name; ?>"/><br />
<label for="sex"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Sex:</strong></font></label>
<select name="sex" size="1" type="text" id="sex">
<option>- Select -</option>
<option value="female" <?php if (!empty($sex) && $sex == 'female') echo 'selected = "selected"'; ?>>Female</option>
<option value="male" <?php if (!empty($sex) && $sex == 'male') echo 'selected = "selected"'; ?>>Male</option>
</select> <br />
<label for="age"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Age:</strong></font></label>
<input name="age" type="text" id="age" size="5" maxlength="2" value="<?php if (!empty($age)) echo $age; ?>" />
<font size="2" face="Arial, Helvetica, sans-serif"><strong><em>***You must be
at least 18 years of age to sign up as a "Friend By The Hour"***</em></strong></font><br />
<label for="city"><font size="2" face="Arial, Helvetica, sans-serif"><strong>City:</strong></font></label>
<input type="text" id="city" name="city" value="<?php if (!empty($city)) echo $city; ?>" /><br />
<label for="state"><font size="2" face="Arial, Helvetica, sans-serif"><strong>State:</strong></font></label>
<select name="state" size="1" type="text" id="state">
<option>- Select -</option>
<option value="alabama" <?php if (!empty($state) && $state == 'Alabama') echo 'selected = "selected"'; ?>>Alabama</option>
<option value="alaska" <?php if (!empty($state) && $state == 'Alaska') echo 'selected = "selected"'; ?>>Alaska</option>
<option value="arizona" <?php if (!empty($state) && $state == 'Arizona') echo 'selected = "selected"'; ?>>Arizona</option>
<option value="arkansas" <?php if (!empty($state) && $state == 'Arkansas') echo 'selected = "selected"'; ?>>Arkansas</option>
<option value="california" <?php if (!empty($state) && $state == 'California') echo 'selected = "selected"'; ?>>California</option>
<option value="colorado" <?php if (!empty($state) && $state == 'Colorado') echo 'selected = "selected"'; ?>>Colorado</option>
<option value="connecticut" <?php if (!empty($state) && $state == 'Connecticut') echo 'selected = "selected"'; ?>>Connecticut</option>
<option value="delaware" <?php if (!empty($state) && $state == 'Delaware') echo 'selected = "selected"'; ?>>Delaware</option>
<option value="florida" <?php if (!empty($state) && $state == 'Florida') echo 'selected = "selected"'; ?>>Florida</option>
<option value="georgia" <?php if (!empty($state) && $state == 'Georgia') echo 'selected = "selected"'; ?>>Georgia</option>
<option value="hawaii" <?php if (!empty($state) && $state == 'Hawaii') echo 'selected = "selected"'; ?>>Hawaii</option>
<option value="idaho" <?php if (!empty($state) && $state == 'Idaho') echo 'selected = "selected"'; ?>>Idaho</option>
<option value="illinois" <?php if (!empty($state) && $state == 'Illinois') echo 'selected = "selected"'; ?>>Illinois</option>
<option value="indiana" <?php if (!empty($state) && $state == 'Indiana') echo 'selected = "selected"'; ?>>Indiana</option>
<option value="iowa" <?php if (!empty($state) && $state == 'Iowa') echo 'selected = "selected"'; ?>>Iowa</option>
<option value="kansas" <?php if (!empty($state) && $state == 'Kansas') echo 'selected = "selected"'; ?>>Kansas</option>
<option value="kentucky" <?php if (!empty($state) && $state == 'Kentucky') echo 'selected = "selected"'; ?>>Kentucky</option>
<option value="louisiana" <?php if (!empty($state) && $state == 'Louisiana') echo 'selected = "selected"'; ?>>Louisiana</option>
<option value="maine" <?php if (!empty($state) && $state == 'Maine') echo 'selected = "selected"'; ?>>Maine</option>
<option value="maryland" <?php if (!empty($state) && $state == 'Maryland') echo 'selected = "selected"'; ?>>Maryland</option>
<option value="massachusetts" <?php if (!empty($state) && $state == 'Massachusetts') echo 'selected = "selected"'; ?>>Massachusetts</option>
<option value="michigan" <?php if (!empty($state) && $state == 'Michigan') echo 'selected = "selected"'; ?>>Michigan</option>
<option value="minnesota" <?php if (!empty($state) && $state == 'Minnesota') echo 'selected = "selected"'; ?>>Minnesota</option>
<option value="mississippi" <?php if (!empty($state) && $state == 'Mississippi') echo 'selected = "selected"'; ?>>Mississippi</option>
<option value="missouri" <?php if (!empty($state) && $state == 'Missouri') echo 'selected = "selected"'; ?>>Missouri</option>
<option value="montana" <?php if (!empty($state) && $state == 'Montana') echo 'selected = "selected"'; ?>>Montana</option>
<option value="nebraska" <?php if (!empty($state) && $state == 'Nebraska') echo 'selected = "selected"'; ?>>Nebraska</option>
<option value="nevada" <?php if (!empty($state) && $state == 'Nevada') echo 'selected = "selected"'; ?>>Nevada</option>
<option value="newhampshire" <?php if (!empty($state) && $state == 'New Hampshire') echo 'selected = "selected"'; ?>>New Hampshire</option>
<option value="newjersey" <?php if (!empty($state) && $state == 'New Jersey') echo 'selected = "selected"'; ?>>New Jersey</option>
<option value="newmexico" <?php if (!empty($state) && $state == 'New Mexico') echo 'selected = "selected"'; ?>>New Mexico</option>
<option value="newyork" <?php if (!empty($state) && $state == 'New York') echo 'selected = "selected"'; ?>>New York</option>
<option value="northcarolina" <?php if (!empty($state) && $state == 'North Carolina') echo 'selected = "selected"'; ?>>North Carolina</option>
<option value="northdakota" <?php if (!empty($state) && $state == 'North Dakota') echo 'selected = "selected"'; ?>>North Dakota</option>
<option value="ohio" <?php if (!empty($state) && $state == 'Ohio') echo 'selected = "selected"'; ?>>Ohio</option>
<option value="oklahoma" <?php if (!empty($state) && $state == 'Oklahoma') echo 'selected = "selected"'; ?>>Oklahoma</option>
<option value="oregon" <?php if (!empty($state) && $state == 'Oregon') echo 'selected = "selected"'; ?>>Oregon</option>
<option value="pennsylvania" <?php if (!empty($state) && $state == 'Pennsylvania') echo 'selected = "selected"'; ?>>Pennsylvania</option>
<option value="rhodeisland" <?php if (!empty($state) && $state == 'Rhode Island') echo 'selected = "selected"'; ?>>Rhode Island</option>
<option value="southcarolina" <?php if (!empty($state) && $state == 'South Carolina') echo 'selected = "selected"'; ?>>South Carolina</option>
<option value="southdakota" <?php if (!empty($state) && $state == 'South Dakota') echo 'selected = "selected"'; ?>>South Dakota</option>
<option value="tennessee" <?php if (!empty($state) && $state == 'Tennessee') echo 'selected = "selected"'; ?>>Tennessee</option>
<option value="texas" <?php if (!empty($state) && $state == 'Texas') echo 'selected = "selected"'; ?>>Texas</option>
<option value="utah" <?php if (!empty($state) && $state == 'Utah') echo 'selected = "selected"'; ?>>Utah</option>
<option value="vermont" <?php if (!empty($state) && $state == 'Vermont') echo 'selected = "selected"'; ?>>Vermont</option>
<option value="virginia" <?php if (!empty($state) && $state == 'Virginia') echo 'selected = "selected"'; ?>>Virginia</option>
<option value="washinton" <?php if (!empty($state) && $state == 'Washington') echo 'selected = "selected"'; ?>>Washington</option>
<option value="westvirginia" <?php if (!empty($state) && $state == 'West Virginia') echo 'selected = "selected"'; ?>>West Virginia</option>
<option value="wisconsin" <?php if (!empty($state) && $state == 'Wisconsin') echo 'selected = "selected"'; ?>>Wisconsin</option>
<option value="wyoming" <?php if (!empty($state) && $state == 'Wyoming') echo 'selected = "selected"'; ?>>Wyoming</option>
</select><br />
<label for="email"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Email:
</strong></font></label>
<input type="text" id="email" name="email" value="<?php if (!empty($email)) echo $email; ?>" />
<br>
<br>
<strong><font size="2" face="Arial, Helvetica, sans-serif">please describe yourself </font></strong><br>
<br>
<textarea name="description" cols="80" rows="5" id="description" value="<?php if (!empty($description)) echo $description; ?>" />Type your personal description here...</textarea>
<br>
input type="submit" value="submit." name="submit" />
</p>
</fieldset>
</form>
...
...
<?php
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (isset($_POST['submit'])) {
$first_name = mysqli_real_escape_string($dbc, trim($_POST['firstname']));
$last_name = mysqli_real_escape_string($dbc, trim($_POST['lastname']));
$sex = mysqli_real_escape_string($dbc, trim($_POST['sex']));
$age = mysqli_real_escape_string($dbc, trim($_POST['age']));
$city = mysqli_real_escape_string($dbc, trim($_POST['city']));
$state = mysqli_real_escape_string($dbc, trim($_POST['state']));
$email = mysqli_real_escape_string($dbc, trim($_POST['email']));
$description = mysqli_real_escape_string($dbc, trim($_POST['description']));
$error = false;
if (!$error) {
if (!empty($first_name) && !empty($last_name) && !empty($gender) && !empty($birthdate) && !empty($city) && !empty($state) && !empty($email) && !empty($description)) {
$query = "UPDATE profile SET firstname = '$first_name', lastname = '$last_name', sex = '$sex', " .
" age = '$age', city = '$city', state = '$state', email = '$email', description = '$description' WHERE user_id = '" . $_SESSION['user_id'] . "'";
}
mysqli_query($dbc, $query);
echo '<p>Your profile has been successfully updated. Would you like to <a href="viewprofile.php">view your profile</a>?</p>';
mysqli_close($dbc);
exit();
}
else {
echo '<p class="error">You must enter all of the profile data.</p>';
}
}
else {
$query = "SELECT firstname, lastname, sex, age, city, state, email, description FROM profile WHERE user_id = '" . $_SESSION['user_id'] . "'";
$data = mysqli_query($dbc, $query);
$row = mysqli_fetch_array($data);
if ($row != NULL) {
$first_name = $row['firstname'];
$last_name = $row['lastname'];
$sex = $row['sex'];
$age = $row['age'];
$city = $row['city'];
$state = $row['state'];
$email = $row['email'];
$description = $row['description'];
}
else {
echo '<p class="error">There was a problem accessing your profile.</p>';
}
}
mysqli_close($dbc);
?>
<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<fieldset>
<legend><strong><font color="#000000" size="3" face="Arial, Helvetica, sans-serif">
Your Account / Profile</font></strong></legend>
<label for="firstname"><font size="2" face="Arial, Helvetica, sans-serif"><strong>First name:</strong></font></label>
<input type="text" id="firstname" name="firstname" value="<?php if (!empty($first_name)) echo $first_name; ?>" /><br />
<label for="lastname"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Last name:</strong></font></label>
<input type="text" id="lastname" name="lastname" value="<?php if (!empty($last_name)) echo $last_name; ?>"/><br />
<label for="sex"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Sex:</strong></font></label>
<select name="sex" size="1" type="text" id="sex">
<option>- Select -</option>
<option value="female" <?php if (!empty($sex) && $sex == 'female') echo 'selected = "selected"'; ?>>Female</option>
<option value="male" <?php if (!empty($sex) && $sex == 'male') echo 'selected = "selected"'; ?>>Male</option>
</select> <br />
<label for="age"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Age:</strong></font></label>
<input name="age" type="text" id="age" size="5" maxlength="2" value="<?php if (!empty($age)) echo $age; ?>" />
<font size="2" face="Arial, Helvetica, sans-serif"><strong><em>***You must be
at least 18 years of age to sign up as a "Friend By The Hour"***</em></strong></font><br />
<label for="city"><font size="2" face="Arial, Helvetica, sans-serif"><strong>City:</strong></font></label>
<input type="text" id="city" name="city" value="<?php if (!empty($city)) echo $city; ?>" /><br />
<label for="state"><font size="2" face="Arial, Helvetica, sans-serif"><strong>State:</strong></font></label>
<select name="state" size="1" type="text" id="state">
<option>- Select -</option>
<option value="alabama" <?php if (!empty($state) && $state == 'Alabama') echo 'selected = "selected"'; ?>>Alabama</option>
<option value="alaska" <?php if (!empty($state) && $state == 'Alaska') echo 'selected = "selected"'; ?>>Alaska</option>
<option value="arizona" <?php if (!empty($state) && $state == 'Arizona') echo 'selected = "selected"'; ?>>Arizona</option>
<option value="arkansas" <?php if (!empty($state) && $state == 'Arkansas') echo 'selected = "selected"'; ?>>Arkansas</option>
<option value="california" <?php if (!empty($state) && $state == 'California') echo 'selected = "selected"'; ?>>California</option>
<option value="colorado" <?php if (!empty($state) && $state == 'Colorado') echo 'selected = "selected"'; ?>>Colorado</option>
<option value="connecticut" <?php if (!empty($state) && $state == 'Connecticut') echo 'selected = "selected"'; ?>>Connecticut</option>
<option value="delaware" <?php if (!empty($state) && $state == 'Delaware') echo 'selected = "selected"'; ?>>Delaware</option>
<option value="florida" <?php if (!empty($state) && $state == 'Florida') echo 'selected = "selected"'; ?>>Florida</option>
<option value="georgia" <?php if (!empty($state) && $state == 'Georgia') echo 'selected = "selected"'; ?>>Georgia</option>
<option value="hawaii" <?php if (!empty($state) && $state == 'Hawaii') echo 'selected = "selected"'; ?>>Hawaii</option>
<option value="idaho" <?php if (!empty($state) && $state == 'Idaho') echo 'selected = "selected"'; ?>>Idaho</option>
<option value="illinois" <?php if (!empty($state) && $state == 'Illinois') echo 'selected = "selected"'; ?>>Illinois</option>
<option value="indiana" <?php if (!empty($state) && $state == 'Indiana') echo 'selected = "selected"'; ?>>Indiana</option>
<option value="iowa" <?php if (!empty($state) && $state == 'Iowa') echo 'selected = "selected"'; ?>>Iowa</option>
<option value="kansas" <?php if (!empty($state) && $state == 'Kansas') echo 'selected = "selected"'; ?>>Kansas</option>
<option value="kentucky" <?php if (!empty($state) && $state == 'Kentucky') echo 'selected = "selected"'; ?>>Kentucky</option>
<option value="louisiana" <?php if (!empty($state) && $state == 'Louisiana') echo 'selected = "selected"'; ?>>Louisiana</option>
<option value="maine" <?php if (!empty($state) && $state == 'Maine') echo 'selected = "selected"'; ?>>Maine</option>
<option value="maryland" <?php if (!empty($state) && $state == 'Maryland') echo 'selected = "selected"'; ?>>Maryland</option>
<option value="massachusetts" <?php if (!empty($state) && $state == 'Massachusetts') echo 'selected = "selected"'; ?>>Massachusetts</option>
<option value="michigan" <?php if (!empty($state) && $state == 'Michigan') echo 'selected = "selected"'; ?>>Michigan</option>
<option value="minnesota" <?php if (!empty($state) && $state == 'Minnesota') echo 'selected = "selected"'; ?>>Minnesota</option>
<option value="mississippi" <?php if (!empty($state) && $state == 'Mississippi') echo 'selected = "selected"'; ?>>Mississippi</option>
<option value="missouri" <?php if (!empty($state) && $state == 'Missouri') echo 'selected = "selected"'; ?>>Missouri</option>
<option value="montana" <?php if (!empty($state) && $state == 'Montana') echo 'selected = "selected"'; ?>>Montana</option>
<option value="nebraska" <?php if (!empty($state) && $state == 'Nebraska') echo 'selected = "selected"'; ?>>Nebraska</option>
<option value="nevada" <?php if (!empty($state) && $state == 'Nevada') echo 'selected = "selected"'; ?>>Nevada</option>
<option value="newhampshire" <?php if (!empty($state) && $state == 'New Hampshire') echo 'selected = "selected"'; ?>>New Hampshire</option>
<option value="newjersey" <?php if (!empty($state) && $state == 'New Jersey') echo 'selected = "selected"'; ?>>New Jersey</option>
<option value="newmexico" <?php if (!empty($state) && $state == 'New Mexico') echo 'selected = "selected"'; ?>>New Mexico</option>
<option value="newyork" <?php if (!empty($state) && $state == 'New York') echo 'selected = "selected"'; ?>>New York</option>
<option value="northcarolina" <?php if (!empty($state) && $state == 'North Carolina') echo 'selected = "selected"'; ?>>North Carolina</option>
<option value="northdakota" <?php if (!empty($state) && $state == 'North Dakota') echo 'selected = "selected"'; ?>>North Dakota</option>
<option value="ohio" <?php if (!empty($state) && $state == 'Ohio') echo 'selected = "selected"'; ?>>Ohio</option>
<option value="oklahoma" <?php if (!empty($state) && $state == 'Oklahoma') echo 'selected = "selected"'; ?>>Oklahoma</option>
<option value="oregon" <?php if (!empty($state) && $state == 'Oregon') echo 'selected = "selected"'; ?>>Oregon</option>
<option value="pennsylvania" <?php if (!empty($state) && $state == 'Pennsylvania') echo 'selected = "selected"'; ?>>Pennsylvania</option>
<option value="rhodeisland" <?php if (!empty($state) && $state == 'Rhode Island') echo 'selected = "selected"'; ?>>Rhode Island</option>
<option value="southcarolina" <?php if (!empty($state) && $state == 'South Carolina') echo 'selected = "selected"'; ?>>South Carolina</option>
<option value="southdakota" <?php if (!empty($state) && $state == 'South Dakota') echo 'selected = "selected"'; ?>>South Dakota</option>
<option value="tennessee" <?php if (!empty($state) && $state == 'Tennessee') echo 'selected = "selected"'; ?>>Tennessee</option>
<option value="texas" <?php if (!empty($state) && $state == 'Texas') echo 'selected = "selected"'; ?>>Texas</option>
<option value="utah" <?php if (!empty($state) && $state == 'Utah') echo 'selected = "selected"'; ?>>Utah</option>
<option value="vermont" <?php if (!empty($state) && $state == 'Vermont') echo 'selected = "selected"'; ?>>Vermont</option>
<option value="virginia" <?php if (!empty($state) && $state == 'Virginia') echo 'selected = "selected"'; ?>>Virginia</option>
<option value="washinton" <?php if (!empty($state) && $state == 'Washington') echo 'selected = "selected"'; ?>>Washington</option>
<option value="westvirginia" <?php if (!empty($state) && $state == 'West Virginia') echo 'selected = "selected"'; ?>>West Virginia</option>
<option value="wisconsin" <?php if (!empty($state) && $state == 'Wisconsin') echo 'selected = "selected"'; ?>>Wisconsin</option>
<option value="wyoming" <?php if (!empty($state) && $state == 'Wyoming') echo 'selected = "selected"'; ?>>Wyoming</option>
</select><br />
<label for="email"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Email:
</strong></font></label>
<input type="text" id="email" name="email" value="<?php if (!empty($email)) echo $email; ?>" />
<br>
<br>
<strong><font size="2" face="Arial, Helvetica, sans-serif">please describe yourself </font></strong><br>
<br>
<textarea name="description" cols="80" rows="5" id="description" value="<?php if (!empty($description)) echo $description; ?>" />Type your personal description here...</textarea>
<br>
input type="submit" value="submit." name="submit" />
</p>
</fieldset>
</form>
...