Jump to content

emcy

Members
  • Posts

    24
  • Joined

  • Last visited

Everything posted by emcy

  1. emcy

    Responsive 5 columns?

    Hi, I have been searching on the w3 schools site for info on making a 5 column layout. I am guessing I have to make a two column and 3 column on the same row? Or is there another way to do it? Another thought I had was to make it 2 columns, 3 columns, 2 columns, 3 columns and 2 columns for the 12 column grid but that got really confusing. Can I just do w3-fifth instead of w3-quarter? Help please? Thanks B
  2. Dear ModeraterJustsomeguy, I would like to humbly request that the latter portion of this initial contact form page issue, about the mailinglist issue, be moved to a new topic. Would you please, kindly consider moving it over? I feel concerned about the two issues mixing in your search field, and the forum page getting tooooooo long and confusing for other info seekers. Thank you for taking the time and I hope you have a wonderful day (thanks tons for the help B
  3. HI, in the interest of this post about the contact form not being mixed up with my mailing list hover button/radio button issue.. how do I move my mailinglist topic question and your responses for it to another post? Thanks B
  4. emcy

    php NOT words?

    HI Thanks!.. ok Here is what I did.... This first part (blog.php) is for: 1. create the modal button on the page 2.when a user clicks on the button it opens up a modal asking for user ID and password 3.when the user enters his info and clicks submit.. it calls up the "include" file named blogpswdefineandcheck.php (see below blog.php) blog.php <!-- Button to open the modal login form --> <button onclick="document.getElementById('id01').style.display='block'">Login</button> <!-- The Modal --> <div id="id01" class="modal"> <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span> <!-- Modal Content --> <?php> ini_set('display_errors', 1); error_reporting(E_ALL); include('blogpswdefineandcheck.php'); function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <form class="modal-content animate" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="application/x-www-form-urlencoded">> <div class="imgcontainer"> <img src="../pagepieces/images/me.png" alt="Avatar" width="150" height="100" class="avatar"> </div> <div class="container"> <label for="uname"><b>Username</b></label> <input type="text" placeholder="Enter Username" name="uname" required> <label for="psw"><b>Password</b></label> <input type="password" placeholder="Enter Password" name="psw" required> <button type="submit" name="submit" value="Submit">Login</button> </div> <div class="container" style="background-color:#f1f1f1"> <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button> </div> </form> </div> <script> // Get the modal var modal = document.getElementById('id01'); // When the user clicks anywhere outside of the modal, close it window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } </script> 4. It checks the users input against the hardcoded username and password 5. If the user name and password match, then it shows a link for the blogentriespage.php blogpswdefineandcheck.php <?php define("uname", "me" . "psw", "mypsw"); function myTest($uname, $psw) { //this $uname and $psw will come from the user's input in the form if ($uname == me and $psw == mypsw) { echo "Hi Me! Welcome Back!"; echo '<a href="http://www.me.com/xmas/blongentriespage.php">Click here to access the blog entries page</a>'; } else { echo "Have a good night! You are NOT me!"; } } myTest(); ?> 7. The next part is for the bottom part of the blog.php page where it shows all the other entries by linked categories (i.e. Year, Month, Title) for the user to select a. first it connects to the database via an included (blogdbConfig.php) b. then it seeks the columns of year, month and title c. then it creates the links to those column's on the blog.php page (right in that section of the page), for the user to choose from d. when the user clicks on year, month or title.. it returns the list of all the entries in that column, in a pretty way on the screen in that same section area <?php //keep this in here to display all the errors on debugging ini_set('display_errors', 1); error_reporting(E_ALL); // SECTION A // define the connection info // got this info from 1and1.com directly include('blogdbConfig.php'); // Define the connection and then connect $connect = mysqli_connect($host_name, $user_name, $password, $database); // this is where the debugging portion ends // Check connection if ($connect->connect_error) { die("Connection failed: " . myseqli_connect_error()); } $mysqli = "SELECT id, date, title, content FROM myblog"; $result = $connect->query($mysqli); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "<br> id: ". $row["id"]. "Date: ". $row["date"]. "Title " . $row["Title"] . "<br>"; echo "Content: " . $row["content"] . "<br>"; } } else { echo "0 results"; } $connect->close(); ?> 8. On the blogentriespage.php I used my code from my contact page on this (also used my blogdbConfig.php)..... <?php //keep this in here to display all the errors on debugging ini_set('display_errors', 1); error_reporting(E_ALL); // SECTION A // define the connection info // got this info from 1and1.com directly include('blogdbConfig.php'); // Define the connection and then connect $connect = mysqli_connect($host_name, $user_name, $password, $database); // SECTION B // check the connection if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } // SECTION C //This tells the server what to do with the user's info when it gets to the SECTION D of this php page // test again and strip the user info of characters I don't want function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } // set all the fields on the new database record to empty initially to reset it from the previous user $dateErr = $titleErr = $contentErr = $signedbyErr = ""; $date = $title = $content = $signedby = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { // if connected to the server successfully and it requests info or is ready to receive the info.... $passed = true; // } else { $passed = false; } // then start working on the user's info to clean it up and make sure all the fields have been filled in if (empty($_POST["date"])) { $dateErr = "Please enter a date in the format of monthname date, full year"; $passed = false; } else { $date = test_input($_POST["date"]); } if (empty($_POST["title"])) { $titleErr = "Title is required"; $passed = false; } else { $title = test_input($_POST["title"]); if (!preg_match("/^[a-zA-Z ]*$/",$title)) { $passed = false; $titleErr = "Only letters and white space allowed"; } } if (empty($_POST["content"])) { $contentErr = "Content is required"; $passed = false; } else { $content = test_input($_POST["content"]); } if (empty($_POST["signedby"])) { $signedbyErr = "Signed by is required"; $passed = false; } else { $signedby = test_input($_POST["signedby"]); if (!preg_match("/^[a-zA-Z ]*$/",$signedby)) { $passed = false; $signedbyErr = "Only letters and white space allowed"; } } if ($passed) { //SECTION E // define what $mysqli is made up of (taken from the fields in the html form code above) $mysqli = "INSERT INTO blogentries (date, title, content, signedby) VALUES ('$date','$title','$content','$signedby')"; //SECTION F // Checking the connection and verifying the user's information/$mysqli (which was defined above) has been entered into the new record in the database, then it gives a success message if (mysqli_query($connect, $mysqli)) { echo "New record created successfully"; } else { echo "Error: " . $mysqli . "<br>" . mysqli_error($connect); } // SECTION G // define what $email, and $email Subject is made up of for when it sends an email to me to let me know someone just posted something. $email = "info@me.com"; $emailSubject = "A new blog entry was just received in the database"; // define what the headers of the email should say $headers = "From:$signedby\r\n"; $headers = "Content-type: text/html\r\n"; // define what the body of the email should say and look like $body = <<<EOD <br><hr><br> Date : $date <br> Title : $title <br> Content : $content <br> Signed By : $signedby <br> EOD; // SECTION H // define the action to take upon success of a new record having been created - i.e. mail it with the email info, email subject, body, and headers from the above definitions, to my email address $success = mail($email, $emailSubject, $body, $headers); // SECTION I // on this same user's page on his computer in the browser window, next, print on screen a copy of what the user entered above echo "<h2>Thank you your new blog entry was received successfully. Here is a copy of what you wrote:</h2>"; echo "Date: " . $date . "<br>"; echo "Title: " . $title . "<br>"; echo "Content: " . $content . "<br>"; echo "Signed By: " . $signedby . "<br>"; // SECTION J // when everything has been done, close the database connection $date = $title = $content = $signedby = ""; } } ?> <p><span class="error">* required field.</span></p> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="application/x-www-form-urlencoded"> Date:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Date" name="date" value="<?php echo $date; ?>"><span class="error">* <?php echo $dateErr; ?></span><br> Title:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Title" required name="title" value="<?php echo $title; ?>"><span class="error">* <?php echo $titleErr; ?></span><br> Content:<textarea placeholder="Content" required name="content" rows="30" cols="40" value="<?php echo $content; ?>"></textarea><span class="error">* <?php echo $contentErr; ?></span><br> Signed By:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Signed By" required name="signedby" value="<?php echo $signedby; ?>"><span class="error">* <?php echo $signedbyErr; ?></span><br> <input class="w3-input w3-padding-16 w3-border" type="datetime-local" required name="date" value="2017-11-16T20:00"> <!--- PLACEHOLDER Not allowed on this type ABOVE--> <br> <button class="w3-button w3-black"><input type="submit" name="submit" value="Submit"></button> </form> <?php mysqli_close($connect); ?> I think that's all I need?.. but it still sort of doesn't work.. ideas? What I now get is: 1. The pop up window /modal for entering a username and password comes up , and I enter my information but then when I click on submit, it disappears and does not open the blogentries page 2. I get this error message: Notice: Trying to get property of non-object in /homepages/42//htdocs/xmas/blog.php on line 2230 results Search the blog for particular dates and entries 3. There are no links above as you can see... only the title"Search the blog for particular dates and entries". hmm. ideas? Here is what line 223 is in blog.php <?php //keep this in here to display all the errors on debugging ini_set('display_errors', 1); error_reporting(E_ALL); // SECTION A // define the connection info // got this info from 1and1.com directly include('blogdbConfig.php'); // Define the connection and then connect $connect = mysqli_connect($host_name, $user_name, $password, $database); // this is where the debugging portion ends // Check connection if ($connect->connect_error) { die("Connection failed: " . myseqli_connect_error()); } $mysqli = "SELECT id, date, title, content FROM myblog"; $result = $connect->query($mysqli); //line 223 if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "<br> id: ". $row["id"]. "Date: ". $row["date"]. "Title " . $row["Title"] . "<br>"; echo "Content: " . $row["content"] . "<br>"; } } else { echo "0 results"; } $connect->close(); ?> <hr> <p>Search the blog for particular dates and entries</p> Thanks B
  5. emcy

    php NOT words?

    Hi, I am working on a simple login for just 1 person.. me .. to be able to update my blog online. I would like to have the login button on the blog page itself. I currently have it set up as a modal. I have the database setup for 4 columns - ID, date, title, content and signedby I have the form page set up as well (blog.php), and the database access dbconfig.php file is written also. 1. - wrote up the modal button so that when I click on the login/submit button it should call up pswchecking.php to verify that the username and password are me only, and that if it is true, then it will pop up the blog entry page which then enters the new entries into the database in mysqli. (how do I write pswchecking.php? - I looked at Mysqli code in w3schools, and php and ajax. I could maybe do it as a php/ajax file but then the text file can be found by a search on google, how do I hide it? So then I thought maybe to do a database with just one user in it.. me that felt like overkill.. not sure.. ideas? After that, I want to automatically be able to post the new blog entries from the database to the blog.php page automatically. I would also like it sorted by year and month links so they don't get all the records downloaded, and it only shows the latest post. To say the least, I would not be posting if it worked like a charm . It doesn't work and I get error messages... current code I have is as such: 1. blog.php page with a login modal button . <!-- Modal Content --> <?php //keep this in here to display all the errors on debugging ini_set('display_errors', 1); error_reporting(E_ALL); // SECTION A // define the connection info // got this info from 1and1.com directly include('blogdbConfig.php'); // where blogdbConfig.php is //<?php // got this info from 1and1.com directly //$host_name = "dbnumber.db.1and1.com"; // $user_name = "dbonumber"; // $password = "password"; // $database = "dbnumber"; // Create connection using the mysqli procedural format //$connect = mysqli_connect($host_name, $user_name, $password, $database); // Check connection // if (!$connect) { // die("Connection failed: " . mysqli_connect_error()); // } // ?> //***********NOW THAT IT'S CONNECTED TO THE DATABASE I WANT IT TO POP UP A PAGE CALLED blogentriespage.php SO I CAN MAKE A NEW DATABASE ENTRY. //DO I USE AN INCLUDE STATMENT HERE? SUCH AS THE FOLLOWING, AND HOW DO I PUT IT ON A POP-UP PAGE? //<?php //include('blogentriespage.php'); //?> // where blogentries.php is: // <?php //keep this in here to display all the errors on debugging // ini_set('display_errors', 1); // error_reporting(E_ALL); // include('blogdbConfig.php'); // $connect = mysqli_connect($host_name, $user_name, $password, $database); // if (!$connect) { // die("Connection failed: " . mysqli_connect_error()); // } // function test_input($data) { // $data = trim($data); // $data = stripslashes($data); // $data = htmlspecialchars($data); // return $data; // } // $dateErr = $titleErr = $contentErr = $signedbyErr = ""; // $date = $title = $content = $signedby = ""; // if ($_SERVER["REQUEST_METHOD"] == "POST") { // $passed = true; // if (empty($_POST["date"])) { // $dateErr = "Please enter a date in the format of monthname date, full year"; // $passed = false; // } else { // $date = test_input($_POST["date"]); // } // if (empty($_POST["title"])) { // $titleErr = "Title is required"; // $passed = false; // } else { // $title = test_input($_POST["title"]); // if (!preg_match("/^[a-zA-Z ]*$/",$title)) { // $passed = false; // $titleErr = "Only letters and white space allowed"; // } // } // if (empty($_POST["content"])) { // $contentErr = "Content is required"; // $passed = false; // } else { // $content = test_input($_POST["content"]); // } // if (empty($_POST["signedby"])) { // $signedbyErr = "Signed by is required"; // $passed = false; // } else { // $signedby = test_input($_POST["signedby"]); // if (!preg_match("/^[a-zA-Z ]*$/",$signedby)) { // $passed = false; // $signedbyErr = "Only letters and white space allowed"; // } // } // if ($passed) { // $mysqli = "INSERT INTO xmasblogentries (date, title, content, signedby) VALUES ('$date','$title','$content','$signedby')"; // if (mysqli_query($connect, $mysqli)) { // echo "New record created successfully"; // } else { // echo "Error: " . $mysqli . "<br>" . mysqli_error($connect); // } // $email = "info@me.com"; // $emailSubject = "A new blog entry was just received in the database"; // $headers = "From:$signedby\r\n"; // $headers = "Content-type: text/html\r\n"; // $body = <<<EOD // <br><hr><br> // Date : $date <br> // Title : $title <br> // Content : $content <br> // Signed By : $signedby <br> // EOD; // $success = mail($email, $emailSubject, $body, $headers); // echo "<h2>Thank you your new blog entry was received successfully. Here is a copy of what you wrote:</h2>"; // echo "Date: " . $date . "<br>"; // echo "Title: " . $title . "<br>"; // echo "Content: " . $content . "<br>"; // echo "Signed By: " . $signedby . "<br>"; // $date = $title = $content = $signedby = ""; // } // } // ?> // <p><span class="error">* required field.</span></p> // <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="application/x-www-form-urlencoded"> // Date:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Date" name="date" value="<?php echo $date; ?>"><span class="error">* <?php echo $dateErr; ?></span><br> // Title:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Title" required name="title" value="<?php echo $title; ?>"><span class="error">* <?php echo $titleErr; ?></span><br> // Content:<textarea placeholder="Content" required name="content" rows="30" cols="40" value="<?php echo $content; ?>"></textarea><span class="error">* <?php echo $contentErr; ?></span><br> // Signed By:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Signed By" required name="signedby" value="<?php echo $signedby; ?>"><span class="error">* <?php echo $signedbyErr; ?></span><br> // <input class="w3-input w3-padding-16 w3-border" type="datetime-local" required name="date" value="2017-11-16T20:00"> // <br> // <button class="w3-button w3-black"><input type="submit" name="submit" value="Submit"></button> // </form> // <?php // mysqli_close($connect); // ?> // </div> //SECTION C // Define the connection and then connect $connect = mysqli_connect($host_name, $user_name, $password, $database); // this is where the debugging portion ends // set all the fields on the new database record to empty initially to reset it from the previous entry // SECTION B // check the connection if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } // SECTION C //This tells the server what to do with the entry info when it gets to the SECTION D of this php page // test again and strip the user info of characters I don't want function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } // set all the fields on the new database record to empty initially to reset it from the previous user (do I need to autoincrement here somewhere? Maybe my database settings are wrong?) $dateErr = $titleErr = $contentErr = $signedbyErr = ""; $date = $title = $content = $signedby = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { // if connected to the server successfully and it requests info or is ready to receive the info.... $passed = true; // } else { $passed = false; } // then start working on the user's info to clean it up and make sure all the fields have been filled in if (empty($_POST["date"])) { $dateErr = "Please enter a date in the format of monthname date, full year"; $passed = false; } else { $date = test_input($_POST["date"]); } if (empty($_POST["title"])) { $titleErr = "Title is required"; $passed = false; } else { $title = test_input($_POST["title"]); if (!preg_match("/^[a-zA-Z ]*$/",$title)) { $passed = false; $titleErr = "Only letters and white space allowed"; } } if (empty($_POST["content"])) { $contentErr = "Content is required"; $passed = false; } else { $content = test_input($_POST["content"]); } if (empty($_POST["signedby"])) { $signedbyErr = "Signed by is required"; $passed = false; } else { $signedby = test_input($_POST["signedby"]); if (!preg_match("/^[a-zA-Z ]*$/",$signedby)) { $passed = false; $signedbyErr = "Only letters and white space allowed"; } } if ($passed) { //SECTION E // define what $mysqli is made up of (taken from the fields in the html form code above) $stmt = $mysqli->prepare("INSERT INTO xmasblogentries (date, title, content, signedby) VALUES (':date',':title',':content',':signedby')"); $stmt->bindParam(':date', $txtdate); $stmt->bindParam(':title', $txttitle); $stmt->bindParam(':content', $txtcontent); $stmt->bindParam(':signedby', $txtsignedby); $stmt->execute(); //SECTION F // Checking the connection and verifying the user's information/$mysqli (which was defined above) has been entered into the new record in the database, then it gives a success message if (mysqli_query($connect, $mysqli)) { echo "New record created successfully"; } else { echo "Error: " . $mysqli . "<br>" . mysqli_error($connect); } // SECTION G // define what $email, and $email Subject is made up of for when it sends an email to me to let me know someone just posted something. $email = "info@me.com"; $emailSubject = "A new blog entry was just received in the database"; // define what the headers of the email should say $headers = "From:$signedby\r\n"; $headers = "Content-type: text/html\r\n"; // define what the body of the email should say and look like $body = <<<EOD <br><hr><br> Date : $date <br> Title : $title <br> Content : $content <br> Signed By : $signedby <br> EOD; $success = mail($email, $emailSubject, $body, $headers); // SECTION I // on this same user's page on his computer in the browser window, next, print on screen a copy of what the user entered above echo "<h2>Thank you your new blog entry was received successfully. Here is a copy of what you wrote:</h2>"; echo "Date: " . $date . "<br>"; echo "Title: " . $title . "<br>"; echo "Content: " . $content . "<br>"; echo "Signed By: " . $signedby . "<br>"; $date = $title = $content = $signedby = ""; } } ?> <form class="modal-content animate" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="application/x-www-form-urlencoded">> <div class="imgcontainer"> <img src="http://www.me.com/pagepieces/images/me.png" alt="Avatar" width="150" height="100" class="avatar"> </div> <div class="container"> <label for="uname"><b>Username</b></label> <input type="text" placeholder="Enter Username" name="uname" required> <label for="psw"><b>Password</b></label> <input type="password" placeholder="Enter Password" name="psw" required> <button type="submit" name="submit" value="Submit">Login</button> </div> <div class="container" style="background-color:#f1f1f1"> <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button> </div> </form> <?php mysqli_close($connect); ?> </div> <script> // Get the modal var modal = document.getElementById('id01'); // When the user clicks anywhere outside of the modal, close it window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } </script> 2. I would like to make it so that when I click on the "submit" button, that it first checks to see if I have entered the correct user name and password info (do I need to make a php file such as pswchecking.php or do this in a new database for only 1 user name?) and that if it isn't me, then it sends an error message - This is what I have written up from my mixed limited understanding of javascript, php, html, etc... (note I am also getting an error in Dreamweaver on the "die("you are NOT Me You cannot access this database"; line - why? Also.. where to place the "include" for this php page? Does it go on the modal before or after the submit button? <?php $user_name = "me"; $password = "mysetpasword"; // Check connection if (!$user_name . !$password) { die("You are NOT Me You cannot access this database"; } ?> 3. Then, if it is me, to give a success message <?php $user_name = "myword"; $password = "mypasword"; // Check connection if (!$user_name, !$password) { die("You are NOT Me! You cannot access this database " . mysqli_connect_error()); } } else { echo "Hi Me! Welcome Back! "; } ?> 4. And to pop up the blog.php page to enter a new blog entry on (how do I make it be a pop window? if its in the middle of the coding?) <?php $user_name = "myword"; $password = "mypasword"; // Check connection if (!$user_name, !$password) { die("You are NOT Me! You cannot access this database " . mysqli_connect_error()); } } else { echo "Hi Me! Welcome Back! " . include('blogentrypage.php'); } ?> 5. This is the blog entry page <?php //keep this in here to display all the errors on debugging ini_set('display_errors', 1); error_reporting(E_ALL); // SECTION A // define the connection info // got this info from 1and1.com directly include('blogdbConfig.php'); // Define the connection and then connect $connect = mysqli_connect($host_name, $user_name, $password, $database); // this is where the debugging portion ends // SECTION B // check the connection if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } // SECTION C // test again and strip the user info of characters I don't want function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } // set all the fields on the new database record to empty initially to reset it from the previous entry $dateErr = $titleErr = $contentErr = $signedbyErr = ""; $date = $title = $content = $signedby = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { // if connected to the server successfully and it requests info or is ready to receive the info.... $passed = true; // } else { $passed = false; } // then start working on the entry info to clean it up and make sure all the fields have been filled in if (empty($_POST["date"])) { $dateErr = "Please enter a date in the format of monthname date, full year"; $passed = false; } else { $date = test_input($_POST["date"]); } if (empty($_POST["title"])) { $titleErr = "Title is required"; $passed = false; } else { $title = test_input($_POST["title"]); if (!preg_match("/^[a-zA-Z ]*$/",$title)) { $passed = false; $titleErr = "Only letters and white space allowed"; } } if (empty($_POST["content"])) { $contentErr = "Content is required"; $passed = false; } else { $content = test_input($_POST["content"]); } if (empty($_POST["signedby"])) { $signedbyErr = "Signed by is required"; $passed = false; } else { $signedby = test_input($_POST["signedby"]); if (!preg_match("/^[a-zA-Z ]*$/",$signedby)) { $passed = false; $signedbyErr = "Only letters and white space allowed"; } } if ($passed) { //SECTION E // define what $mysqli is made up of (taken from the fields in the html form code below) $mysqli = "INSERT INTO blogentries (date, title, content, signedby) VALUES ('$date','$title','$content','$signedby')"; //SECTION F // Checking the connection and verifying the user's information/$mysqli (which was defined above) has been entered into the new record in the database, then it gives a success message if (mysqli_query($connect, $mysqli)) { echo "New record created successfully"; } else { echo "Error: " . $mysqli . "<br>" . mysqli_error($connect); } // SECTION G // define what $email, and $email Subject is made up of for when it sends an email to me to let me know I just posted something. $email = "info@me.com"; $emailSubject = "A new blog entry was just received in the database"; // define what the headers of the email should say $headers = "From:$signedby\r\n"; $headers = "Content-type: text/html\r\n"; // define what the body of the email should say and look like $body = <<<EOD <br><hr><br> Date : $date <br> Title : $title <br> Content : $content <br> Signed By : $signedby <br> EOD; // SECTION H // define the action to take upon success of a new record having been created - i.e. mail it with the email info, email subject, body, and headers from the above definitions, to my email address $success = mail($email, $emailSubject, $body, $headers); // SECTION I // on this same page on the computer in the browser window, next, print on screen a copy of what was entered echo "<h2>Thank you your new blog entry was received successfully. Here is a copy of what you wrote:</h2>"; echo "Date: " . $date . "<br>"; echo "Title: " . $title . "<br>"; echo "Content: " . $content . "<br>"; echo "Signed By: " . $signedby . "<br>"; // SECTION J // when everything has been done, close the database connection $date = $title = $content = $signedby = ""; } } ?> <p><span class="error">* required field.</span></p> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="application/x-www-form-urlencoded"> Date:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Date" name="date" value="<?php echo $date; ?>"><span class="error">* <?php echo $dateErr; ?></span><br> Title:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Title" required name="title" value="<?php echo $title; ?>"><span class="error">* <?php echo $titleErr; ?></span><br> Content:<textarea placeholder="Content" required name="content" rows="30" cols="40" value="<?php echo $content; ?>"></textarea><span class="error">* <?php echo $contentErr; ?></span><br> Signed By:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Signed By" required name="signedby" value="<?php echo $signedby; ?>"><span class="error">* <?php echo $signedbyErr; ?></span><br> <input class="w3-input w3-padding-16 w3-border" type="datetime-local" required name="date" value="2017-11-16T20:00"> <!--- PLACEHOLDER Not allowed on this type ABOVE--> <br> <button class="w3-button w3-black"><input type="submit" name="submit" value="Submit"></button> </form> <?php mysqli_close($connect); ?> 6. Next, when I have finished entering the information for the new entry, and click submit - it goes to a Config.php file to access the database and put the info into it <?php // got this info from 1and1.com directly $host_name = "me.db.1and1.com"; $user_name = "medatabaseusername"; $password = "mydatabasepsassword"; $database = "mydatabase"; // Create connection using the mysqli procedural format $connect = mysqli_connect($host_name, $user_name, $password, $database); // Check connection if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } ?> I have the entry page setup to send me a confirmation email with the new entry info. The final step is to add the information for the new posting only, on the blog.php page, as well as links to years and months for all the other postings , so not all the entries are shown at once. <?php //keep this in here to display all the errors on debugging ini_set('display_errors', 1); error_reporting(E_ALL); // SECTION A // define the connection info // got this info from 1and1.com directly include('blogdbConfig.php'); // Define the connection and then connect $connect = mysqli_connect($host_name, $user_name, $password, $database); // this is where the debugging portion ends // SECTION B // check the connection if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } // SECTION C // test again and strip the user info of characters I don't want function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } // set all the fields on the new database record to empty initially to reset it from the previous entry $dateErr = $titleErr = $contentErr = $signedbyErr = ""; $date = $title = $content = $signedby = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { // if connected to the server successfully and it requests info or is ready to receive the info.... $passed = true; // } else { $passed = false; } // then start working on the entry info to clean it up and make sure all the fields have been filled in if (empty($_POST["date"])) { $dateErr = "Please enter a date in the format of monthname date, full year"; $passed = false; } else { $date = test_input($_POST["date"]); } if (empty($_POST["title"])) { $titleErr = "Title is required"; $passed = false; } else { $title = test_input($_POST["title"]); if (!preg_match("/^[a-zA-Z ]*$/",$title)) { $passed = false; $titleErr = "Only letters and white space allowed"; } } if (empty($_POST["content"])) { $contentErr = "Content is required"; $passed = false; } else { $content = test_input($_POST["content"]); } if (empty($_POST["signedby"])) { $signedbyErr = "Signed by is required"; $passed = false; } else { $signedby = test_input($_POST["signedby"]); if (!preg_match("/^[a-zA-Z ]*$/",$signedby)) { $passed = false; $signedbyErr = "Only letters and white space allowed"; } } if ($passed) { //SECTION E // define what $mysqli is made up of (taken from the fields in the html form code below) $mysqli = "INSERT INTO blogentries (date, title, content, signedby) VALUES ('$date','$title','$content','$signedby')"; //SECTION F // Checking the connection and verifying the user's information/$mysqli (which was defined above) has been entered into the new record in the database, then it gives a success message if (mysqli_query($connect, $mysqli)) { echo "New record created successfully"; } else { echo "Error: " . $mysqli . "<br>" . mysqli_error($connect); } // SECTION G // define what $email, and $email Subject is made up of for when it sends an email to me to let me know I just posted something. $email = "info@me.com"; $emailSubject = "A new blog entry was just received in the database"; // define what the headers of the email should say $headers = "From:$signedby\r\n"; $headers = "Content-type: text/html\r\n"; // define what the body of the email should say and look like $body = <<<EOD <br><hr><br> Date : $date <br> Title : $title <br> Content : $content <br> Signed By : $signedby <br> EOD; // SECTION H // define the action to take upon success of a new record having been created - i.e. mail it with the email info, email subject, body, and headers from the above definitions, to my email address $success = mail($email, $emailSubject, $body, $headers); // SECTION I // setup a new link on the blog page for the category under which it falls (i.e. year/month/date) //i.e if a new database record was created, then post the new link on the blog page by category under year and month and date ( so it needs to be sorted in order), and show only the fresh content via an "echo" command? //HOW!?!?!???! // SECTION J // when everything has been done, close the database connection $date = $title = $content = $signedby = ""; } } ?> <p><span class="error">* required field.</span></p> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="application/x-www-form-urlencoded"> Date:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Date" name="date" value="<?php echo $date; ?>"><span class="error">* <?php echo $dateErr; ?></span><br> Title:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Title" required name="title" value="<?php echo $title; ?>"><span class="error">* <?php echo $titleErr; ?></span><br> Content:<textarea placeholder="Content" required name="content" rows="30" cols="40" value="<?php echo $content; ?>"></textarea><span class="error">* <?php echo $contentErr; ?></span><br> Signed By:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Signed By" required name="signedby" value="<?php echo $signedby; ?>"><span class="error">* <?php echo $signedbyErr; ?></span><br> <input class="w3-input w3-padding-16 w3-border" type="datetime-local" required name="date" value="2017-11-16T20:00"> <!--- PLACEHOLDER Not allowed on this type ABOVE--> <br> <button class="w3-button w3-black"><input type="submit" name="submit" value="Submit"></button> </form> <?php mysqli_close($connect); ?> where blogsortedlinks.php is used to sort the information before posting it on the blog.php page: <?php //keep this in here to display all the errors on debugging ini_set('display_errors', 1); error_reporting(E_ALL); // SECTION A // define the connection info // got this info from 1and1.com directly include('blogdbConfig.php'); // Define the connection and then connect $connect = mysqli_connect($host_name, $user_name, $password, $database); // this is where the debugging portion ends /// set all the fields on the new database record to empty initially to reset it from the previous user (do I need to autoincrement here somewhere? Maybe my database settings are wrong?) // SECTION B // check the connection if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } // SECTION C //This tells the server what to do with the user's info when it gets to the SECTION D of this php page (I suspect this should be after the SECTION D but then SECTION E of defining mysqli will have to be moved down further as well) // test again and strip the user info of characters I don't want function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } // set all the fields on the new database record to empty initially to reset it from the previous user (do I need to autoincrement here somewhere? Maybe my database settings are wrong?) $dateErr = $titleErr = $contentErr = $signedbyErr = ""; $date = $title = $content = $signedby = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { // if connected to the server successfully and it requests info or is ready to receive the info.... $passed = true; // } else { $passed = false; } if ($passed) { // I have a MySQL database with which I'm dynamically populating a web page. I'm building a MySQL query that fetches some dates stored in a table called blogentries that I can later echo out on the blog page with PHP. The columns in that table are id, date, title, content, and signedby. I want the user to be able to sort dates and titles alphabetically, by date (low-high) etc by clicking the relevant links on the page. This is what I've written so far: // Run a SELECT query to get all the dates that are stored in the database // By default, if no sorting URL variable is fed onto the page, then the SQL query becomes order by id. // The first time you land on the blog page as plain blog.php, not blog.php?=variable, this is the query that's used $mysqli = mysqli_query($connect,"SELECT * FROM blogentries ORDER BY date DESC"); // If the user chooses to sort the dates in a different way, then an HTML link will set a PHP variable onto this blog page // We will check for that variable and change the SQL query to sort the dates in a different way if (isset($_GET['sortby'])) { // Capture that in a variable by that name $sortby == $_GET['sortby']; // Now to change the SQL query based on the sorting the user chose (date high to low, low to high, alphabetical and latest first) if ($sortby == 'datehilo') { $mysqli = mysqli_query($connect,"SELECT * FROM date ORDER BY title DESC"); } elseif ($sortby = 'datelohi') { $mysqli == mysqli_query($connect,"SELECT * FROM date ORDER BY title ASC"); } elseif ($sortby = 'title') { $mysqli == mysqli_query($connect,"SELECT * FROM date ORDER BY title"); } } <p><a href="blog.php?sortby=datehilo">Date (Highest-Lowest)</a></p> <p><a href="blog.php?sortby=datelohi">Date (Lowest-Highest)</a></p> <p><a href="blog.php?sortby=title">Alphabetical</a></p> ?> sortedlinks.php is: <?php ini_set('display_errors', 1); error_reporting(E_ALL); include('blogdbConfig.php'); $connect = mysqli_connect($host_name, $user_name, $password, $database); if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } $dateErr = $titleErr = $contentErr = $signedbyErr = ""; $date = $title = $content = $signedby = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $passed = true; // } else { $passed = false; } if ($passed) { $mysqli = mysqli_query($connect,"SELECT * FROM blogentries ORDER BY date DESC"); // I copied the folowing code from somewhere else and am wondering if I need to make abother php page or something that identifies the variables sortby, datehilo, datelohi, title - seems to me this coudl just be done on the mysqli database itself ? // If the user chooses to sort the dates in a different way, then an HTML link will set a PHP variable onto this blog page // We will check for that variable and change the SQL query to sort the dates in a different way if (isset($_GET['sortby'])) { // Capture that in a variable by that name $sortby == $_GET['sortby']; // Now to change the SQL query based on the sorting the user chose (date high to low, low to high, alphabetical and latest first) if ($sortby == 'datehilo') { $mysqli = mysqli_query($connect,"SELECT * FROM date ORDER BY title DESC"); } elseif ($sortby = 'datelohi') { $mysqli == mysqli_query($connect,"SELECT * FROM date ORDER BY title ASC"); } elseif ($sortby = 'title') { $mysqli == mysqli_query($connect,"SELECT * FROM date ORDER BY title"); } } include('blogentryretrieval.php'); <p><a href="blog.php?sortby=datehilo">Date (Highest-Lowest)</a></p> <p><a href="blog.php?sortby=datelohi">Date (Lowest-Highest)</a></p> <p><a href="blog.php?sortby=title">Alphabetical</a></p> ?> and finally blogentryretrieval.php <?php // got this info from 1and1.com directly $host_name = "dbnumber.db.1and1.com"; $user_name = "dbonumber"; $password = "password"; $database = "dbnumber"; // Create connection using the mysqli procedural format $connect = mysqli_connect($host_name, $user_name, $password, $database); // Check connection if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } $mysqli = "SELECT date, title, content, signedby FROM blogentries"; $result = $connect->query($mysqli); if ($result->num_rows > 0) { echo "<table><tr><th>Date</th><th>Title</th><th>Content</th><th>Written by:</th></tr>"; // output data of each row while($row = $result->fetch_assoc()) { echo "<tr><td>" . $row["date"]. "</td><td>" . $row["title"]. "</td><td> " . $row["content"]. "</td><td>" . $row["signedby"]. "</td></tr>"; } echo "</table>"; } else { echo "0 results"; } $connect->close(); ?> The error messages I am getting are as follows: on the blog.php page when I call it up initially it says this: Warning: include(blogsortedlinks): failed to open stream: No such file or directory in /homepages/42/htdocs/blog.php on line 375Warning: include(): Failed opening 'blogsortedlinks' for inclusion (include_path='.:/usr/lib/php5.6') in /homepages/42/htdocs/blog.php on line 375Date: Notice: Undefined index: date in /homepages/42/htdocs/blog.php on line 378Title: Notice: Undefined index: title in /homepages/42/htdocs/blog.php on line 379Content: Notice: Undefined index: content in /homepages/42/htdocs/blog.php on line 380Author: Notice: Undefined index: signedby in /homepages/42/htdocs/blog.php on line 381 When I click on the login button.. it calls up the modal fine....but.. it disappears when I click on submit and doesn't do anything.... I also don't know where to put my username and password in a database or on a separate php file to sore it permanently so the modal can call on it to verify I am the right person ....ideas? Thanks B
  6. Hi, No, This is what I want to do but haven't found a way to do it with AJAX yet... 1. when a user gets to the point of selecting yes or no for the mailing list..... a. if he clicks the "yes" radio button, it will drop down a box where he can select from a number of mailing lists (checkboxes), and that information gets held onto until he clicks"submit" for the entire form 2. Once he clicks submit on the form page, the information goes to these places: a. an email of the information goes to me b. an email copy of the info goes to the user c. all the information with each mailing list selected goes into the mailinglist database d. all the information with just a yes/no for the mailinglist question goes to the contactform database e. all the info the user entered and the mailinglists he selected gets printed on his browser window with a "success" message I tried to figure it out in AJAX, but... I can't see how to create the checkboxes in there . It seems like its more for static information, not interactivity. other ideas? or did I miss something? THanks B
  7. HI OK .. am processing.. .... I have a php page which contains my form. at one point I have this piece of code....... if (empty($_POST["join_mailing_list"])) { $join_mailing_listErr = "requires a yes or no"; $passed = false; } else { $join_mailing_list = test_input($_POST["join_mailing_list"]); } $first_nameErr = $last_nameErr = $phone_numberErr = $addressErr = $cityErr = $stateErr = $zipErr = $countryErr = $email_addressErr = $commentsErr = $everylistErr = $list1Err = $list2Err = $list3Err = $list4Err = $list5Err = $list6Err = $list7Err = $list8Err = $list9Err = $list10Err = $list11Err = ""; $first_name = $last_name = $phone_number = $address = $city = $state = $zip = $country = $email_address = $comments = $everylist = $list1 = $list2 = $list3 = $list4 = $list5 = $list6 = $list7 = $list8 = $list9 = $list10 = $list11 = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { // if connected to the server successfully and it requests info or is ready to receive the info.... $passed = true; $everylist = test_input($_POST["everylist"]); $list1 = test_input($_POST["list1"]); $list2 = test_input($_POST["list2"]); $list3 = test_input($_POST["list3"]); $list4 = test_input($_POST["list4"]); $list5 = test_input($_POST["list5"]); $list6 = test_input($_POST["list6"]); $list7 = test_input($_POST["list7"]); $list8 = test_input($_POST["list8"]); $list9 = test_input($_POST["list9"]); $list10 = test_input($_POST["list10"]); $list11 = test_input($_POST["list11"]); if ($passed) { $mysqli = "INSERT INTO mailinglist (first_name, last_name, phone_number, address, city, state, zip, country, email_address, comments, everylist, list1, list2, list3, list4, list5, list6, list7, list8, list9, list10, list11) VALUES ('$first_name','$last_name','$phone_number','$address','$city','$state','$zip','$country','$email_address', '$comments','$everylist','$list1','$list2','$list3','$list4','$list5','$list6','$list7','$list8','$list9','$list10','$list11])"; if (mysqli_query($connect, $mysqli)) { echo "New record created successfully"; } else { echo "Error: " . $mysqli . "<br>" . mysqli_error($connect); } $email = "info@mygmail.com"; $emailSubject = "Inquiry from the contact page with Newsletter signup"; // define what the headers of the email should say $headers = "From:$email_address\r\n"; $headers = "Content-type: text/html\r\n"; // define what the body of the email should say and look like $body = <<<EOD <br><hr><br> First Name : $first_name <br> Last Name : $last_name <br> Phone Number : $phone_number <br> Address : $address <br> City : $city <br> State : $state <br> Zip : $zip <br> Country : $country <br> Email Address : $email_address <br> Comments : $comments <br> You have subscribed to the following Newsletters : // how do I show which ones here?<br> <br> EOD; echo "<h2>Thank you your message was received successfully. Here is a copy of what you sent us:</h2>"; echo "First Name: " . $first_name . "<br>"; echo "Last Name: " . $last_name . "<br>"; echo "Phone Number: " . $phone_number . "<br>"; echo "Address: " . $address . "<br>"; echo "City: " . $city . "<br>"; echo "State: " . $state . "<br>"; echo "Zip Code: " . $zip . "<br>"; echo "Country: " . $country . "<br>"; echo "Email Address: " . $email_address . "<br>"; echo "Comments: " . $comments . "<br>"; echo "Joined The following Mailing lists: " . // $how do I show which ones here?; $first_name = $last_name = $phone_number = $address = $city = $state = $zip = $country = $email_address = $comments = $everylist = $list1 = $list2 = $list3 = $list4 = $list5 = $list6 = $list7 = $list8 = $list9 = $list10 = $list11 = ""; } } //$mailinglistdatabase = //$first_name','$last_name','$phone_number','$address','$city','$state','$zip','$country','$email_address', //$comments','one',two','three','four' // The form's html code would go in here? // define variables as per what the user has entered on the page I thought, but am told I don't need these so will try to go without. :) // $first_name = $_POST['first_name']; // $last_name = $_POST['last_name']; // $phone_number = $_POST['phone_number']; // $address = $_POST['address']; // $city = $_POST['city']; // $state = $_POST['state']; // $zip = $_POST['zip']; // $email_address = $_POST['email_address']; // $country = $_POST['country']; // $comments = $_POST['comments']; // $join_mailing_list = $_POST['join_mailing_list']; // $name=$_POST['name']; ?> Do I insert the AJAX as below in place of the above coding? i.e. <div id="mailinglists"> <h2>Signup for our mailinglists</h2> <button type="button" onclick="loadDoc()">show a selection for them to click on and open the boxes</button> </div> where loadDoc opens a file called "mailinglist" which is the .txt file? and <script> function loadDoc() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("demo").innerHTML = this.responseText; } }; xhttp.open("GET", "mailinglist.txt", true); xhttp.send(); } </script> (do I need to change GET to POST for security reasons?) and mailinglist.txt is an xml file that looks like this:? everylist list1 list2 list3 list4 list5 list6 list7 list8 list9 list10 list11 But how do I get the pretty little check boxes for the user to click them open if this is a text file? Do I need to make it a little php file of it's own to execute at the same time the greater php file executes on submit? thanks
  8. OK.. looks like I have tons more work to do on this... am going into research mode on w3schools forum to learn about AJAX and declaring the function twice in a php form. Thanks.. will check back in soon... Hope you all have a great day B
  9. ok.. Just changed the phone number field to "Varchar" since it gave me an error message when I tried to change it to text. I'm guessing that's a similar thing like "text", and it will still be stripped of unwanted characters by the php function before insertion.
  10. Wow! Cool ! You just "up-sold" me on having to learn AJAX now too LOL!!! Thanks.. I think ?!?!?!?! So Far I have the page looking right on the user's side. The hover drop down button looks pretty However when I hit submit I get and error message: Fatal error: Cannot redeclare test_input() (previously declared in /homepages/42/d547303762/htdocs/w/contactus.php:121) in /homepages/42/d547303762/htdocs/w/contactus.php on line 258 SO.. I will look into AJAX and javascript. THanks
  11. Ok.. am just processing thoughts here in english to get to the php codeing of it.....Am open to your suggestions please 1. Php If/else statement: If the user clicks on the "yes" radio button, then a hoverable-drop-down-menu opens up with a selection of checkboxes for which list to sign up for My attempt at html multi-selection-hoverable-drop-down-button: .....<input class="w3-radio" type="radio" name="join_mailing_list" <?php if (isset($join_mailing_list) && $join_mailing_list == "yes") echo "checked"; ?> value="yes"> <div class="dropdown"> <button onclick="myFunction()" class="dropbtn">Yes</button> <div class="dropdown-content"> <label class="container">All Lists <input type="checkbox" checked="checked" value'"All LIsts"> <span class="checkmark"></span> </label> <label class="container">one <input type="checkbox" value="one"> <span class="checkmark"></span> </label> <label class="container">two <input type="checkbox" value="two"> <span class="checkmark"></span> </label> <label class="container">three <input type="checkbox" value="three"> <span class="checkmark"></span> </label> <label class="container">four <input type="checkbox" value="four"> <span class="checkmark"></span> </label> </div> </div> My Attempt at the Php code for it: // This would be added to Section C from my previous messages above // this is already in the page // if (empty($_POST["join_mailing_list"])) { // $join_mailing_listErr = "requires a yes or no"; // $passed = false; // } else { // $join_mailing_list = test_input($_POST["join_mailing_list"]); // . }" // Here I am adding the extra new code.. some of which seems like the same thing put in here but twice (since I copied it from the php code above to re-enter it for to send the same info to the second database).... // I want to tell it....if value="yes", then "on submit", send the page information to two databases. // The first database ($database) gets all the information and "joining_the_mailinglist" is shown as yes or no ... this already is set up and works. This is done via my "Configfile.php" which is set up as an "include" in the contact form at the top. // The second database ($mailinglistdatabase?) gets all the information plus the checked boxes of mailing lists selected. // so....can I be connected to two databases at one time to do this? or how do I work this the best? Do I close the first one first, then re-send the info to the second database using similar php coding to include all the info from the form plus more? include('dbConfigmailinglist#2signininfo.php'); $connect = mysqli_connect($host_name, $user_name, $password, $database); if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } $first_nameErr = $last_nameErr = $phone_numberErr = $addressErr = $cityErr = $stateErr = $zipErr = $countryErr = $email_addressErr = $commentsErr = $join_mailing_listErr = ""; $first_name = $last_name = $phone_number = $address = $city = $state = $zip = $country = $email_address = $comments = $one = $two = $three = $four = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { // if connected to the server successfully and it requests info or is ready to receive the info.... $passed = true; if (empty$_POST["join_mailing_list"])) { $join_mailing_listErr = "requires a yes or no"; $passed = false; } else { $join_mailing_list = test_input($_POST["join_mailing_list"]); } if ($passed) { $mysqli = "INSERT INTO mailinglistdatabases (first_name, last_name, phone_number, address, city, state, zip, country, email_address, comments, one, two, three, four) VALUES ('$first_name','$last_name','$phone_number','$address','$city','$state','$zip','$country','$email_address', '$comments','$one','$two','$three','$four')"; if (mysqli_query($connect, $mysqli)) { echo "New record created successfully"; } else { echo "Error: " . $mysqli . "<br>" . mysqli_error($connect); } $email = "info@myemail.com"; $emailSubject = "Inquiry from the contact page with Newsletter signup"; // define what the headers of the email should say $headers = "From:$email_address\r\n"; $headers = "Content-type: text/html\r\n"; // define what the body of the email should say and look like $body = <<<EOD <br><hr><br> First Name : $first_name <br> Last Name : $last_name <br> Phone Number : $phone_number <br> Address : $address <br> City : $city <br> State : $state <br> Zip : $zip <br> Country : $country <br> Email Address : $email_address <br> Comments : $comments <br> You subscribed to the following Newsletters : // how do I show which ones here?<br> <br> EOD; echo "<h2>Thank you your message was received successfully. Here is a copy of what you sent us:</h2>"; echo "First Name: " . $first_name . "<br>"; echo "Last Name: " . $last_name . "<br>"; echo "Phone Number: " . $phone_number . "<br>"; echo "Address: " . $address . "<br>"; echo "City: " . $city . "<br>"; echo "State: " . $state . "<br>"; echo "Zip Code: " . $zip . "<br>"; echo "Country: " . $country . "<br>"; echo "Email Address: " . $email_address . "<br>"; echo "Comments: " . $comments . "<br>"; echo "Joined The following Mailing lists: " . // $how do I show which ones here?; $first_name = $last_name = $phone_number = $address = $city = $state = $zip = $country = $email_address = $comments = $one = $two = $three = $four = ""; } } ?> $mailinglistdatabase = $first_name','$last_name','$phone_number','$address','$city','$state','$zip','$country','$email_address', '$comments','one',two','three','four' // The form's html code would go in here? <form></form> Issues: do I need to define a new $variable here for the entire page of info? to send to the "mailinglist" database? , or perhaps use another "Insert Into" statement for the second database? Is it possible to nest "Insert Into" statements? Is it possible to nest "include" statements for two databases? Thanks B
  12. Oh one more question...... I am also building a mailinglist page in php. On the contact page as the last choice for the user, I give them the option to elect yes or no if they want to sign up for the mailing list. I would like to make it so that: 1) if the user selects yes, that it will present a drop down menu to select which list they want to sign up on (I have about 8) - Because I am working with php and html, I am a bit confused... can I simply create a drop down menu in html, and then in php add an" if/else" statement so that the menu is hidden until they select yes? I feel like I'm missing a piece here... how to hide the menu until "yes" is selected? Or do I need to use Php object rules?, or.....I found a new one on the w3 schools forum about...PHP resource! That sounds like it might be able to put the info into the other database.. ugh! So many options! LOL! 2) How do I send all the information from the contact page to the mailing list database (which is a separate database from teh contactpage database) only when the user selects a mailing list? 3) How to make it "echo" back on the page which mailing lists they signed up for ( more than one hopefully) Thanks
  13. oh I have one more issue... When the user enters the phone number it shows up wrong in the database... i.e. when a dash is entered between the numbers 224-578-9562, then only the 224 shows up in teh database. when I leave the dashes out, it shows up as a completely different number 2147483671 . (there are enough digits in this but it's not the number the user entered... I am guessing this is because I have no error testing set up on the phone number in the php form? I also have the function to strip out hash marks and other characters I don't want. .so how do I specify that for phone numbers it's ok to accept dashes, and how do I make it also give the correct number if the user chooses not to enter dashes? Thanks
  14. Yes! Thank you! That's it! I had it set to Tiny Int (1). I am still new to mysqli and have studied the w3schools pages but still have more to learn . Thank you!!!!! Where can I send you a coffee? Peace B
  15. Hmmm.. I think I wasn't clear in my statement before... It doesn't matter which radio button is chosen, the database field for both yes and no are entered with zeros, both, each time. so I have no way to differentiate if it's a yes or no that the user has entered.
  16. Oh... hang on a second... The radio button thing isn't working right. ugh! I just noticed that if I click yes or no both times it just enters a zero in teh mysqli database field. ideas? as to why this is happening? THanks Barb
  17. Thank you! I understand. That Heredoc issue made a world of difference! wow! Thanks to you both for the support on this. I believe I owe you a coffee Thanks also for the info on the $passed. I like that piece of code in there :), and the debugging thing. I am guessing I can comment the debugger out now? I hope you both have an awesome day! Peace B
  18. Hi JustSomeguy. Thanks! If I understand it correctly... "If the request method is post, then that generally means a form has been submitted" - so this should come after the form. yes?
  19. um..... I must be getting close.. it's more confusing LOL! I have commented by the various parts in the code, and labelled the different sections to make it easier to reference... I don't have to keep adding the line numbers this way when I am talking with you. Thanks for you response. I am not sure how to interpret what you wrote.. did you mean that I should re-write the code piece like this?.... if ($_SERVER["REQUEST_METHOD"] == "POST") { // if connected to the server and it requests info then post the following info $passed=true; } else { $passed = false; } * The form needs to below the setting of empty string value, and below the validation of submitted data from form to show error messages. Ok. I moved it.. BUT..... in my head there is a connection missing then.... maybe it's just a theorem I need to accept? - i.e. if php reads from the top down, and the form (SECTION D) is positioned after the 'validation of the submitted data from the form'... then how can it validate the information from the submitted data if the form comes after it? That says to me that it doesn't have a form to validate but thinks it does and carries out the action.. but how?.. huh? I'm confused on this part. * This form will appear along side the display of data se(n)t through email, so you might (want)to check if email fail(s to) show form again, else show the other (other what?). Huh? I didn't understand your sentence here..... Line 16 has nothing to with setting database field to zero, these hold values that should hold some value otherthan "", before getting anywhere near being added to database. Auto incremental fields don't need to be included, as name suggests it autoincrements on every new record created. OK Ok it now looks like this: I put that little piece of code in there... then moved the form (SECTION D) to go after the connection is made/tested and has cleared the variables. Then I put the instructions on what to with the form data after the form submit button. To me ... this makes sense...but it's not working and I am now getting an error message such as this.. Parse error: syntax error, unexpected end of file in /homepages/42//htdocs/contactcode.php on line 238 Line 238 is mysqli_close($connect); <?php //SECTION A // define the conection info // got this info from 1and1.com directly $host_name = "........."; $user_name = "........."; $password = "........."; $database = "........."; // define the connection and then connect $connect = mysqli_connect($host_name, $user_name, $password, $database); //keep this in here to display all the errors on debugging ini_set('display_errors', 1); error_reporting(E_ALL); //this is where the debugging portion ends // set all the fields on the new database record to empty initially to reset it from the previous user (do I need to autoincrement here somewhere? Maybe my database settings are wrong?) $first_nameErr = $last_nameErr = $phone_numberErr = $addressErr = $cityErr = $stateErr = $zipErr = $countryErr = $email_addressErr = $commentsErr = $join_mailing_listErr = ""; $first_name = $last_name = $phone_number = $address = $city = $state = $zip = $country = $email_address = $comments = $join_mailing_list = ""; // SECTION B // check the connection if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } // SECTION C //This tells the server what to do with the user's info when it gets to the SECTION D of this php page (I suspect this should be after the SECTION D but then SECTION E of defining mysqli will have to be moved down further as well) if ($_SERVER["REQUEST_METHOD"] == "POST") { // if connected to the server successfully and it requests info or is ready to receive the info.... $passed=true; } else { $passed = false; } // then start working on the user's info to clean it up and make sure all the fields have been filled in if (empty($_POST["first_name"])) { // this checks to see if the field on the users browser website page is empty or if they filled it in $first_nameErr = "First name is required"; // if the field on the users computer is left empty when posting, this tells gives the user an error message } else { $first_name = test_input($_POST["first_name"]); // if the field has been filled in, then run it through the following test to test it for hacking characters if (!preg_match("/^[a-zA-Z ]*$/",$first_name)) { // if there is a match of any of the hacking characters listed here, then send an error message to the user $first_nameErr = "Only letters and white space allowed"; // this is the error message sent if there is a strange character in the field } } if (empty($_POST["last_name"])) { $last_nameErr = "Last name is required"; } else { $last_name = test_input($_POST["last_name"]); if (!preg_match("/^[a-zA-Z ]*$/",$last_name)) { $last_nameErr = "Only letters and white space allowed"; } } if (empty($_POST["phone_number"])) { $phone_numberErr = "Please enter a phone number"; } else { $phone_number = test_input($_POST["phone_number"]); } if (empty($_POST["address"])) { $addressErr = "Address is required"; } else { $address = test_input($_POST["address"]); } if (empty($_POST["city"])) { $cityErr = "City is required"; } else { $city = test_input($_POST["city"]); if (!preg_match("/^[a-zA-Z ]*$/",$city)) { $cityErr = "Only letters and white space allowed"; } } if (empty($_POST["state"])) { $stateErr = "State is required"; } else { $state = test_input($_POST["state"]); if (!preg_match("/^[a-zA-Z ]*$/",$state)) { $stateErr = "Only letters and white space allowed"; } } if (empty($_POST["zip"])) { $zipErr = "Zip is required"; } else { $zip = test_input($_POST["zip"]); } if (empty($_POST["country"])) { $countryERR = "please enter your country"; } else { $country = test_input($_POST["country"]); if (!preg_match("/^[a-zA-Z ]*$/",$country)) { $countryErr = "Only letters and white space allowed"; } } if (empty($_POST["email_address"])) { $email_addressErr = "Email is required"; } else { $email_address = test_input($_POST["email_address"]); if (!filter_var($email_address, FILTER_VALIDATE_EMAIL)) { $email_addressErr = "Invalid email format"; } } if (empty($_POST["comments"])) { $comments = ""; } else { $comments = test_input($_POST["comments"]); } if (empty($_POST["join_mailing_list"])) { $join_mailing_listErr = "requires a yes or no"; } else { $join_mailing_list = test_input($_POST["join_mailing_list"]); } // define variables as per what the user has entered on the page I thought, but am told I don't need these so will try to go without. :) // $first_name = $_POST['first_name']; // $last_name = $_POST['last_name']; // $phone_number = $_POST['phone_number']; // $address = $_POST['address']; // $city = $_POST['city']; // $state = $_POST['state']; // $zip = $_POST['zip']; // $email_address = $_POST['email_address']; // $country = $_POST['country']; // $comments = $_POST['comments']; // $join_mailing_list = $_POST['join_mailing_list']; // $name=$_POST['name']; // test again and strip the user info of characters I don't want function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <!-- SECTION D - Here is where the user enterss the info for the database to it up --> <!-- Middle Column section --> <!-- the form itself --> <p><span class="error">* required field.</span></p> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="text/plain"> First Name:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="First Name" required name="first_name" value="<?php echo $first_name;?>"><span class="error">* <?php echo $first_nameErr;?></span><br> Last Name:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Last Name" required name="last_name" value="<?php echo $last_name;?>"><span class="error">* <?php echo $last_nameErr;?></span><br> Phone:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Phone" required name="phone_number" size="50" value="<?php echo $phone_number;?>"><span class="error">* <?php echo $phone_numberErr;?></span><br> Address:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Address" required name="address" value="<?php echo $address;?>"><span class="error">* <?php echo $addressErr;?></span><br> City:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="City" required name="city" value="<?php echo $city;?>"><span class="error">* <?php echo $cityErr;?></span><br> State:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="State" required name="state" value="<?php echo $state;?>"><span class="error">* <?php echo $stateErr;?></span><br> Zip Code:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Zip" required name="zip" value="<?php echo $zip;?>"><span class="error">* <?php echo $zipErr;?></span><br> Country:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Country" required name="country" value="<?php echo $country;?>"><span class="error">* <?php echo $countryErr;?></span><br> Email Address:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Email Address" required name="email_address" value="<?php echo $email_address;?>"><span class="error">* <?php echo $email_addressErr;?></span><br> Comment:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Message" required name="comments" size="75" value="<?php echo $comments;?>"><span class="error">* <?php echo $commentsErr;?></span><br> Would you like to be on our mailing list?<input class="w3-radio" type="radio" name="join_mailing_list" <?php if (isset($join_mailing_list) && $join_mailing_list=="yes") echo "checked";?> value="yes"><label>Yes</label> <input class="w3-radio" type="radio" name="join_mailing_list" <?php if (isset($join_mailing_list) && $join_mailing_list=="no") echo "checked";?> value="no"><label>No</label><span class="error">* <?php echo $join_mailing_listErr;?></span> <br> <input class="w3-input w3-padding-16 w3-border" type="datetime-local" placeholder="Date and time" required name="date" value="2017-11-16T20:00"><br> <button class="w3-button w3-black"><input type="submit" name="submit" value="Submit"></button> </form> <?php //SECTION E // define what $mysqli is made up of (taken from the fields in the html form code above) $mysqli = "INSERT INTO mydatabase (first_name, last_name, phone_number, address, city, state, zip, country, email_address, comments, join_mailing_list) VALUES ('$first_name','$last_name','$phone_number','$address','$city','$state','$zip','$country','$email_address', '$comments','$join_mailing_list')"; //SECTION F // Checking the connection and verifying the user's information/$mysqli (which was defined above) has been entered into the new record in the database, then it gives a success message if (mysqli_query($connect, $mysqli)) { echo "New record created successfully"; } else { echo "Error: " . $mysqli . "<br>" . mysqli_error($connect); } // SECTION G // define what $email, and $email Subject is made up of for when it sends an email to me to let me know someone just posted something. $email = "myemail@gmail.com"; $emailSubject = "Inquiry from the Contact Page"; // define what the headers of the email should say $headers = "From:$email_address\r\n"; $headers = "Content-type: text/html\r\n"; // define what the body of the email should say and look like $body = <<<EOD <br><hr><br> First Name : $first_name <br> Last Name : $last_name <br> Phone Number : $phone_number <br> Address : $address <br> City : $city <br> State : $state <br> Zip : $zip <br> Country : $country <br> Email Address : $email_address <br> Comments : $comments <br> Subscribe to Mailing List : $join_mailing_list <br> EOD; // SECTION H // define the action to take upon success of a new record having been created - i.e. mail it with the email info, email subject, body, and headers from the above definitions, to my email address $success = mail($email, $emailSubject, $body, $headers); // define the action to take upon success of a new record having been created - i.e. mail it with the email info, email subject, body, and headers from the above definitions, to the user's email address $usersuccess = mail($email_address, $emailSubject, $body, $headers); // SECTION I // on this same user's page on his computer in the browser window, next, print on screen a copy of what the user entered above echo "<h2>Thank you your message was received successfully. Here is a copy of what you sent us:</h2>"; echo $first_name; echo "<br>"; echo $last_name; echo "<br>"; echo $phone_number; echo "<br>"; echo $address; echo "<br>"; echo $city; echo "<br>"; echo $state; echo "<br>"; echo $zip; echo "<br>"; echo $country; echo "<br>"; echo $email_address; echo "<br>"; echo $comments; echo "<br>"; echo $join_mailing_list; // SECTION J // when everything has been done, close the database connection // NOTE I am getting a red error note on the Dreamweaver software panel saying there is something wrong with this being here.. why?!?!?!?! mysqli_close($connect); ?> </body> </html>
  20. I edited this response... see my next posting one down
  21. HI OK. Thank you I rearranged a few things and that got rid of all the error messages... BUT!~ Even though the records are being created in the database, they are still empty. I'm guessing that the records are being created empty because somehow I am still emptying them after the info has been sent.. I just don't see how when I look at my code. hint? The emails are being sent to me but they are also empty. am guessing if I fix the above issue, this will resolve itself The emails are NOT being sent to the user as I instructed the code to do. hmm....I have scoured the code and not been able to see my error. I believe I set it up to draw the user's email from the html form info he enters above, and to automatically send the user a copy. I copied the same bit of code for $usersuccess from right above it $success (where it successfully sends me the email) and just changed the $variables. ideas? It still says "record created successfully all the time. not only when the form has been sent. Do I need to put in something like this on line # 195? - $failed= if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } if (empty($mysqli) {$failed) { $failederrormessage = "An attempt to send your message has failed. Please try again."; } else { $success, $usersuccess Here is the new layout of the code: Thanks again for your help! 1 <?php 2 // define the conection info 3 $host_name = "..........."; 4 $database = "..........."; 5 $user_name = "..........."; 6 $password = "..........."; 7 8 // define the connection and then connect 9 $connect = mysqli_connect($host_name, $user_name, $password, $database); 10 11 //keep this in here to display all the errors on debugging 12 ini_set('display_errors', 1); 13 error_reporting(E_ALL); 14 //this is where the debugging portion ends 15 16 // set all the fields on the new database record to empty initially to reset it from the previous user (do I need to autoincrement here somewhere? Maybe my database settings are wrong?) 17 $first_nameErr = $last_nameErr = $phone_numberErr = $addressErr = $cityErr = $stateErr = $zipErr = $countryErr = $email_addressErr = $commentsErr = $join_mailing_listErr = ""; 18 $first_name = $last_name = $phone_number = $address = $city = $state = $zip = $country = $email_address = $comments = $join_mailing_list = ""; 19 20 ?> 21 <!-- the form itself . How to put this in the php code? reference my attempt below the form code--> 22 <p><span class="error">* required field.</span></p> 23 <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="text/plain"> 24 First Name:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="First Name" required name="first_name" value="<?php echo $first_name;?>"><span class="error">* <?php echo $first_nameErr;?></span><br> 25 Last Name:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Last Name" required name="last_name" value="<?php echo $last_name;?>"><span class="error">* <?php echo $last_nameErr;?></span><br> 26 Phone:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Phone" required name="phone_number" size="50" value="<?php echo $phone_number;?>"><span class="error">* <?php echo $phone_numberErr;?></span><br> 27 Address:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Address" required name="address" value="<?php echo $address;?>"><span class="error">* <?php echo $addressErr;?></span><br> 28 City:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="City" required name="city" value="<?php echo $city;?>"><span class="error">* <?php echo $cityErr;?></span><br> 29 State:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="State" required name="state" value="<?php echo $state;?>"><span class="error">* <?php echo $stateErr;?></span><br> 30 Zip Code:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Zip" required name="zip" value="<?php echo $zip;?>"><span class="error">* <?php echo $zipErr;?></span><br> 31 Country:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Country" required name="country" value="<?php echo $country;?>"><span class="error">* <?php echo $countryErr;?></span><br> 32 Email Address:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Email Address" required name="email_address" value="<?php echo $email_address;?>"><span class="error">* <?php echo $email_addressErr;?></span><br> 33 Comment:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Message" required name="comments" size="75" value="<?php echo $comments;?>"><span class="error">* <?php echo $commentsErr;?></span><br> 34 Would you like to be on our mailing list?<input class="w3-radio" type="radio" name="join_mailing_list" <?php if (isset($join_mailing_list) && $join_mailing_list=="yes") echo "checked";?> 35 value="yes"><label>Yes</label> 36 <input class="w3-radio" type="radio" name="join_mailing_list" <?php if (isset($join_mailing_list) && $join_mailing_list=="no") echo "checked";?> 37 value="no"><label>No</label><span class="error">* <?php echo $join_mailing_listErr;?></span> 38 <br> 39 <input class="w3-input w3-padding-16 w3-border" type="datetime-local" placeholder="Date and time" required name="date" value="2017-11-16T20:00"><br> 40 <button class="w3-button w3-black"><input type="submit" name="submit" value="Submit"></button> 41 </form> 42 43 44 <?php 45 // check the connection 46 if (!$connect) { 47 die("Connection failed: " . mysqli_connect_error()); 48 } 49 50 // define what $mysqli is made up of (taken from the fields in the html form code above) 51 $mysqli = "INSERT INTO mydatabasename (first_name, last_name, phone_number, address, city, state, zip, country, email_address, comments, join_mailing_list) 52 VALUES ('$first_name','$last_name','$phone_number','$address','$city','$state','$zip','$country','$email_address', '$comments','$join_mailing_list')"; 53 54 55 // if connected this says to give a success message and enter the info from $mysqli which was defined above 56 if (mysqli_query($connect, $mysqli)) { 57 echo "New record created successfully"; 58 } else { 59 echo "Error: " . $mysqli . "<br>" . mysqli_error($connect); 60 } 61 62 //This tells the server what to do with the user's info (I suspect this should be after the html form but then the other portion of defining mysqli will have to be moved down further as well) 63 64 if ($_SERVER["REQUEST_METHOD"] == "POST") { // if connected to the server and it requests info then post the following info 65 if (empty($_POST["first_name"])) { // this checks to see if the fiedl on teh users browser website page is empty or if they filled it in 66 $first_nameErr = "First name is required"; // if the field on the users computer is left empty when posting, this tells gives the user an error message 67 } else { 68 $first_name = test_input($_POST["first_name"]); // if the fiedl has been filled in, then run it through the following test to test it for hacking characters 69 if (!preg_match("/^[a-zA-Z ]*$/",$first_name)) { // if there is a match of any of the hacking characters listed here, then send an error message to the user 70 $first_nameErr = "Only letters and white space allowed"; // this is the error message sent if there is a strange character in the field 71 } 72 } 73 if (empty($_POST["last_name"])) { 74 $last_nameErr = "Last name is required"; 75 } else { 76 $last_name = test_input($_POST["last_name"]); 77 if (!preg_match("/^[a-zA-Z ]*$/",$last_name)) { 78 $last_nameErr = "Only letters and white space allowed"; 79 } 80 } 81 if (empty($_POST["phone_number"])) { 82 $phone_numberErr = "Please enter a phone number"; 83 } else { 84 $phone_number = test_input($_POST["phone_number"]); 85 } 86 if (empty($_POST["address"])) { 87 $addressErr = "Address is required"; 88 } else { 89 $address = test_input($_POST["address"]); 90 } 91 92 if (empty($_POST["city"])) { 93 $cityErr = "City is required"; 94 } else { 95 $city = test_input($_POST["city"]); 96 if (!preg_match("/^[a-zA-Z ]*$/",$city)) { 97 $cityErr = "Only letters and white space allowed"; 98 } 99 } 100 if (empty($_POST["state"])) { 101 $stateErr = "State is required"; 102 } else { 103 $state = test_input($_POST["state"]); 104 if (!preg_match("/^[a-zA-Z ]*$/",$state)) { 105 $stateErr = "Only letters and white space allowed"; 106 } 107 } 108 109 if (empty($_POST["zip"])) { 110 $zipErr = "Zip is required"; 111 } else { 112 $zip = test_input($_POST["zip"]); 113 } 114 115 if (empty($_POST["country"])) { 116 $countryERR = "please enter your country"; 117 } else { 118 $country = test_input($_POST["country"]); 119 if (!preg_match("/^[a-zA-Z ]*$/",$country)) { 120 $countryErr = "Only letters and white space allowed"; 121 } 122 } 123 124 if (empty($_POST["email_address"])) { 125 $email_addressErr = "Email is required"; 126 } else { 127 $email_address = test_input($_POST["email_address"]); 128 if (!filter_var($email_address, FILTER_VALIDATE_EMAIL)) { 129 $email_addressErr = "Invalid email format"; 130 } 131 } 132 133 if (empty($_POST["comments"])) { 134 $comments = ""; 135 } else { 136 $comments = test_input($_POST["comments"]); 137 } 138 if (empty($_POST["join_mailing_list"])) { 139 $join_mailing_listErr = "requires a yes or no"; 140 } else { 141 $join_mailing_list = test_input($_POST["join_mailing_list"]); 142 } 143 144 // define variables as per what the user has entered on the page I thought, but am told I don't need these so will try to go without. :) 145 // $first_name = $_POST['first_name']; 146 // $last_name = $_POST['last_name']; 147 // $phone_number = $_POST['phone_number']; 148 // $address = $_POST['address']; 149 // $city = $_POST['city']; 150 // $state = $_POST['state']; 151 // $zip = $_POST['zip']; 152 // $email_address = $_POST['email_address']; 153 // $country = $_POST['country']; 154 // $comments = $_POST['comments']; 155 // $join_mailing_list = $_POST['join_mailing_list']; 156 // $name=$_POST['name']; 157 158 159 // test again and strip the user info of characters I don't want 160 function test_input($data) { 161 $data = trim($data); 162 $data = stripslashes($data); 163 $data = htmlspecialchars($data); 164 return $data; 165 } 166 } 167 // define what $email, and $email Subject is made up of 168 $email = "myemail@gmail.com"; 169 $emailSubject = "Inquiry from the Contact Page"; 170 171 // define what the headers should say 172 $headers = "From:$email_address\r\n"; 173 $headers = "Content-type: text/html\r\n"; 174 175 // define what teh body of the email should say and look like 176 $body = <<<EOD 177 <br><hr><br> 178 First Name : $first_name <br> 179 Last Name : $last_name <br> 180 Phone Number : $phone_number <br> 181 Address : $address <br> 182 City : $city <br> 183 State : $state <br> 184 Zip : $zip <br> 185 Country : $country <br> 186 Email Address : $email_address <br> 187 Comments : $comments <br> 188 Subscribe to Mailing List : $join_mailing_list <br> 189 EOD; 190 191 // define what to upon success of a new record having been created - mail it with the email info, email subject, body, and headers to my email address 192 $success = mail($email, $emailSubject, $body, $headers); 193 // define what to upon success of a new record having been created - mail it to the user's email info (which was defined above in the form), email subject, body, and headers 194 $usersuccess = mail($email_address, $emailSubject, $body, $headers); 195 196 // on this same users page on his computer in the browser window, next, print on screen a copy of what they entered above 197 echo "<h2>Thank you your message was received successfully. Here is a copy of what you sent us:</h2>"; 198 echo $first_name; 199 echo "<br>"; 200 echo $last_name; 201 echo "<br>"; 202 echo $phone_number; 203 echo "<br>"; 204 echo $address; 205 echo "<br>"; 206 echo $city; 207 echo "<br>"; 208 echo $state; 209 echo "<br>"; 210 echo $zip; 211 echo "<br>"; 212 echo $country; 213 echo "<br>"; 214 echo $email_address; 215 echo "<br>"; 216 echo $comments; 217 echo "<br>"; 218 echo $join_mailing_list; 219 220 // when everything has been done, close the database connection 221 mysqli_close($connect); 222 223 ?>
  22. Hi, I love that little code! Thank you!.. I tried it wow! I cleaned up most of it. Here is how it now stands... There are no new records created in the database, the user doesn't get his copy of what he submitted, the email sent to me only contains the fields but not the user's info, the "Thank you your message was received successfully. Here is a copy of what you sent us:" message is on the page all the time from the moment the page is called up, the user's info doesn't echo back onto the page for them to see. While, I understand this page is doing exactly as it is programmed to LOL!, It's not doing what I thought I programmed it to do! LOL This first part about the Undefined variables (line 21 and 24)... I had it originally set to $sql and got the same error message. so then I thought it's because it should be mysqli. So I changed it and got the same error message. ugh Also I have searched the internet for info as to what the "Undefined index" could mean... I thought perhaps I did not have the settings correct in mysqli in the columns. so I went in and added an index for each column, but I still get the same error messages. Then I think I am done thinking I thought perhaps there is a simple typo or an equal sign missing and I've checked them all and could not find it. help please? I am getting the following error messages (I have posted the code below these, in a box as requested. Thanks for pointing that out : ) Thanks for anyone's help please! Notice: Undefined variable: mysqli in /homepages/42/htdocs/contactcode.php on line 21 Warning: mysqli_query(): Empty query in /homepages/42/htdocs/contactcode.php on line 21 Notice: Undefined variable: mysqli in /homepages/42/htdocs/contactcode.php on line 24 Error: Notice: Undefined index: first_name in /homepages/42/htdocs/contactcode.php on line 30 Notice: Undefined index: last_name in /homepages/42/htdocs/contactcode.php on line 31 Notice: Undefined index: phone_number in /homepages/42/htdocs/contactcode.php on line 32 Notice: Undefined index: address in /homepages/42/htdocs/contactcode.php on line 33 Notice: Undefined index: city in /homepages/42/htdocs/contactcode.php on line 34 Notice: Undefined index: state in /homepages/42/htdocs/contactcode.php on line 35 Notice: Undefined index: zip in /homepages/42/htdocs/contactcode.php on line 36 Notice: Undefined index: email_address in /homepages/htdocs/contactcode.php on line 37 Notice: Undefined index: country in /homepages/42/htdocs/contactcode.php on line 38 Notice: Undefined index: comments in /homepages/42/htdocs/contactcode.php on line 39 Notice: Undefined index: join_mailing_list in /homepages/42/htdocs/contactcode.php on line 40 Warning: mysqli_close(): Couldn't fetch mysqli in /homepages/42/htdocs/contactcode.php on line 205 8 // create the connection 9 $connect = mysqli_connect($host_name, $user_name, $password, $database); 10 11 // check the connection 12 13 if (!$connect) { 14 die("Connection failed: " . mysqli_connect_error()); 15 } 16 //keep this in here to display all the errors on debugging 17 ini_set('display_errors', 1); 18 error_reporting(E_ALL); 19 //this is where the debugging portion ends 20 21 if (mysqli_query($connect, $mysqli)) { 22 echo "New record created successfully"; 23 } else { 24 echo "Error: " . $mysqli . "<br>" . mysqli_error($connect); 25 } 26 27 mysqli_close($connect); 28 29 // define variables and set to empty values 30 $first_name = $_POST['first_name']; 31 $last_name = $_POST['last_name']; 32 $phone_number = $_POST['phone_number']; 33 $address = $_POST['address']; 34 $city = $_POST['city']; 35 $state = $_POST['state']; 36 $zip = $_POST['zip']; 37 $email_address = $_POST['email_address']; 38 $country = $_POST['country']; 39 $comments = $_POST['comments']; 40 $join_mailing_list = $_POST['join_mailing_list']; 41 42 $first_nameErr = $last_nameErr = $phone_numberErr = $addressErr = $cityErr = $stateErr = $zipErr = $countryErr = $email_addressErr = $commentsErr = $join_mailing_listErr = ""; 43 $first_name = $last_name = $phone_number = $address = $city = $state = $zip = $country = $email_address = $comments = $join_mailing_list = ""; 44 45 $mysqli = "INSERT INTO nydatabase (first_name, last_name, phone_number, address, city, state, zip, country, email_address, comments, join_mailing_list) 46 VALUES ('$first_name','$last_name','$phone_number','$address','city','state','zip','$country','$email_address', '$comments','$join_mailing_list')"; 47 48 49 if ($_SERVER["REQUEST_METHOD"] == "POST") { 50 if (empty($_POST["first_name"])) { 51 $first_nameErr = "First name is required"; 52 } else { 53 $first_name = test_input($_POST["first_name"]); 54 if (!preg_match("/^[a-zA-Z ]*$/",$first_name)) { 55 $first_nameErr = "Only letters and white space allowed"; 56 } 57 } 58 if (empty($_POST["last_name"])) { 59 $last_nameErr = "Last name is required"; 60 } else { 61 $last_name = test_input($_POST["last_name"]); 62 if (!preg_match("/^[a-zA-Z ]*$/",$last_name)) { 63 $last_nameErr = "Only letters and white space allowed"; 64 } 65 } 66 if (empty($_POST["phone_number"])) { 67 $phone_numberErr = "Please enter a phone number"; 68 } else { 69 $phone_number = test_input($_POST["phone_number"]); 70 } 71 if (empty($_POST["address"])) { 72 $addressErr = "Address is required"; 73 } else { 74 $address = test_input($_POST["address"]); 75 } 76 77 if (empty($_POST["city"])) { 78 $cityErr = "City is required"; 79 } else { 80 $city = test_input($_POST["city"]); 81 if (!preg_match("/^[a-zA-Z ]*$/",$city)) { 82 $cityErr = "Only letters and white space allowed"; 83 } 84 } 85 if (empty($_POST["state"])) { 86 $stateErr = "State is required"; 87 } else { 88 $state = test_input($_POST["state"]); 89 if (!preg_match("/^[a-zA-Z ]*$/",$state)) { 90 $stateErr = "Only letters and white space allowed"; 91 } 92 } 93 94 if (empty($_POST["zip"])) { 95 $zipErr = "Zip is required"; 96 } else { 97 $zip = test_input($_POST["zip"]); 98 } 99 100 if (empty($_POST["country"])) { 101 $countryERR = "please enter your country"; 102 } else { 103 $country = test_input($_POST["country"]); 104 if (!preg_match("/^[a-zA-Z ]*$/",$country)) { 105 $countryErr = "Only letters and white space allowed"; 106 } 107 } 108 109 if (empty($_POST["email_address"])) { 110 $email_addressErr = "Email is required"; 111 } else { 112 $email_address = test_input($_POST["email_address"]); 113 if (!filter_var($email_address, FILTER_VALIDATE_EMAIL)) { 114 $email_addressErr = "Invalid email format"; 115 } 116 } 117 118 if (empty($_POST["comments"])) { 119 $comments = ""; 120 } else { 121 $comments = test_input($_POST["comments"]); 122 } 123 if (empty($_POST["join_mailing_list"])) { 124 $join_mailing_listErr = "requres a yes or no"; 125 } else { 126 $join_mailing_list = test_input($_POST["join_mailing_list"]); 127 } 128 129 function test_input($data) { 130 $data = trim($data); 131 $data = stripslashes($data); 132 $data = htmlspecialchars($data); 133 return $data; 134 } 135 } 136 ?> 137 <p><span class="error">* required field.</span></p> 138 <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="text/plain"> 139 First Name:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="First Name" required name="first_name" value="<?php echo $first_name;?>"><span class="error">* <?php echo $first_nameErr;?></span><br> 140 Last Name:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Last Name" required name="last_name" value="<?php echo $last_name;?>"><span class="error">* <?php echo $last_nameErr;?></span><br> 141 Phone:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Phone" required name="phone_number" size="50" value="<?php echo $phone_number;?>"><span class="error">* <?php echo $phone_numberErr;?></span><br> 142 Address:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Address" required name="address" value="<?php echo $address;?>"><span class="error">* <?php echo $addressErr;?></span><br> 143 City:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="City" required name="city" value="<?php echo $city;?>"><span class="error">* <?php echo $cityErr;?></span><br> 144 State:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="State" required name="state" value="<?php echo $state;?>"><span class="error">* <?php echo $stateErr;?></span><br> 145 Zip Code:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Zip" required name="zip" value="<?php echo $zip;?>"><span class="error">* <?php echo $zipErr;?></span><br> 146 Country:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Country" required name="country" value="<?php echo $country;?>"><span class="error">* <?php echo $countryErr;?></span><br> 147 Email Address:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Email Address" required name="email_address" value="<?php echo $email_address;?>"><span class="error">* <?php echo $email_addressErr;?></span><br> 148 Comment:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Message" required name="comments" size="75" value="<?php echo $comments;?>"><span class="error">* <?php echo $commentsErr;?></span><br> 149 Would you like to be on our mailing list?<input class="w3-radio" type="radio" name="join_mailing_list" <?php if (isset($join_mailing_list) && $join_mailing_list=="yes") echo "checked";?> 150 value="yes"><label>Yes</label> 151 <input class="w3-radio" type="radio" name="join_mailing_list" <?php if (isset($join_mailing_list) && $join_mailing_list=="no") echo "checked";?> 152 value="no"><label>No</label><span class="error">* <?php echo $join_mailing_listErr;?></span> 153 <br> 154 <input class="w3-input w3-padding-16 w3-border" type="datetime-local" placeholder="Date and time" required name="date" value="2017-11-16T20:00"><br> 155 <button class="w3-button w3-black"><input type="submit" name="submit" value="Submit"></button> 156 </form> 157 158 <?php 159 $email = "me@myemail.com"; 160 $emailSubject = "Inquiry from the Contact Page"; 161 162 $headers = "From:$email_address\r\n"; 163 $headers .= "Content-type: text/html\r\n"; 164 165 $body = <<<EOD 166 <br><hr><br> 167 First Name : $first_name <br> 168 Last Name : $last_name <br> 169 Phone Number : $phone_number <br> 170 Address : $address <br> 171 City : $city <br> 172 State : $state <br> 173 Zip : $zip <br> 174 Country : $country <br> 175 Email Address : $email_address <br> 176 Comments : $comments <br> 177 Subscribe to Mailing List : $join_mailing_list <br> 178 EOD; 179 180 $success = mail($email, $emailSubject, $body, $headers); 181 $usersuccess = mail($email_address, $emailSubject, $body, $headers); 182 echo "<h2>Thank you your message was received successfully. Here is a copy of what you sent us:</h2>"; 183 echo $first_name; 184 echo "<br>"; 185 echo $last_name; 186 echo "<br>"; 187 echo $phone_number; 188 echo "<br>"; 189 echo $address; 190 echo "<br>"; 191 echo $city; 192 echo "<br>"; 193 echo $state; 194 echo "<br>"; 195 echo $zip; 196 echo "<br>"; 197 echo $country; 198 echo "<br>"; 199 echo $email_address; 200 echo "<br>"; 201 echo $comments; 202 echo "<br>"; 203 echo $join_mailing_list; 204 205 mysqli_close($connect); 206 ?>
  23. Whoa! Lots of error messages when I added that tidbit of code. Thanks! I have some more work to do . Will check back in soon...
  24. Hi, I have spent hours on this and not figured it out. researched online extensively, and I'm sure I'm not the first one , but I haven't been able to figure it out. Help please? I have an action_page1.php script. I have an html contact form. I have a msqli db setup. The form looks ok on the html in the browser. The form seems to work alright when I enter the information, in so much that it seems to take the info and spit out a the return screen that says: "Connection to server successfully established. New record created successfully. Last inserted ID is: 9First Name: Last Name: Phone: Address: City: State: Zip: Email Address: Country: Comments: Subscribe to Mailing List?: Error connecting to database." Issues: 1. I don't know why it says "Error" connecting to database" at the end. huh? I know I programmed it in there, but I'm not sure why it's showing up there if the top says it's fine?! 2. How do I get the 'First Name" to sit under the ID instead of next to it? 3. When I go to see the record in the database, it is empty...why? here is a snap shot of what the records looks like: https://drive.google.com/open?id=1gPZEosBsouyo5hrkI_u4ZzB5Xanh35Vr 4. Why are the fields in the returned screen above, empty also? here is the script file: "<?php $host_name = "db......."; $database = "db......"; $user_name = "db......"; $password = ".........."; $connect = mysqli_connect($host_name, $user_name, $password, $database); if(mysqli_connect_errno()) { echo '<p>Failed to connect to Server: '.mysqli_connect_error().'</p>'; } else { echo '<p>Connection to server successfully established.</p>'; } $mysqli = "INSERT INTO contactpage (first_name, last_name, phone_number, address, city, state, zip, country, email_address, comments, join_mailing_list) VALUES ('$first_name','$last_name','$phone_number','$address','city','state','zip','$country','$email_address', '$comments','$join_mailing_list')"; if ($connect->query($mysqli) === TRUE) { $last_id = $connect->insert_id; echo "New record created successfully. Last inserted ID is: " . $last_id; } else { echo "Error: " . $mysqli . "<br>" . $connect->error; } // define variables and set to empty values $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $phone_number = $_POST['phone_number']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $email_address = $_POST['email_address']; $country = $_POST['country']; $comments = $_POST['comments']; $join_mailing_list = $_POST['join_mailing_list']; $first_nameErr = $last_nameErr = $phone_numberErr = $addressErr = $cityErr = $stateErr = $zipErr = $countryErr = $email_addressErr = $commentsErr = $join_mailing_listErr = ""; $email = "............."; $emailSubject = "test"; $headers = "From:$emailaddress\r\n"; $headers .= "Content-type: text/html\r\n"; $body = <<<EOD <br><hr><br> First Name : $first_name <br> Last Name : $last_name <br> Phone Number : $phone_number <br> Address : $address <br> City : $city <br> State : $state <br> Zip : $zip <br> Country : $country <br> Email Address : $email_address <br> Comments : $comments <br> Subscribe to Mailing List : $join_mailing_list <br> EOD; $success = mail($email, $emailSubject, $body, $headers); $theResults = <<<EOD "Thank you. Your message has been sent and you will be contacted soon" echo "<br>"; echo "<h2>Your Input:</h2>"; echo $first_name; echo "<br>"; echo $last_name; echo "<br>"; echo $phone_number; echo "<br>"; echo $address; echo "<br>"; echo $city; echo "<br>"; echo $state; echo "<br>"; echo $zip; echo "<br>" echo $country; echo "<br>"; echo $email_address; echo "<br>"; echo $comments; echo "<br>"; echo $join_mailing_list; echo "<br>"; EOD; echo "First Name: " . $first_name . "<br>"; echo "Last Name: " . $last_name . "<br>"; echo "Phone: " . $phone_number . "<br>"; echo "Address: " . $address . "<br>"; echo "City: " . $city . "<br>"; echo "State: " . $state . "<br>"; echo "Zip: " . $zip . "<br>"; echo "Email Address: " . $email_address . "<br>"; echo "Country: " . $country . "<br>"; echo "Comments: " . $comments . "<br>"; echo "Subscribe to Mailing List?: " . $join_mailing_list . "<br>"; $db = mysqli_connect("localhost","db..........","........."); if(!$db) die("Error connecting to database."); mysqli_select_db("db.........." ,$db); $mysqli = "INSERT INTO contactpage (first_name, last_name, phone_number, address, city, state, zip, country, email_address, comments, join_mailing_list) VALUES (". PrepmySQLi($varfirst_name) . ", " . PrepmySQLi($varlast_name) . ", " . PrepmySQLi($varphone_number) . ", " . PrepmySQLi($varaddress) . ", " . PrepmySQLi($varcity) . ", " . PrepmySQLi($varstate) . ", " . PrepmySQLi($varzip) . ", " . PrepmySQLi($varcountry) . ", " . PrepmySQLi($varemail_address) . ", " . PrepmySQLi($varcomments) . ", " . PrepSQL($varjoin_mailing_list) . ", " . mysqli_query($mysqli); if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["first_name"])) { $first_nameErr = "First name is required"; } else { $first_name = test_input($_POST["first_name"]); if (!preg_match("/^[a-zA-Z ]*$/",$first_name)) { $first_nameErr = "Only letters and white space allowed"; } } if (empty($_POST["last_name"])) { $last_nameErr = "Last name is required"; } else { $last_name = test_input($_POST["last_name"]); if (!preg_match("/^[a-zA-Z ]*$/",$last_name)) { $last_nameErr = "Only letters and white space allowed"; } } if (empty($_POST["phone_number"])) { $phone_numberErr = "Please enter a phone number"; } else { $phone_number = test_input($_POST["phone_number"]); } if (empty($_POST["address"])) { $addressErr = "Address is required"; } else { $address = test_input($_POST["address"]); } if (empty($_POST["city"])) { $cityErr = "City is required"; } else { $city = test_input($_POST["city"]); } if (empty($_POST["state"])) { $stateErr = "State is required"; } else { $state = test_input($_POST["state"]); } if (empty($_POST["zip"])) { $zipErr = "Zip is required"; } else { $zip = test_input($_POST["zip"]); } if (empty($_POST["country"])) { $countryERR = "please enter your country"; } else { $country = test_input($_POST["country"]); } if (empty($_POST["email_address"])) { $email_addressErr = "Email is required"; } else { $email_address = test_input($_POST["email_address"]); if (!filter_var($email_address, FILTER_VALIDATE_EMAIL)) { $email_addressErr = "Invalid email format"; } } if (empty($_POST["comments"])) { $comments = ""; } else { $comments = test_input($_POST["comments"]); } if (empty($_POST["join_mailing_list"])) { $join_mailing_listErr = "requres a yes or no"; } else { $join_mailing_list = test_input($_POST["join_mailing_list"]); } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } if($_POST['formSubmit'] == "Submit") { $varfirst_name = $_POST['first_name']; $varlast_name = $_POST['last_name']; $varphone_number = $_POST['phone_number']; $varaddress = $_POST['address']; $varcity = $_POST['city']; $varstate = $_POST['state']; $varzip = $_POST['zip']; $varcountry = $_POST['country']; $varemail_address = $_POST['email_address']; $varcomments = $_POST['comments']; $varjoin_mailing_list = $_POST['join_mailing_list']; $errorMessage = ""; // - - - snip - - - } echo "$theResults"; } $connect->close(); ?>" Thanks for any help you can offer!
×
×
  • Create New...