Jump to content

LivingLearning

Members
  • Content count

    9
  • Joined

  • Last visited

Community Reputation

0 Neutral

About LivingLearning

  • Rank
    Newbie
  1. Prepared statements: having trouble with PDO and Mariadb

    Hi and thanks for the response, I've changed the params as follows: // Prepare sql and bind parameters $stmt = $conn->prepare("INSERT INTO [test-survey1].favorites (FavMonster, FavVillian, FavMovie) VALUES (:Q1, :Q2, :Q3)"); $stmt->bindParam(':Q1', $Q1); $stmt->bindParam(':Q2', $Q2); $stmt->bindParam(':Q3', $Q3); Was that what you were referring to. This is my latest error after running it: Connection failed: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[test-survey1].favorites (FavMonster, FavVillian, FavMovie) VALUES ('Me', 'You',' at line 1 I can't help but feel that perhaps I'm not using the proper commands for my version of Mariadb or something like that. Is there a way/place to go to make sure that I'm using the correct commands for my ver of Mariadb and PDO. I can't seem to locate that info anywhere. I'm running MariaDB ver 10.1.26, Apache 2.4.27, and PHP 7.1.9 Definately getting confused on where to find the correct info to run now and is hindering the learning curve.
  2. Hi all, I've been working out my learning issues slowly and was able to figure out the process to communicate from html form to PDO to Mariadb fine. I decided to try to work with Prepared Statements via PDO into my Mariadb and am having some probs I can't get through. I'm trying to simplify things as much as possible so I can work it out, but don't think I've got it. Can anyone help point out a better approach to using prepared statements for a simple form with a few q's. I've scaled down my practice files to ease of use. I'm using my own Apache test server locally, w/ latest ver of apache and Mariadb 10.1.26 on windows 8.1 Here is simple html file: <!doctype html> <html lang="en-US"> <!-- ###################################################################################################/--> <!-- Main Page for Monsters of SciFi Tribute -- Testing Only /--> <!-- ###################################################################################################/--> <head> <meta charset="UTF-8"> <title>SciFi Monsters</title> <link href="http://localhost/CheckFormData.php" type="text/php" rel="stylesheet"> </head> <body> <br> <br> <br> <!-- This section is for: Take a quick Godzilla survey /--> <div id="survey-div"> <form action = "CheckFormData.php" method = "post"> <fieldset id="survey-fieldset"> <legend>Take one of our quick surveys.</legend> <p> <label>1. Who is your <strong>favorite monster</strong> character (Godzilla related or not):</label> <input id="FavMonster" name="FavMonster" type="text" value="" /> </p> <p> <label>2. Who is your <strong>favorite villian</strong>:</label> <input id="FavVillian" name="FavVillian" type = "text" /> </p> <p> <label>3. What is your <strong>favorite monster related movie</strong>:</label> <input id="FavMovie" name="FavMovie" type = "text" /> </p> <p> <label>Press 'Submit' when you are done.</label> <input type="submit" value="Submit" name="submit_button" /> </p> </fieldset> </form> </div> </body> </html> Here is my CheckFormData.php test file (what a mess, haha): <!DOCTYPE html> <html lang = "en-US"> <head> <meta charset = "UTF-8"> <title>CheckFormData.php</title> </head> <!-- The attempt with this file is to verify all user entered data is formatted correctly, then establish a database connection, and attempt to communicate that data to the database, all from one file. /--> <body> <?php // define variables and set to empty values // 1st - Set variables for form array $_POST $SurveyForm = $_POST; $Q1 = $SurveyForm['FavMonster']; $Q2 = $SurveyForm['FavVillian']; $Q3 = $SurveyForm['FavMovie']; // Set any functions up // validate all form data function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } // We are NOT testing for 'required' fields if ($_SERVER["REQUEST_METHOD"] == "POST") { //Start validation on all Q's test_input($Q1); test_input($Q2); test_input($Q3); // Start move validation if (!preg_match("/^[a-zA-Z ]*$/",$Q1)) { $SQErr = "Only letters and white space allowed"; } if (!preg_match("/^[a-zA-Z ]*$/",$Q2)) { $SQErr = "Only letters and white space allowed"; } if (!preg_match("/^[a-zA-Z ]*$/",$Q3)) { $SQErr = "Only letters and white space allowed"; } } // OK, presuming my validations are working, now attempt to connect to database // PDO connection check $servername = "localhost"; $username = "Any"; $password = "BurgerKing"; $dbname = "test-survey1"; try { //Attempt MySQL server connection $conn = new PDO("mysql:host=$servername; dbname=$dbname", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Prepare sql and bind parameters $stmt = $conn->prepare("INSERT INTO [test-survey1].favorites (FavMonster, FavVillian, FavMovie) VALUES (:Q1, :Q2, :Q3)"); $stmt->bindParam(':FavMonster', $Q1); $stmt->bindParam(':FavVillian', $Q2); $stmt->bindParam(':FavMovie', $Q3); $Q1; $Q2; $Q3; $stmt->execute(); echo "New records created successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } $conn = null; ?> </body> </html> ** What this all gives me right now is: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
  3. Pressing 'Submit' on html form brings blank page

    Hi there, I think I got that issue worked out. (But can't be sure, since I only get a blank page when I hit the submit button now and no other messages). Any thoughts on what I'm missing for this 'blank page' issue and how could I better set this up to see if it is working correctly. My next step after this is to pass it to the database, but I figured I'd try to setup each piece step-by-step so I could test/see how it works better. When you press the 'submit' button, what should people really see. Thanks, Any chance anyone would be interested in helping me more via 'pm' or is this the best route. I've done all the reading I can, but can't quite get to the carrot!!
  4. Pressing 'Submit' on html form brings blank page

    Hi and thanks for the response. I checked all my <input> lines and made sure they all have a 'name=' entry and tested it again. I get same results. I have both my MainPage.html and GetFormData.php file in my 'htdocs' folder as expected ad I read that a regular browser check of this won't work because PHP is not understood by regular browser session without going through my Apache Web Server. So, with that up and going, here is my result when I hit the Submit button: Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\GetFormData.php on line 38 Atleast this is something different then I've been getting so far. So, i'm at this point, is there anything wrong with the syntax of my GetFormData.php file from what anyone can see. My eyes are crossing, lol. I've run through syntax checker, but you know how good that is. Please let me know, i'm very interested in keeping this going so i can figure it out and continue learning and moving forward. I'm sure it's pretty straight forward, I just don't know enough yet.
  5. Pressing 'Submit' on html form brings blank page

    Hi all, Having some problems getting my HTML <form> to work correctly when I press the 'Submit' button. When I put data in the 'text' field and then press Submit, the page goes 'white' with no response, but the URL is still the same. What I'm really trying to do at this point, is to just make sure that my <form> and related GetFormData.php file are setup correct as I get ready to try to send data to my mariadb on my local test server. Have checked out a lot of forum posts, but not finding the missing link, lol. Using my test web site for fun: Here are important parts from MainPage Html file (<form> section has 5 q's, I'll pull 1st): ** This line in the <head> section: <link href="http://localhost/GetFormData.php" type="text/php" rel="stylesheet"> ** Here is <form> from <body>: <!-- This section is for: Take a quick Godzilla survey /--> <div id="survey-div"> <form id="survey-form" class="MainPgTxtBckgColor" action = "GetFormData.php" method = "post"> <fieldset id="survey-fieldset"> <legend>Take one of our quick surveys.</legend> <p> <label>1. Who is your <strong>favorite monster</strong> character (Godzilla related or not):</label> <input id="FavMonster" type = "text" value = "" /> </p> <p> <label>Press 'Submit' when you are done.</label> <input type="submit" value="Submit" name="submit_button"> </p> </fieldset> </form> </div> ** Here is contents of GetFormData.php file: <!DOCTYPE html> <html lang = "en-US"> <head> <meta charset = "UTF-8"> <title>GetFormData.php</title> </head> <body> <p> <?php // define variables and set to empty values $favmonsterErr = ""; $favmonster = ""; // verify that field is not empty if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["favmonster"])) { $favmonsterErr = "Favorite Monster is required"; } else { $favmonster = test_input($_POST["favmonster"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$favmonster)) { $favmonsterErr = "Only letters and white space allowed"; } } // validate all form data function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> </body> </html> ** Am I missing something with how <form> Submits work or am I just, missing something!
  6. Proper steps for testing my mariadb connection

    Hi guys, Am still new at this, so be patient with me. I have my local xampp test server all setup and appears to be working fine. Am ready to test connection from my html form - PHP (PDO) - mariadb I'm getting a bit lost in all the manuals for the proper placement and setup. Am using win8.1 and current recommended ver of xampp. Latest release. Briefly: I have a simple html form set up (to test off of one simple survey q). I'll post all code below. <form> has --- action = "GetFormData.php" method = "post" ---set Submit button set as follows in html file under <form>: <label>Press 'Submit' when you are done.</label> <input type="submit" value="Submit" name="submit_button"> Basically, i'm confused on the exact steps/(.php) files I need to use in order to get the form data (and validate it), then setup and test a mariadb connection, then to pass that data to the database. Is it all done in one .php file on the server side, or should I be having multiple files for each step? I understand that the .php file that works with the <form> data should be on server side, so i have it under my 'htdocs' folder in test server (localhost). I keep checking in the faq and other W3Schools tutorial areas, but am missing the bigger picture on the proper setup somewhere and what goes where. And, what is best way to manually test the .db connection. From a command line somehow or through some control panel? -------------------- my scripts are as follows so far: Main pg html file containing <form> i'm testing: (only pieces in question) <head> <meta charset="UTF-8"> <title>SciFi Monsters</title> <link href="Framework-MonstersOfSciFi.css" type="text/css" rel="stylesheet"> <link href="style-MainPg.css" type="text/css" rel="stylesheet"> <link href="/localhost/GetFormData.php" type="text/php" rel="stylesheet"> <link href="/localhost/testConnect.php" type="text/php" rel="stylesheet"> </head> (further down, here is the survey part (part i'm testing only): <div id="survey-div"> <form id="survey-form" class="MainPgTxtBckgColor" action = "GetFormData.php" method = "post"> <fieldset id="survey-fieldset"> <legend>Take one of our quick surveys.</legend> <p> <label>1. Who is your <strong>favorite monster</strong> character (Godzilla related or not):</label> <input id="FavMonster" type = "text" /> </p> (there are only 5 survey q's, so not posting all. Only testing one) That's it for the main html file. (I only have one form for this site, just building and playing with things to learn first.) -------------------------------------------------- Now for the .php files: First: The 'GetFormData.php file (under localhost/htdocs) This file is setup, from what I've read about so far, to get the form data and sanitize it. (not sure if I should have something else in here, or if the .db connection .php file should go in here as well.) <!DOCTYPE html> <html lang = "en-US"> <head> <meta charset = "UTF-8"> <title>GetFormData.php</title> </head> <body> <p> <?php // define variables and set to empty values $favmonsterErr = ""; $favmonster = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["favmonster"])) { $favmonsterErr = "Favorite Monster is required"; } else { $favmonster = test_input($_POST["favmonster"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$favmonster)) { $favmonsterErr = "Only letters and white space allowed"; } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> </p> </body> </html> ---------------------------------------- Now the testConnect.php file: This file is setup to make a test connection to the .db. After this, should i have another .php script, which would then try to post the data to the .db, or does it all happen in one .php file. <!DOCTYPE html> <html lang = "en-US"> <head> <meta charset = "UTF-8"> <title>testConnect.php</title> </head> <body> <p> <?php $servername = "localhost"; $username = "Any"; $password = "McG1v3r-9"; try { $conn = new PDO("mysql:host=$servername;dbname=test-survey1", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } ?> </p> </body> </html> --------------------- This is all I have for now. Getting a bit confused on the proper setup of stuff. Thanks in advance,
  7. Which Apache ver to use: 2.2 or 2.4

    Hi all, thanks for the input. I'll go with the latest release of things from the recommended site and take it from there. Let's see how things go.
  8. Hi all. I'll try to be direct with the details. I've installed a test server on my development pc (HP Envy, specs are fine) running win 8.1. I used the 'xampp-win32-7.1.9-0-VC14-install' from the preferred site. Installation went fine, no noted errors in any logs. I changed the psswd for MySQL as suggested. (No prob there) I can bring up the XAMPP control panel from command line fine (administrator priv) and I can start up Apache, MySQL just fine. (logs all good) (I'm not sure if I should be starting up the 'Tomcat' piece of the pie as well though, can't get a grip on what piece that plays in this picture.) I won't be using the 'FileZilla' or 'Mercury' piece at the moment. I can get into MySql and do stuff in there just fine via command line execution of the Control Panel (V3.2.2) My problem is this. I cannot figure out how to bring up Apache Control Panel via localhost. This has eluded me for some time now. I've read through dozens of posts from diff forums and still am not seeing the light on this issue. Using FireFox or Chrome, when I type in "http://localhost/xampp" all i get is the default Dashboard. (like lots of other users have gotten, but I can't get an answer on this that I can understand. I have all this installed under "c:/xampp and in the ~/htdocs folder I do have an index.php file. I've moved that and still cannot get control panel to come up. I'm thinking this might be a 'Path' issue, and there are not xampp files under that htdocs folder, since they shouldn't be there for public use i thought. They are in a diff folder. Perhaps that is just my problem. I just need to tell it to look in a diff place. All the ports are default settings, not changed, and am not detecting any conflicts with any application port usage. I'm just not sure on the proper use of this browser accessible approach still, lol. Any suggestions.
  9. Which Apache ver to use: 2.2 or 2.4

    Hi all, I'm leaning all this web server stuff and am enjoying it so far. Have done all the reading on HTML, CSS, JS, MySql, PHP. Am at a point where I need to create a test server to mash it all together. I am running on Win 8.1 (64bit) (I can run 32bit fine, no prefference), and my test server will be my development pc. It is an HP Envy fully stacked, haha! I'm running Norton software for firewall as well as MBAM for added protection. I have created 'flat' web pages for practice and am looking forward to linking the MySQL/PHP side into things, so I can continue the learning curve more appropriately. My q is simple. Should I go with the latest ver of Apache (2.4) or stick with Apache (2.2). I have no preferences, so it shouldn't really matter. I'm NOT looking to go live host for web pages until I feel much more comfortable with the whole circle of things here, LOL. It's just time for this test server setup and keep on learning. I've read through the FAQ's on this site about it, but that post is a bit old now. Hence my double check on the Apache Ver. I also noticed that if I tried to install via the XAMPP option, it seems to have a MariaDB instead of MySQL?? Is this just a joke on newbies (haha) or have they switched it out. I'd probably rather stay with MySQL for kicks. Thanks in advance,
×