Jump to content

Jonline

Members
  • Posts

    9
  • Joined

  • Last visited

Jonline's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I can't edit anymore, but basically: OK scrap what I said, I had a proper look at your code. What you are doing is submitting the form, and sending it to topic_proposal_theme.php. At the top of this PHP page, you are including topic_proposal_theme.shtml, which means anything you echo out after this included file will be done so after the contents of the file. In other words, your current set-up will always echo out after the closing HTML tag. What you could do is this: topic_proposal_theme.shtml: <?php include_once('topic_proposal_theme.php'); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Meeting Topic Proposal - Theme</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.js"></script> <script> $(document).ready(function(){ $("#topic_proposal_theme").validate({ // jQuery code - omitted }); }); </script> <style type="text/css"> label.error { float: none; color: red; background-color: yellow; padding-left: .5em; vertical-align: top; font-weight:bold} </style> <link rel="stylesheet" type="text/css" href="css/main.css" media="screen"/> <link rel="stylesheet" type="text/css" href="css/print.css" media="print"/> </head> <body> <h1>Meeting Topic Proposal - Theme</h1> <?php if (isset($_POST['submitForm'])) { validateForm(pass through relevant arguments); } ?> <form id="topic_proposal_theme" method="post" action="topic_proposal_theme.shtml"> // note change of action[/font][/size] [size=3][font=verdana,geneva,sans-serif]<p>Use this form to make a suggestion for a future meeting topic. Complete the form and press the Submit button. To clear the form without submitting it, press the Reset button.</p> <div id="errorbox"><ul></ul></div> <p>Topic proposal submitted by (e.g. Doug B.): <input type="text" name="proposer" id="cproposer" size="30" maxlength="30"/></p> <fieldset><legend>Proposed Topic</legend> <p>Title (e.g. The future of Genetic Engineering): <input type="text" name="title" id="ctitle" size="50" maxlength="50"/></p> </fieldset> <p></p> <p>What will we discuss? (e.g. How human beings will change physically and emotionally if genetic engineering proceeds.)</p> <p><textarea name="discuss" id="cdiscuss" rows="10" cols="50"></textarea></p> <p>What, if anything, do we have to do to prepare for the meeting? (e.g. Read a Wikipedia article on genetic engineering and any novel in which genetic engineering is a key plot element.)</p> <p><textarea name="prepare" id="cprepare" rows="10" cols="50"></textarea></p> <p><input type="checkbox" name="related" id="crelated" value="Related">There is a related topic that should be presented at the same meeting.</p> <p>Additional Comments (e.g. It would be helpful if you could prepare a list of genetic enhancements that you would like to have.):</p> <p><textarea name="comments" id="ccomments" rows="10" cols="50"></textarea></p> <p> <input type="hidden" name="_submit_check" value="1"/> <input name="submitForm" id="submitForm" type="submit" value="Submit"/> <input name="reset" id="reset" type="reset" value="Reset"/> </p> </form> <p><!--valid XHTML 1.0 Strict code--><a href="http://validator.w3.org/check/referer"> topic_proposal_theme.php <?php $debug = 0; $Defaults = array(); $Errors = array(); //////////////////////////////////////////////// include('topic_proposal_theme.shtml'); -------------- get rid of this line -------------------- if ($debug) { echo 'Current php version: ' . phpversion() . '<br/>'; //Gives 5.3.19 on absolut server on 2013-01-18 echo 'Request method: ' . $_SERVER['REQUEST_METHOD'] . '<br/>'; //determine request method } if ($debug) {echo "Count: " . count($_POST) . "<br/>";} /* If any of the form elements were completed, validate them. If all elements were valid, insert a record * to the database. */[/font][/size] function validateForm(pass through relevant arguments) { if (count($_POST) > 0) { $Defaults = $_POST; $proposer = $_POST['proposer']; $title = $_POST['title']; $discuss = $_POST['discuss']; $prepare = $_POST['prepare']; $related = $_POST['related']; $comments = $_POST['comments']; if ($debug) { echo "Proposer: $proposer<br/>"; echo "Title: $title<br/>"; echo "Discuss: $discuss<br/>"; echo "Prepare: $prepare<br/>"; echo "Related: $related<br/>"; echo "Comments: $comments<br/>"; } /* Verify that all mandatory fields contain data. */ if (empty($proposer) || strlen(trim($proposer))==0) { $Errors[] = 'The name of the person proposing the topic is a required field. Example: Bob T.'; } if (empty($title) || strlen(trim($title))==0) { $Errors[] = 'The title is a required field. Example: The future of genetic engineering'; } if (empty($discuss) || strlen(trim($discuss))==0) { $Errors[] = 'The discussion is a required field. Example: Consider how human beings will change physically and emotionally if trends continue.'; } if (empty($prepare) || strlen(trim($prepare))==0) { $Errors[] = 'The preparation is a required field. Example: Read a Wikipedia article and Holy Fire by Bruce Sterling.'; } //Ensure that the description of what is to be discussed does not exceed the maximum. $max_discuss_length = 500; if (strlen(trim($discuss))>500) { $Errors[] = 'The discussion cannot exceed $max_discuss_length characters. Please shorten your input.'; } //Ensure that the description of the preparation does not exceed the maximum. $max_prepare_length = 500; if (strlen(trim($prepare))>500) { $Errors[] = 'The preparation cannot exceed $max_prepare_length characters. Please shorten your input.'; } /* Cross checks */ //None if (count($Errors)==0){ echo "<h3>Your data has all been validated successfully. Attempting to insert into database...</h3>"; //If the related checkbox is unchecked, pass a value of No to the database. Otherwise, pass Yes to the database. $related = ($related=="") ? "No" : "Yes"; Insert_Proposal($proposer, $title, $discuss, $prepare, $related, $comments); } else { echo "<h4>The form contains errors as noted below. Please fix them and then press the Submit button again.</h4>"; foreach ($Errors as $oneError) { echo "<p class='red'>" . $oneError . "</p>"; } } } } function Insert_Proposal($proposer, $title, $discuss, $prepare, $related, $comments) { $debug = 0; //temporary include('#pdo-signin-insert.shtml'); //Sign in, connect and select database $date_proposed = date('Y-m-d'); //The date is generated here, not obtained from the form. if ($debug) { echo "Date proposed: $date_proposed<br/>"; echo "Proposer: $proposer<br/>"; echo "Title: $title<br/>"; echo "Discuss: $discuss<br/>"; echo "Prepare: $prepare<br/>"; echo "Related: $related<br/>"; echo "Comments: $comments<br/>"; } try { $stmt = $db->prepare("INSERT INTO TopicProposals_Themes(Date_Proposed, Proposer, Title, Discuss, Prepare, Related, Comments) VALUES (:date_proposed, :proposer, :title, :discuss, :prepare, :related, :comments)"); $stmt->execute(array(':date_proposed' => $date_proposed, ':proposer' => $proposer, ':title' => $title, ':discuss' => $discuss, ':prepare' => $prepare, ':related' => $related, ':comments' => $comments)); $affected_rows = $stmt->rowCount(); } catch (PDOException $excp) { echo "Error during insert into TopicProposals_Themes. Message: " . $excp->getMessage(); exit(1); } include('topic_proposal_accepted.shtml'); } ?> thank-you page (though instead of making this a page it is probably easier to just echo this at the end of your PHP script): <h1>Thank you!</h1> <p>Your proposed topic has been added to the database. It will be considered at the next planning session. Planning sessions are typically held during the regular June and December meetings.</p> <p>You can <a href="choosing_topics.shtml">make another suggestion</a> or <a href="index.shtml">return to the home page</a>.</p> If you want to set the page title based upon the page, then you may do the following in topic_proposal_theme.shtml: // Very top of document <?php include_once('topic_proposal_theme.php'); $title = "Meeting Topic Proposal - Theme"; ?> <!DOCTYPE html> <html> ... and within the thank you page: <?php $title = "Thank You!";?> <h1>Thank you!</h1> <p>Your proposed topic has been added to the database. It will be considered at the next planning session. Planning sessions are typically held during the regular June and December meetings.</p> <p>You can <a href="choosing_topics.shtml">make another suggestion</a> or <a href="index.shtml">return to the home page</a>.</p> As you are including the file, it will set the value of $title to be "Thank You!" and thus update your page title accordingly. -- I've given up trying to remove any and codes, they keep reappearing when trying to delete them!
  2. topic_proposal_theme.shtml is fine topic_proposal_theme.php is fine The thank-you file, try (like I said before, it's the only logical problem area, though it may not be the problem) removing the <html>, <head> and <body> tags, so that it is purely the following: <h1>Thank you!</h1> <p>Your proposed topic has been added to the database. It will be considered at the next planning session. Planning sessions are typically held during the regular June and December meetings.</p> <p>You can <a href="choosing_topics.shtml">make another suggestion</a> or <a href="index.shtml">return to the home page</a>.</p> If you want to set the page title, then you may do the following in topic_proposal_theme.shtml: <?php $title = "Meeting Topic Proposal - Theme";?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title><?php echo $title;?></title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> ... and within the thank you page: <?php $title = "Thank You!";?> <h1>Thank you!</h1> <p>Your proposed topic has been added to the database. It will be considered at the next planning session. Planning sessions are typically held during the regular June and December meetings.</p> <p>You can <a href="choosing_topics.shtml">make another suggestion</a> or <a href="index.shtml">return to the home page</a>.</p> As you are including the file, it will set the value of $title to be "Thank You!" and thus update your page title accordingly.
  3. Not sure how lines 9 and 11 will work - you aren't actually querying the table at any time. As a side note, you should refrain from using SELECT * - it's bad practice and, as you're only counting the number of rows, it makes more sense to return only one value to reduce the overhead.
  4. You should understand the basics of HTML before learning PHP. You're intertwining an unordered list and table row...
  5. Well as you are restating the <html> tags, you will be defining what is effectively a new page. Think of it like a class, you may have many in one namespace, but each is seperate. Given that you are executing the code before the final </html> tag, this is the only logical reason. I wouldn't get too worked up over the W3C validation checks, type in Google or Facebook and you'll see 100s of errors. Out of interest, as you are including the file then I would suggest it need not.
  6. Have you a link to a working live website? And my guess would be that you are including a file into another file that has already defined the <html>, <head> and so forth tags. Have you tried setting the thank you file to just: <h1>Thank you!</h1> <p>Your proposed topic has been added to the database. It will be considered at the next planning session. Planning sessions are typically held during the regular June and December meetings.</p> <p>You can <a href="choosing_topics.shtml">make another suggestion</a> or <a href="index.shtml">return to the home page</a>.</p> You can change the title by, in the main file, setting it to: <title><?php echo $title;?></title> and then setting the value of $title accordingly.
  7. I know you posted as I posted my edit, but yes, the issue layed within the fact it was creating two session IDs, one with the www. and one without. Thanks for the response though!
  8. Can't edit the main post, sorry. I've found the ultimate cause: When the redirect is called, it sends the user to the details.php page. However, this page contains the following snippet of code: if (!isset($_SESSION['login'])) { header("Location: http://www.jonline.me.uk/fbedder/index.php"); } Obviously what is happening, is that the session is not being detected / saved / "whatevered", and as a result is sending the user back to the index page. Is there are a way to ensure the $_SESSION is not effectively lost. I had read about this before posting here, and is why I inserted session_write_close(), but that doesn't seem to be doing the desired effect. Any ideas? -- After diagnosing the problem being within the fact the $_SESSION variable was effectively being lost, I read up about the session_write_close() function and came across this comment: Source: http://pt2.php.net/m...close.php#84925 Setting the parameters resolved the issue.
  9. I've come across a problem within (at least) Google Chrome and Safari. Upon the first attempt at logging in, the user is not redirected. The session is created, but it is almost as if it is not detected, and takes the user back to the index page. Upon a second attempt, the correct redirect is issued and the user is taken to the correct page. The script works fine in Firefox, and I have checked extensively to see if the correct data is being returned, which it is. I've searched and I've searched and I've searched, but unfortunately nothing of use has cropped up. Access.php - User logging in <?php session_start(); ob_start(); include_once('db.class.php'); include_once('register.class.php'); include_once('login.class.php'); $db = null; $reg = null; $log = null; $db = new Database(); $log = new Login($db, null, null, null, null, null, null); if (isset($_SESSION['login'])) { $log->redirectUser($_SESSION['login']); } include_once('includes/header.html'); ?> Some HTML... <?php if (isset($_POST['logsub'])) { $db = new Database(); $log = new Login($db, $_POST['email'], $_POST['pass']); $validation = &$log->validate(); if(empty($validation)) { $log->redirectUser($_SESSION['login']); } else { echo "<div id='error'><div class='box-error'><p style='font-weight: bold'>The following errors occured...</p><ul>"; for ($i = 0; $i < count($validation); $i++) { echo "<li>" . $log->getErrorMessage($validation[$i]) . "</li>"; } echo "</ul></div></div>"; } } ?> Login.class.php - Login class // Validate the credentials given public function validateLogin() { // Hash the plain text password $this->hashedPass = $this->hashPassword(); try { $query = $this->dbcon->prepare("SELECT Login_ID, Login_Email, Login_Password FROM Login WHERE Login_Email = :email AND Login_Password = :pass"); $query->bindParam(':email', $this->email, PDO::PARAM_STR); $query->bindParam(':pass', $this->hashedPass, PDO::PARAM_STR); $query->execute(); $fetch = $query->fetch(PDO::FETCH_NUM); $this->loginid = $fetch[0]; // If a match is found, create a session storing the login_id for the user if ($query->rowCount() == 1) { $_SESSION['login'] = $this->loginid; session_write_close(); } else { return LOG_ERR_NO_MATCH; } } catch (PDOException $e) { $this->dbcon->rollback(); echo "Error: " . $e->getMessage(); } } // Fetch the customer ID private function getCustId() { try { $query = $this->dbcon->prepare("SELECT Customer.Cust_ID FROM Customer JOIN Login ON Customer.Login_ID = Login.Login_ID WHERE Customer.Login_ID = :loginid"); $query->bindParam(':loginid', $this->loginid, PDO::PARAM_INT); $query->execute(); $fetch = $query->fetch(PDO::FETCH_NUM); return $fetch[0]; } catch (PDOException $e) { $this->dbcon->rollback(); echo "Error: " . $e->getMessage(); } } // Check the registration progress - are they verified? paid? // This function is used elsewhere hence the $sessionid argument public function checkRegistration($sessionid) { $this->loginid = $sessionid; $this->custid = $this->getCustId(); try { $queryVer = $this->dbcon->prepare("SELECT Cust_ID FROM Customer_Verify_Email WHERE Cust_ID = :custid"); $queryVer->bindParam(":custid", $this->custid, PDO::PARAM_INT); $queryVer->execute(); $queryFee = $this->dbcon->prepare("SELECT Cust_ID FROM Initial_Fee_Payment WHERE Cust_ID = :custid"); $queryFee->bindParam(":custid", $this->custid, PDO::PARAM_INT); $queryFee->execute(); // If a record exists in the verify table, return the value 1. This means the user has not yet verified their email. if ($queryVer->rowCount() == 1) { return 1; } else { // If a record does not exist in the payment table, no payment has been made. Return 2. if ($queryFee->rowCount() == 0) { return 2; // Otherwise, email is verified and the payment has been made. } else { return 0; } } } catch (PDOException $e) { $this->dbcon->rollback(); echo "Error: " . $e->getMessage(); } } // Redirect the user accordingly public function redirectUser($sessionid) { $this->loginid = $sessionid; $logNum = $this->checkRegistration($this->loginid); if ($logNum == 0) { header("Location: http://www.jonline.me.uk/fbedder/details.php", true, 200); exit(); } else if ($logNum == 1) { header("Location: http://www.jonline.me.uk/fbedder/verification.php", true, 200); exit(); } else if ($logNum == 2) { header("Location: http://www.jonline.me.uk/fbedder/payment.php", true, 200); exit(); } } Here's a link to the site: http://www.jonline.me.uk/fbedder/ -> I have set-up a test account with the credentials -> email: test@jonline.me.uk / password: test123321 To reiterate, the problem exists only in Google Chrome and Safari (the Safari being on my iPhone) and lies purely within the logging in aspect. On the first attempt, the session will be ignored (it is created), and on the second attempt, the user will be redirected. Any ideas? I've tried a multitude of possibilities... Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.