我目前正在为我的网站制作个人资料页面。到目前为止,这一切都很顺利,除了在编辑个人资料页面上。数据库似乎没有像应该的那样更新变量,我也不知道为什么。有3个主要代码块,实际输入部分是我认为的问题。
在此之前,变量不会更新,但在该代码块之后,变量会更新(它是一个表单)。顺便说一句,如果你想知道问题是什么,就在这里。如果用户输入了某些内容,然后将其删除,则会在表单提交时重新输入数据。现在,这里是3个主要代码块(按顺序):
function utf8_encode_string($value) {
if (empty($_POST[$value])) {
$str = "";
return $str;
}
else {
$str = utf8_encode(htmlspecialchars(trim($_POST[$value]), ENT_QUOTES));
return $str;
}
}
//Grabs all of the profile information
$accountinfoquery = "SELECT * FROM users WHERE username = :username";
$accountinfoparams = array(':username' => $accounturl);
try{
$accountinfostmt = $connection->prepare($accountinfoquery);
$accountinforesult = $accountinfostmt->execute($accountinfoparams);
}
catch(PDOException $ex){
echo ("Failed to run query: " . $ex->getMessage());
}
$accountinfocolumns = $accountinfostmt->fetch();
$firstnameinput = utf8_encode_string("firstname");
$lastnameinput = utf8_encode_string("lastname");
$ageinput = utf8_encode_string("age");
$locationinput = utf8_encode_string("location");
$quoteinput = utf8_encode_string("quote");
$genderinput = utf8_encode_string("gender");
$aboutinput = utf8_encode_string("about");
if (!$firstnameinput) {
$firstnameinput = utf8_encode(htmlspecialchars(trim($accountinfocolumns["firstname"]), ENT_QUOTES));
}
if (!$lastnameinput) {
$lastnameinput = utf8_encode(htmlspecialchars(trim($accountinfocolumns["lastname"]), ENT_QUOTES));
}
if (!$ageinput) {
if ($accountinfocolumns["age"] == "0") {
$ageinput = "";
}
else {
$ageinput = utf8_encode(htmlspecialchars(trim($accountinfocolumns["age"]), ENT_QUOTES));
}
}
if (!$locationinput) {
$locationinput = utf8_encode(htmlspecialchars(trim($accountinfocolumns["location"]), ENT_QUOTES));
}
if (!$quoteinput) {
$quoteinput = utf8_encode(htmlspecialchars(trim($accountinfocolumns["quote"]), ENT_QUOTES));
}
if (!$genderinput) {
$genderinput = utf8_encode(htmlspecialchars(trim($accountinfocolumns["gender"]), ENT_QUOTES));
}
if (!$aboutinput) {
$aboutinput = utf8_encode(htmlspecialchars(trim($accountinfocolumns["about"]), ENT_QUOTES));
}
//Final Check
$firstnamefinalcheck = False;
$lastnamefinalcheck = False;
$agefinalcheck = False;
$locationfinalcheck = False;
$quotefinalcheck = False;
$aboutfinalcheck = False;
(重要提示:我认为问题在按钮附近)。
<form action="http://localhost/postin'/profiles/edit/<?php print utf8_decode($loggedin_session_permalink); ?>" method="post">
<div class="row" id="informationquoteholder">
<div id="informationtitlesmall" class="col-xs-12 col-sm-3">
Quote
</div>
<div id="quoteinputwidth" class="col-xs-12 col-sm-5 col-md-8">
<input type="text" name="quote" id="quoteinput" value="<?php print utf8_decode($quoteinput); ?>" />
</div>
<?php
if ($_POST) {
$quotetest1 = False;
$quotetest2 = False;
if (utf8_decode(trim($_POST["quote"])) == "") {
$quotefinalcheck = True;
$quoteinput = "";
}
else {
// Test #1 - Makes sure it fits the length requirements
if(mb_strlen(utf8_decode($quoteinput), "UTF-8") < 3 ) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Quote is too short. </div>
<?php
}
elseif(mb_strlen(utf8_decode($quoteinput), "UTF-8") > 100 ) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Quote is too long, maxium 100 characters.</div>
<?php
}
else {
$quotetest1 = True;
// Test #2 - Makes sure it does not have any restricted characters
if(!preg_match("~^[\p{L}\p{N},() _@.?!:;-]+$~u", utf8_decode($quoteinput))) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Quote contains restricted characters. </div>
<?php
}
elseif(preg_match('~(\S)(?:\1){10,}~mui', utf8_decode($quoteinput))) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Quote is not valid. </div>
<?php
}
else {
$quotetest2 = True;
// Final Check
if (($quotetest1) and ($quotetest2)) {
$quotefinalcheck = True;
$quoteinput = utf8_encode(htmlspecialchars(trim($_POST["quote"]), ENT_QUOTES));
}
else {
$quotefinalcheck = False;
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> There is a error. </div>
<?php
}
}
}
}
}
?>
</div>
</div>
</div>
<div class="col-xs-12">
<button id="profileinformationbutton" input type="submit" value="Login"> Update Profile </button>
</div>
<div class="col-xs-12">
<a href="http://localhost/postin'/profiles/<?php print utf8_decode($loggedin_session_permalink); ?>">
<div id="informationcancelbutton" input type="submit" value="Cancel"> Cancel </div>
</a>
</div>
</form>
<?php
if ($quotefinalcheck) {
$quote_for_database = "";
if (isset($quoteinput)) {
$quote_for_database = $quoteinput;
}
else {
$quote_for_database = "";
}
$inputquery = "UPDATE users SET quote = :quote, WHERE id = :id";
$datasend = $connection->prepare($inputquery);
$datasend->execute(array(':quote'=>utf8_decode($quote_for_database),
':id'=>$_SESSION["logged_in"]));
}
?>
我认为主要问题只是我这样做的顺序。如果你想要完整的代码(请注意,有些部分是针对不同的东西):
<?php
require("C:\wamp\www\postin'\db_connection.php");
//Grabs the URL
$urlname = explode("/",$_SERVER['REQUEST_URI']);
$urlquery = "SELECT username FROM users WHERE permalink = :permalink";
$urlparams = array(':permalink' => $urlname[4]);
try{
$urlstmt = $connection->prepare($urlquery);
$urlresult = $urlstmt->execute($urlparams);
}
catch(PDOException $ex){
echo ("Failed to run query: " . $ex->getMessage());
}
$urlcolumns = $urlstmt->fetch();
$accounturl = $urlcolumns["username"];
if(!$urlcolumns){
header("Location: http://localhost/postin'/home.php");
exit();
}
else {
?>
<!DOCTYPE html>
<html>
<head>
<?php include("C:\wamp\www\postin'\includes\head.php");?>
<title> POSTIN' Profile <?php echo $accounturl; ?> </title>
<link type="text/css" rel="stylesheet" href="http://localhost/postin'/css/style.profile.php.css"/>
<link type="text/css" rel="stylesheet" href="http://localhost/postin'/css/style.editprofile.php.css"/>
</head>
<body>
<div id="wrapper" class="container">
<?php
//Stars the sessions
session_start();
//Makes sure the user is trying to edit there profile
if (!isset($_SESSION["logged_in"])) {
header("Location: http://localhost/postin'/home.php");
exit();
}
$sessionquery = "SELECT username FROM users WHERE id = :id";
$sessionparams = array(':id' => $_SESSION["logged_in"]);
try{
$sessionstmt = $connection->prepare($sessionquery);
$sessionresult = $sessionstmt->execute($sessionparams);
}
catch(PDOException $ex){
echo ("Failed to run query: " . $ex->getMessage());
}
$sessionfetch = $sessionstmt->fetch();
$loggedin_session_username = $sessionfetch["username"];
if($accounturl != $loggedin_session_username){
header("Location: http://localhost/postin'/home.php");
exit();
}
else {
//Adds the header and sidebar
include("C:\wamp\www\postin'\includes\header.php");
include("C:\wamp\www\postin'\includes\sidebar.php");
//Sets the "last_url" to this page
if (!isset($_SESSION["last_url"])) {
$_SESSION["last_url"] = "http://localhost/postin'/home.php";
}
$last_url = $_SESSION["last_url"];
//Grabs all of the profile information
$accountinfoquery = "SELECT * FROM users WHERE username = :username";
$accountinfoparams = array(':username' => $accounturl);
try{
$accountinfostmt = $connection->prepare($accountinfoquery);
$accountinforesult = $accountinfostmt->execute($accountinfoparams);
}
catch(PDOException $ex){
echo ("Failed to run query: " . $ex->getMessage());
}
$accountinfocolumns = $accountinfostmt->fetch();
$firstnameinput = utf8_encode_string("firstname");
$lastnameinput = utf8_encode_string("lastname");
$ageinput = utf8_encode_string("age");
$locationinput = utf8_encode_string("location");
$quoteinput = utf8_encode_string("quote");
$genderinput = utf8_encode_string("gender");
$aboutinput = utf8_encode_string("about");
if (!$firstnameinput) {
$firstnameinput = utf8_encode(htmlspecialchars(trim($accountinfocolumns["firstname"]), ENT_QUOTES));
}
if (!$lastnameinput) {
$lastnameinput = utf8_encode(htmlspecialchars(trim($accountinfocolumns["lastname"]), ENT_QUOTES));
}
if (!$ageinput) {
if ($accountinfocolumns["age"] == "0") {
$ageinput = "";
}
else {
$ageinput = utf8_encode(htmlspecialchars(trim($accountinfocolumns["age"]), ENT_QUOTES));
}
}
if (!$locationinput) {
$locationinput = utf8_encode(htmlspecialchars(trim($accountinfocolumns["location"]), ENT_QUOTES));
}
if (!$quoteinput) {
$quoteinput = utf8_encode(htmlspecialchars(trim($accountinfocolumns["quote"]), ENT_QUOTES));
}
if (!$genderinput) {
$genderinput = utf8_encode(htmlspecialchars(trim($accountinfocolumns["gender"]), ENT_QUOTES));
}
if (!$aboutinput) {
$aboutinput = utf8_encode(htmlspecialchars(trim($accountinfocolumns["about"]), ENT_QUOTES));
}
//Final Check
$firstnamefinalcheck = False;
$lastnamefinalcheck = False;
$agefinalcheck = False;
$locationfinalcheck = False;
$quotefinalcheck = False;
$aboutfinalcheck = False;
?>
<div id="mobilephonescrollplace">
Hold Here To Slide Screen
</div>
<div class="maincontentssection">
<!-- ========================================================================================================================== -->
<!-- WHERE THE USER CHANGES HIS PROFILE INFORMATION -->
<!-- ========================================================================================================================== -->
<div id="accountinformationholder" class="row">
<div id="picturequoteholder" class="col-xs-12 col-sm-12 col-md-12 col-lg-3">
<div class="row">
<div id="accountpictureholder" class="col-xs-12 col-sm-6 col-md-6 col-lg-12 margintopimageeditpage">
<div id="accountpictureview">
<img src="http://localhost/postin'/images/logo.png" id="accountpictureholderspecs">
</div>
</div>
<div id="changepictureholder" class="col-xs-12 col-sm-6 col-md-6 col-lg-12">
<div id="changepicture">
Change Picture
</div>
</div>
</div>
</div>
<div id="editinformationholder" class="col-xs-12 col-sm-12 col-md-12 col-lg-8">
<form action="http://localhost/postin'/profiles/edit/<?php print utf8_decode($loggedin_session_permalink); ?>" method="post">
<div class="row">
<div class="row">
<div id="importantinformation" class="col-xs-12">
(*) means field is required.
</div>
</div>
<div class="col-xs-12 col-sm-8">
<div class="row">
<div id="informationtitlesmall" class="col-xs-12 col-sm-5">
* First Name
</div>
<div id="informationfirstname" class="col-xs-12 col-sm-7">
<input type="text" name="firstname" id="firstnameinput" value="<?php print mb_ucfirst($firstnameinput); ?>" />
</div>
<?php
if ($_POST) {
$firstnametest1 = False;
$firstnametest2 = False;
// Test #1 - Makes sure it fits the length requirements
if(mb_strlen(utf8_decode($firstnameinput), "UTF-8") < 3 ) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> First name is not valid. </div>
<?php
}
elseif(mb_strlen(utf8_decode($firstnameinput), "UTF-8") > 25 ) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> First name is not valid. </div>
<?php
}
else {
$firstnametest1 = True;
// Test #2 - Makes sure it does not have any restricted characters
if(!preg_match("~^[\p{L}\p{N}]+$~u", utf8_decode($firstnameinput))) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> First name contains restricted characters. </div>
<?php
}
elseif(preg_match('~(\S)(?:\1){10,}~mui', utf8_decode($firstnameinput))) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> First name is not valid. </div>
<?php
}
else {
$firstnametest2 = True;
// Final Check
if (($firstnametest1) and ($firstnametest2)) {
$firstnamefinalcheck = True;
}
else {
$firstnamefinalcheck = False;
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> There is a error. </div>
<?php
}
}
}
}
?>
</div>
<div class="row">
<div id="informationtitlesmall" class="col-xs-12 col-sm-5">
* Last Name
</div>
<div id="informationlastname" class="col-xs-12 col-sm-7">
<input type="text" name="lastname" id="lastnameinput" value="<?php print mb_ucfirst($lastnameinput); ?>" />
</div>
<?php
if ($_POST) {
$lastnametest1 = False;
$lastnametest2 = False;
// Test #1 - Makes sure it fits the length requirements
if(mb_strlen(utf8_decode($lastnameinput), "UTF-8") < 3 ) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Last name is not valid. </div>
<?php
}
elseif(mb_strlen(utf8_decode($lastnameinput), "UTF-8") > 35 ) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Last name is not valid. </div>
<?php
}
else {
$lastnametest1 = True;
// Test #2 - Makes sure it does not have any restricted characters
if(!preg_match("~^[\p{L}\p{N}-]+$~u", utf8_decode($lastnameinput))) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Last name contains restricted characters. </div>
<?php
}
elseif(preg_match('~(\S)(?:\1){10,}~mui', utf8_decode($lastnameinput))) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Last name is not valid. </div>
<?php
}
else {
$lastnametest2 = True;
// Final Check
if (($lastnametest1) and ($lastnametest2)) {
$lastnamefinalcheck = True;
}
else {
$lastnamefinalcheck = False;
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> There is a error. </div>
<?php
}
}
}
}
?>
</div>
<div class="row">
<div id="informationtitlesmall" class="col-xs-12 col-sm-5">
Age
</div>
<div id="informationage" class="col-xs-12 col-sm-7">
<input type="text" name="age" id="ageinput" value="<?php print utf8_decode($ageinput); ?>" />
</div>
<?php
if ($_POST) {
$agetest1 = False;
$agetest2 = False;
if (utf8_decode(trim($_POST["age"])) == "") {
$agefinalcheck = True;
$ageinput = "";
}
else {
// Test #1 - Makes sure it fits the length requirements
if(mb_strlen(utf8_decode($ageinput), "UTF-8") > 3 ) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Age is not valid. </div>
<?php
}
elseif(utf8_decode($ageinput) > 125 ) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Age is not valid. </div>
<?php
}
elseif(utf8_decode($ageinput) < 14 ) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> You are too young. </div>
<?php
}
else {
$agetest1 = True;
// Test #2 - Makes sure it does not have any restricted characters
if(!preg_match("~^[0-9]+$~", utf8_decode($ageinput))) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Age is not valid. </div>
<?php
}
else {
$agetest2 = True;
// Final Check
if (($agetest1) and ($agetest2)) {
$agefinalcheck = True;
$ageinput = $_POST["age"];
}
else {
$agefinalcheck = False;
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> There is a error. </div>
<?php
}
}
}
}
}
?>
</div>
<div class="row">
<div id="informationtitlesmall" class="col-xs-12 col-sm-5">
Location
</div>
<div id="informationlocation" class="col-xs-12 col-sm-7">
<input type="text" name="location" id="locationinput" value="<?php print utf8_decode($locationinput); ?>" />
</div>
<?php
if ($_POST) {
$locationtest1 = False;
$locationtest2 = False;
if (utf8_decode(trim($_POST["location"])) == "") {
$locationfinalcheck = True;
$locationinput = "";
}
else {
// Test #1 - Makes sure it fits the length requirements
if(mb_strlen(utf8_decode($locationinput), "UTF-8") < 3 ) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Location is not valid. </div>
<?php
}
elseif(mb_strlen(utf8_decode($locationinput), "UTF-8") > 60 ) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Location is not valid. </div>
<?php
}
else {
$locationtest1 = True;
// Test #2 - Makes sure it does not have any restricted characters
if(!preg_match("~^[\p{L}\p{N},() .-]+$~u", utf8_decode($locationinput))) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Location contains restricted characters. </div>
<?php
}
elseif(preg_match('~(\S)(?:\1){10,}~mui', utf8_decode($locationinput))) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Location is not valid. </div>
<?php
}
else {
$locationtest2 = True;
// Final Check
if (($locationtest1) and ($locationtest2)) {
$locationfinalcheck = True;
$locationinput = utf8_encode(htmlspecialchars(trim($_POST["location"]), ENT_QUOTES));
}
else {
$locationfinalcheck = False;
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> There is a error. </div>
<?php
}
}
}
}
}
?>
</div>
</div>
<div class="col-xs-12 col-sm-3">
<div id="informationtiptext">
<strong>Remember:</strong> Anyone can see your profile, do not share information you do not want others to know!
</div>
</div>
</div>
<div class="row" id="informationquoteholder">
<div id="informationtitlesmall" class="col-xs-12 col-sm-3">
Quote
</div>
<div id="quoteinputwidth" class="col-xs-12 col-sm-5 col-md-8">
<input type="text" name="quote" id="quoteinput" value="<?php print utf8_decode($quoteinput); ?>" />
</div>
<?php
if ($_POST) {
$quotetest1 = False;
$quotetest2 = False;
if (utf8_decode(trim($_POST["quote"])) == "") {
$quotefinalcheck = True;
$quoteinput = "";
}
else {
// Test #1 - Makes sure it fits the length requirements
if(mb_strlen(utf8_decode($quoteinput), "UTF-8") < 3 ) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Quote is too short. </div>
<?php
}
elseif(mb_strlen(utf8_decode($quoteinput), "UTF-8") > 100 ) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Quote is too long, maxium 100 characters.</div>
<?php
}
else {
$quotetest1 = True;
// Test #2 - Makes sure it does not have any restricted characters
if(!preg_match("~^[\p{L}\p{N},() _@.?!:;-]+$~u", utf8_decode($quoteinput))) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Quote contains restricted characters. </div>
<?php
}
elseif(preg_match('~(\S)(?:\1){10,}~mui', utf8_decode($quoteinput))) {
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> Quote is not valid. </div>
<?php
}
else {
$quotetest2 = True;
// Final Check
if (($quotetest1) and ($quotetest2)) {
$quotefinalcheck = True;
$quoteinput = utf8_encode(htmlspecialchars(trim($_POST["quote"]), ENT_QUOTES));
}
else {
$quotefinalcheck = False;
?>
<div id="allinputboxerror" class="col-xs-12 col-sm-offset-5 col-sm-7"> There is a error. </div>
<?php
}
}
}
}
}
?>
</div>
<div class="row" id="informationgenderholder">
<div id="informationtitlesmall" class="col-xs-12 col-sm-3">
Gender
</div>
<div class="col-xs-12 col-sm-8" id="radioholder" >
<input type="radio" name="gender" value="Male" id="selectormale" class="col-xs-12 col-sm-4"> <!-- Gender Selector -->
<label for="selectormale"> Male </label>
<input type="radio" name="gender" value="Female" id="selectorfemale" class="col-xs-12 col-sm-4">
<label for="selectorfemale"> Female </label>
<input type="radio" name="gender" value="Other" id="selectorother" class="col-xs-12 col-sm-4">
<label for="selectorother"> Other </label>
</div>
</div>
<div class="row" id="aboutinformationeditboxholder">
<div id="informationtitlesmallabout" class="col-xs-12 col-sm-3">
About
</div>
<div class="col-xs-12 col-sm-8" id="aboutinformationeditbox">
<textarea id="aboutinformationboxstyle" rows="1" cols="15" name="about" maxlength="10000"><?php print utf8_decode($aboutinput); ?></textarea>
<div id="aboutcharactercount"> <span id="textareacharactercount">0</span> / 2500 </div>
<script>
function wordCount(val){
return {characters : val.length,};
}
var print = document.getElementById("textareacharactercount");
var grab = document.getElementById("aboutinformationboxstyle");
grab.addEventListener("input", function(){
var wordcountprint = wordCount( this.value );
print.innerHTML = (wordcountprint.characters);
}, false);
</script>
<?php
if ($_POST) {
$abouttest1 = False;
$abouttest2 = False;
if (utf8_decode(trim($_POST["about"])) == "") {
$aboutfinalcheck = True;
$aboutinput = "";
}
else {
// Test #1 - Makes sure it fits the length requirements
if(mb_strlen(utf8_decode($aboutinput), "UTF-8") < 3 ) {
?>
<div id="allinputboxerroraboutbox" class="col-xs-12 col-sm-7"> About section is too short. </div>
<?php
}
elseif(mb_strlen(utf8_decode($aboutinput), "UTF-8") > 2500 ) {
?>
<div id="allinputboxerroraboutbox" class="col-xs-12 col-sm-7"> About section is too long. </div>
<?php
}
else {
$abouttest1 = True;
// Test #2 - Makes sure it does not have any restricted characters
if(!preg_match("~^[\p{L}\p{N},() _@.?!:;\r\n-]+$~u", utf8_decode($aboutinput))) {
?>
<div id="allinputboxerroraboutbox" class="col-xs-12 col-sm-7"> About section contains restricted characters. </div>
<?php
}
elseif(preg_match('~(\S)(?:\1){50,}~mui', utf8_decode($aboutinput))) {
?>
<div id="allinputboxerroraboutbox" class="col-xs-12 col-sm-7"> About section is not valid. </div>
<?php
}
else {
$abouttest2 = True;
// Final Check
if (($abouttest1) and ($abouttest2)) {
$aboutfinalcheck = True;
$aboutinput = utf8_encode(htmlspecialchars(trim($_POST["about"]), ENT_QUOTES));
}
else {
$aboutfinalcheck = False;
?>
<div id="allinputboxerroraboutbox" class="col-xs-12 col-sm-7"> There is a error. </div>
<?php
}
}
}
}
}
?>
</div>
</div>
<div class="col-xs-12">
<button id="profileinformationbutton" input type="submit" value="Login"> Update Profile </button>
</div>
<div class="col-xs-12">
<a href="http://localhost/postin'/profiles/<?php print utf8_decode($loggedin_session_permalink); ?>">
<div id="informationcancelbutton" input type="submit" value="Cancel"> Cancel </div>
</a>
</div>
</form>
</div>
</div>
<!-- ========================================================================================================================== -->
<!-- AN AD -->
<!-- ========================================================================================================================== -->
<!-- BELOW WILL BE EXECUTED IF THE USER HAS ALLOWED ADS IN THERE PREFERENCES -->
<!-- DISPLAYS THE ADS -->
<?php
if (isset($_SESSION["logged_in"])) {
if ($loggedin_session_allowads == "false") {
}
else {
?>
<div class="row">
<?php include("C:\wamp\www\postin'\includes\ads\adleaderboard1.php");?>
</div>
<?php
}
}
else {
?>
<div class="row">
<?php include("C:\wamp\www\postin'\includes\ads\adleaderboard1.php");?>
</div>
<?php
}
?>
<!-- ========================================================================================================================== -->
<!-- UPDATES THE DATABASE -->
<!-- ========================================================================================================================== -->
<?php
if (($firstnamefinalcheck) and ($lastnamefinalcheck) and ($agefinalcheck) and ($locationfinalcheck) and ($quotefinalcheck)) {
$age_for_database = "";
if (isset($ageinput)) {
$age_for_database = $ageinput;
}
else {
$age_for_database = "";
}
$location_for_database = "";
if (isset($locationinput)) {
$location_for_database = $locationinput;
}
else {
$location_for_database = "";
}
$quote_for_database = "";
if (isset($quoteinput)) {
$quote_for_database = $quoteinput;
}
else {
$quote_for_database = "";
}
$about_for_database = "";
if (isset($aboutinput)) {
$about_for_database = $aboutinput;
}
else {
$about_for_database = "";
}
$inputquery = "UPDATE users SET firstname = :firstname, lastname = :lastname, age = :age, location = :location, quote = :quote, gender = :gender, about = :about WHERE id = :id";
$datasend = $connection->prepare($inputquery);
$datasend->execute(array(':firstname'=>mb_ucfirst($firstnameinput),
':lastname'=>mb_ucfirst($lastnameinput),
':age'=>utf8_decode($age_for_database),
':location'=>utf8_decode($location_for_database),
':quote'=>utf8_decode($quote_for_database),
':gender'=>$genderinput,
':about'=>utf8_decode($about_for_database),
':id'=>$_SESSION["logged_in"]));
}
?>
</div>
<?php include("C:\wamp\www\postin'\includes\bottom.php");?>
</div>
</body>
</html>
<?php }} ?>
答案 0 :(得分:1)
请参阅第3块中的代码。我发现参数id
尚未绑定。
所以,在执行之前绑定参数,如果它可以帮助你:
$datasend->bindParam(':id', $id);
$datasend->execute();
<?php
....................
$inputquery = "UPDATE users SET quote = :quote, WHERE id = :id";
$datasend = $connection->prepare($inputquery);
$datasend->bindParam(':id', $id);
$datasend->execute();
....................
?>
编辑&amp; UPDATE:强>
将session_start放在上面,如:
<?php
//Stars the sessions
session_start();
//Makes sure the user is trying to edit there profile
if (!isset($_SESSION["logged_in"])) {
header("Location: http://localhost/postin'/home.php");
exit();
}
......................
-.end-
?>
<html>
.............
-.end-
答案 1 :(得分:1)
很难确定你当前的问题,因为你发布了很多代码。所以,我会添加另一件事来解决,以防万一。
不要这样做:
include("C:\wamp\www\postin'\includes\header.php");
首先,在大多数情况下,括号是不必要的(除非你需要一个返回值,而你不在这里),所以它现在变为:
include "C:\wamp\www\postin'\includes\header.php";
现在,最好不要硬连接完整的目录路径,所以再次将其更改为类似的东西(如果你做了几个,只需要一个$root
):
$root = __DIR__;
include $root . "\postin'\includes\header.php";
此外,虽然这可以在Windows上运行,但您可能遇到具有特殊含义的转义字符的问题,例如: “\ n”换行)。所以,使用正斜杠,这也很适合在Windows,OS X和Linux上使用它。 PHP将进行必要的反斜杠转换:
$root = __DIR__;
include $root . "/postin'/includes/header.php";
我会说postin'
撇号也要求麻烦(尽管它可能不是你眼前问题的原因)。如果你真的需要那种非标准的URL字符,我会使用URL重写。