Jump to content

osherdo

Members
  • Posts

    41
  • Joined

  • Last visited

Everything posted by osherdo

  1. Well done, thank you very much sir!. I figured that out with your help. Could you refer me to the specific page in the php documentation that shows more info about that issue?
  2. So I have this code: <?php $user = "clicrckc_osherdo"; $pass = "3563077"; $CurrentUser= $_SESSION['user_id']; try { $dbh = new PDO('mysql:host=localhost;dbname=clicrckc_andfit', $user, $pass); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "connected successfully"; print_r($_SESSION); $UserName = $dbh->prepare("SELECT first_name,last_name FROM users WHERE user_id = ?"); $UserName->bindParam(1, $CurrentUser); $UserName->execute(); $UserName->fetch(PDO::FETCH_ASSOC); $dbh = null; } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br/>"; die(); } ?> <div id="PersonalDetails">Hello dear <?= $UserName ?>!</div> I am trying to insert the current username in the session to the html code where $Username is. I cannot find out why it wont work. I am getting the following message, instead of the current username in the session: Catchable fatal error: Object of class PDOStatement could not be converted to string in/home/clicrckc/public_html/dashboard.phpon line136 I have tried to google the issue but I could not address the issue. please- help anyone? Thank you.
  3. I will get down on it. This topic seems so complex. Although, you did gave me some headstart to go from. Thank you, and I will update here as soon as I get this topic solved.
  4. When should i start the session? and where? in the registration page or at the dashboard, the page that the user is redirected after registration?
  5. Hello everyone. I have a fully working form that gets data from a user (with $_post array) , and stores it in a database (mysql). After successfulIy filling the form, I refer him to the "dashboard" page. In this page, i am having trouble to get his details from the database. How should I recognize him as the user that just registered? should I use a $_post? or maybe a session? could you please give me a clue how to solve this?
  6. Just figured it out. Used The ALTER TABLE & MODIFY statement to extend the char limit for the desired column: Working example: http://imgur.com/hkADy4J ALTER TABLE tablename MODIFY columnname VARCHAR(150);
  7. Hello Guys. I am having a trouble viewing a specific column content both in phpMyAdmin and console.It only shows a partial info about the contents inside that column. I have attached a screenshot of this to give you a demonstration inside that link: http://i59.tinypic.com/2n6ymqf.jpg as you can see , the user picked hamburger ,steak and ground beef (and some more), but it seems that it stops showing it right in the middle of the word. Is there any limit for characters in this case? What would be possible to figure that out please? Thanks in advance..
  8. Working Code: <html> <head> <meta charset="UTF-8"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <!-- Load Jquery --> <script> $(document).ready(function(){ //Specify a function to execute when the DOM is fully loaded. $("button").click(function(){ // הפעלת פקודה על הכפתור. $("#SignUpButton").remove(); // Remove the SignUpButton onclick. }); }); </script> <!-- below is the tag that allows reading the css settings from an external .css file. --> <link rel="stylesheet" type="text/css" href="CSSFILE.css"> </head> <title>Welcome to Click-And-Fit website.Soon you'll be in better shape!</title> <body> <img src="Demo_Photo.jpg" class="Demo_Photo" alt="CAF Demo Image" height=350 width="300"> <img src="Click_and_Fit!.jpg" class="Logo" alt="Click And Fit logo" height="200" width="200"> <p style="text-align: center"> Welcome to Click-And-Fit!<br> <br>Would you like to make a change in your life? <br> <br> <FONT COLOR="#551A8B"><b>Click-And-Fit</b></FONT><br> <br> Let's make this change happen by sign up to our website with the following form beyond.<br> <br> You need to provide some of your daily lifestyle habits. (e.g.:Like if you're a smoker) </p> <br> <br> <br> <div class="container"> <a href="" class="button"><strong>Already have an account?</strong></a> </div> <div align="center"> <form action="" id="SignUpForm" autocomplete="on" style="display: none" method="post"> <!-- Form is Hidden until the user is clicking the "Sign Up" button. --> <input type="hidden" name="Language" value="English"> Fill up the following fields:<br> <br> First name:<input type="text" name="fname" required><br> <br> Last name: <input type="text" name="lname" required><br> <br> Age: <input type="number" name="UserAge" min="1" max="120" required><br> <br> Gender: <input type="radio" name="Gender" value="male">Male<br> <input type="radio" name="Gender" value="Female">Female<br> E-mail Address: <input type="email" name="email" autocomplete="off" required><br> <br> Pick your new password: <input type="password" maxlength=”40” name="Password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,40}"> Add password strength checker here.<br> <br> <!-- Uses regular expression. --> Confirm Password: <input type="password" maxlength=”40” name="ConfirmPassword" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,40}"><br> <br> <!-- A better way is to use onblur to check user's type match. --> <hr> <script> (function(){ $("#submit").click(function(){ $(".error").hide(); //Bind an event handler to the "error" JavaScript event. var hasError = false; var passwordVal = $("#Password").val(); var checkVal = $("#ConfirmPassword").val(); if (passwordVal == '') { $("#Password").after('<span class="error">Please enter a password.</span>'); hasError = true; } else if (checkVal == '') { $("#ConfirmPassword").after('<span class="error">Please re-enter your password.</span>'); hasError = true; } else if (passwordVal != checkVal ) { $("#ConfirmPassword").after('<span class="error">Passwords do not match.</span>'); hasError = true; } if(hasError == true) {return false;} }); }); </script> <script> //The validationMessage property of a DOM node contains the message the browser displays to the user when a node's validity is checked and fails. document.getElementById("name").validationMessage; document.getElementById("lname").validationMessage; document.getElementById("UserAge").validationMessage; document.getElementById("Gender").validationMessage; document.getElementById("email").validationMessage; document.getElementById("Password").validationMessage; document.getElementById("ConfirmPassword").validationMessage; </script> Now let's go through your prefered food. Check the appropriate boxed beyond.<br> <br> This will help us to better understand your food discipline:<br> <p style="text-align: center"> <b> Meat And Poultry:</b> </p> <div id="MeatCheckBox"> <input type="checkbox" name="FoodTypes[]" value="Hamburger">Hamburger<br> <input type="checkbox" name="FoodTypes[]" value="Steak">Steak<br> <input type="checkbox" name="FoodTypes[]" value="GroundBeef">Ground Beef<br> <input type="checkbox" name="FoodTypes[]" value="Bacon">Bacon<br> <input type="checkbox" name="FoodTypes[]" value="Beef">Beef<br> <input type="checkbox" name="FoodTypes[]" value="Salami">Salami<br> <input type="checkbox" name="FoodTypes[]" value="Chicken">Chicken (In all its forms)<br> <input type="checkbox" name="FoodTypes[]" value="NoMeat">I don't eat meat at all (Vegeterian/Vegan)<br> </div> <p style="text-align: center"> <b> Fish And Seafood:</b> </p> <div id="FishAndSeaFood"> <input type="checkbox" name="FoodTypes[]" value="Fish">Fish<br> <input type="checkbox" name="FoodTypes[]" value="Sushi">Sushi<br> <input type="checkbox" name="FoodTypes[]" value="CannedFish">Canned Fish<br> <input type="checkbox" name="FoodTypes[]" value="Oysters">Seafood<br> <input type="checkbox" name="FoodTypes[]" value="SmokedSalmon">Smoked Salmon<br> </div> <div id="Vegetables"> <p style="text-align: center"> <b> Do you eat vegtables?</b> </p> <br> <input type="radio" name="YesOrNo" value="Yes">Yes <!-- Give both options the same name,Because they are related. --> <input type="radio" name="YesOrNo" value="No">No<br> </div> <hr> <p>Do you workout as part of your lifestyle?</p> <br> <input type="radio" name='workout_options' value='valuable' data-id="DoWorkout" class="workout_options" /> I do workout occasionally <input type="radio" name='workout_options' value='valuable' data-id="DoNotWorkout" class="workout_options" /> I am not working out<br> <br> <br> <section> <div id=DoWorkout class="workout_options"> <p> We see you're not having any exercise at the moment.<br> <br>Did you know that doing some kind of activity like running or cardio 3 times a week improve your life quality?<br> <br>We'll help you go straight from zero to hero! </p> </div> <div id=DoNotWorkout class="workout_options"> What type of workout you're working on at the moment? Please choose from the options beyond:<br> <br> <br> <input type="checkbox" name="Cardio" value="Cardio" data-id="Cardio" />Cardio/Aerobics<br> <br> <input type="checkbox" name=" Weight_Lifting" value=" Weight_Lifting" data-id="Weight_Lifting" />Weight Lifting/ Anaerobics </div> <br> </section> <input type="submit" value="Submit Details" name="SubmitDetails" id="SubmitDetails"> </div> </form> <p style="text-align: center;"> <a href="#" id="Learn_More"> Learn more about Click-And-Fit</a> </p> <div id="clickme"> <p align="center"> <button type="submit" id="SignUpButton" name="SignUpButton" class="SignUpButton"> <p style="font-size: 30px;">Sign Up</p> <br> <span style="font-family: Consolas; font-size: 20px;"> (I am ready for the challenge!)</span> </button> </p> </div> <!-- Show form on click. --> <script> $( "#clickme" ).click(function() { $( "#SignUpForm" ).show( "slow", function() { // Animation complete. }); }); </script> <!-- script for the exercise options --> <script type="text/javascript"> $(':radio').change(function (event) { // when any radio button changes, var id = $(this).data('id'); // get the id from data-id $('#' + id) // find the div with that id. .addClass('workout_options') // give it the class .siblings().removeClass('workout_options'); // and remove the class from all it’s siblings // siblings are nodes before and after with the same parent. }); </script> </body> </html> PHP: <?php require('password_compat-master/lib/password.php'); //backward compatibility for the passord_hash function. ini_set('error_reporting',E_ALL^E_NOTICE); //Server initial configuration. $servername = "localhost"; $username = "root"; $password = "3563077"; $dbname = "caf_users"; try { $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 //Values in the query below are parameterized queries. $stmt = $conn->prepare("INSERT INTO users (Food_Types,first_name,last_name,gender,Email_Address,Password,User_Age,workout_options,Registration_Date) VALUES (?,?,?,?,?,?,?,?,?)"); //While binding parameters,the second parameter will always be a variable. $stmt->bindParam('1',$FoodTypes); $stmt->bindParam('2',$fname); $stmt->bindParam('3',$lname); $stmt->bindParam('4',$Gender); $stmt->bindParam('5',$email); $stmt->bindParam('6',$Password); $stmt->bindParam('7',$UserAge); $stmt->bindParam('8',$workout_options); $stmt->bindParam('9',$Registration_Date); // insert a row if (isset($_POST['SubmitDetails'])) { $FoodTypes=implode(':',$_POST["FoodTypes"]); // $FoodTypes will contain all values glued together with a ';' in between them. $fname=$_POST["fname"]; $lname=$_POST["lname"]; $Gender=$_POST["Gender"]; $email=$_POST["email"]; $Password=$_POST["Password"]; $ConfirmPassword=$_POST["ConfirmPassword"]; //check if user entered the exact password twice. if($Password == $ConfirmPassword) { $hash = password_hash($Password, PASSWORD_DEFAULT); } // The first parameter is the password string that needs to be hashed, //and the second parameter specifies the algorithm that should be used for generating the hash. //encrypted by bcrypt algorithm. else { echo "Passwords are mismatched. Please try again."; }; $UserAge=$_POST["UserAge"]; $workout_options=$_POST["workout_options"]; $Registration_Date=date("Y-m-d H:i:s"); $stmt->execute(); /* insert another row $firstname = "Mary"; $lastname = "Moe"; $email = "mary@example.com"; $stmt->execute(); // insert another row $firstname = "Julie"; $lastname = "Dooley"; $email = "julie@example.com"; $stmt->execute(); */ echo "New records created successfully"; }} catch(PDOException $e) { echo "Error: " . $e->getMessage(); } $conn = null; //Disconnect. ?>
  9. Hi! i have worked through this, and figured it out! there was some mess with the query single qoute positions and brackets and double quote position as well. All fixed and works perfect, and now I can finally insert data into the database! Although,data is not shown completely on the mysql table- specifically an array of choices,but I will open a new thread about it. Thank you for your consistent help, I am now more aware of errors in the process. Could you also please explain and demostrate can I echo the contents of my sql query in case I am using $conn as a connection parameters, and then point it to the query itself? (Like it's done in the case of this thread). Thanks.
  10. Hi guys. I have tried your suggestions and made some changes to the code. It don't bring any errors on page loading. but it do show error when I try to sumbit the details to the server. Again i receive a message code like that: Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2 line 2 is my html code, and i don't understand what I have to do with that. Here's an updated code of the html and php codes: <html> <head> <meta charset="UTF-8"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <!-- Load Jquery --> <script> $(document).ready(function(){ //Specify a function to execute when the DOM is fully loaded. $("button").click(function(){ // הפעלת פקודה על הכפתור. $("#SignUpButton").remove(); // Remove the SignUpButton onclick. }); }); </script> <!-- below is the tag that allows reading the css settings from an external .css file. --> <link rel="stylesheet" type="text/css" href="CSSFILE.css"> </head> <title>Welcome to Click-And-Fit website.Soon you'll be in better shape!</title> <body> <img src="Demo_Photo.jpg" class="Demo_Photo" alt="CAF Demo Image" height=350 width="300"> <img src="Click_and_Fit!.jpg" class="Logo" alt="Click And Fit logo" height="200" width="200"> <p style="text-align: center"> Welcome to Click-And-Fit!<br> <br>Would you like to make a change in your life? <br> <br> <FONT COLOR="#551A8B"><b>Click-And-Fit</b></FONT><br> <br> Let's make this change happen by sign up to our website with the following form beyond.<br> <br> You need to provide some of your daily lifestyle habits. (e.g.:Like if you're a smoker) </p> <br> <br> <br> <div class="container"> <a href="" class="button"><strong>Already have an account?</strong></a> </div> <div align="center"> <form action="" id="SignUpForm" autocomplete="on" style="display: none" method="post"> <!-- Form is Hidden until the user is clicking the "Sign Up" button. --> <input type="hidden" name="Language" value="English"> Fill up the following fields:<br> <br> First name:<input type="text" name="fname" required><br> <br> Last name: <input type="text" name="lname" required><br> <br> Age: <input type="number" name="UserAge" min="1" max="120" required><br> <br> Gender: <input type="radio" name="Gender" value="male">Male<br> <input type="radio" name="Gender" value="Female">Female<br> E-mail Address: <input type="email" name="email" autocomplete="off" required><br> <br> Pick your new password: <input type="password" maxlength=”40” name="Password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,40}"> Add password strength checker here.<br> <br> <!-- Uses regular expression. --> Confirm Password: <input type="password" maxlength=”40” name="ConfirmPassword" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,40}"><br> <br> <!-- A better way is to use onblur to check user's type match. --> <hr> <script> (function(){ $("#submit").click(function(){ $(".error").hide(); //Bind an event handler to the "error" JavaScript event. var hasError = false; var passwordVal = $("#Password").val(); var checkVal = $("#ConfirmPassword").val(); if (passwordVal == '') { $("#Password").after('<span class="error">Please enter a password.</span>'); hasError = true; } else if (checkVal == '') { $("#ConfirmPassword").after('<span class="error">Please re-enter your password.</span>'); hasError = true; } else if (passwordVal != checkVal ) { $("#ConfirmPassword").after('<span class="error">Passwords do not match.</span>'); hasError = true; } if(hasError == true) {return false;} }); }); </script> <script> //The validationMessage property of a DOM node contains the message the browser displays to the user when a node's validity is checked and fails. document.getElementById("name").validationMessage; document.getElementById("lname").validationMessage; document.getElementById("UserAge").validationMessage; document.getElementById("Gender").validationMessage; document.getElementById("email").validationMessage; document.getElementById("Password").validationMessage; document.getElementById("ConfirmPassword").validationMessage; </script> Now let's go through your prefered food. Check the appropriate boxed beyond.<br> <br> This will help us to better understand your food discipline:<br> <p style="text-align: center"> <b> Meat And Poultry:</b> </p> <div id="MeatCheckBox"> <input type="checkbox" name="FoodTypes[]" value="Hamburger">Hamburger<br> <input type="checkbox" name="FoodTypes[]" value="Steak">Steak<br> <input type="checkbox" name="FoodTypes[]" value="GroundBeef">Ground Beef<br> <input type="checkbox" name="FoodTypes[]" value="Bacon">Bacon<br> <input type="checkbox" name="FoodTypes[]" value="Beef">Beef<br> <input type="checkbox" name="FoodTypes[]" value="Salami">Salami<br> <input type="checkbox" name="FoodTypes[]" value="Chicken">Chicken (In all its forms)<br> <input type="checkbox" name="FoodTypes[]" value="NoMeat">I don't eat meat at all (Vegeterian/Vegan)<br> </div> <p style="text-align: center"> <b> Fish And Seafood:</b> </p> <div id="FishAndSeaFood"> <input type="checkbox" name="FoodTypes[]" value="Fish">Fish<br> <input type="checkbox" name="FoodTypes[]" value="Sushi">Sushi<br> <input type="checkbox" name="FoodTypes[]" value="CannedFish">Canned Fish<br> <input type="checkbox" name="FoodTypes[]" value="Oysters">Seafood<br> <input type="checkbox" name="FoodTypes[]" value="SmokedSalmon">Smoked Salmon<br> </div> <div id="Vegetables"> <p style="text-align: center"> <b> Do you eat vegtables?</b> </p> <br> <input type="radio" name="YesOrNo" value="Yes">Yes <!-- Give both options the same name,Because they are related. --> <input type="radio" name="YesOrNo" value="No">No<br> </div> <hr> <p>Do you workout as part of your lifestyle?</p> <br> <input type="radio" name='workout_options' value='valuable' data-id="DoWorkout" class="workout_options" /> I do workout occasionally <input type="radio" name='workout_options' value='valuable' data-id="DoNotWorkout" class="workout_options" /> I am not working out<br> <br> <br> <section> <div id=DoWorkout class="workout_options"> <p> We see you're not having any exercise at the moment.<br> <br>Did you know that doing some kind of activity like running or cardio 3 times a week improve your life quality?<br> <br>We'll help you go straight from zero to hero! </p> </div> <div id=DoNotWorkout class="workout_options"> What type of workout you're working on at the moment? Please choose from the options beyond:<br> <br> <br> <input type="checkbox" name="Cardio" value="Cardio" data-id="Cardio" />Cardio/Aerobics<br> <br> <input type="checkbox" name=" Weight_Lifting" value=" Weight_Lifting" data-id="Weight_Lifting" />Weight Lifting/ Anaerobics </div> <br> </section> <input type="submit" value="Submit Details" name="SubmitDetails" id="SubmitDetails"> </div> </form> <p style="text-align: center;"> <a href="#" id="Learn_More"> Learn more about Click-And-Fit</a> </p> <div id="clickme"> <p align="center"> <button type="submit" id="SignUpButton" name="SignUpButton" class="SignUpButton"> <p style="font-size: 30px;">Sign Up</p> <br> <span style="font-family: Consolas; font-size: 20px;"> (I am ready for the challenge!)</span> </button> </p> </div> <!-- Show form on click. --> <script> $( "#clickme" ).click(function() { $( "#SignUpForm" ).show( "slow", function() { // Animation complete. }); }); </script> <!-- script for the exercise options --> <script type="text/javascript"> $(':radio').change(function (event) { // when any radio button changes, var id = $(this).data('id'); // get the id from data-id $('#' + id) // find the div with that id. .addClass('workout_options') // give it the class .siblings().removeClass('workout_options'); // and remove the class from all it’s siblings // siblings are nodes before and after with the same parent. }); </script> </body> </html> PHP: <?php require('password_compat-master/lib/password.php'); //backward compatibility for the passord_hash function. ini_set('error_reporting',E_ALL^E_NOTICE); //Server initial configuration. $servername = "localhost"; $username = "root"; $password = "3563077"; $dbname = "caf_users"; try { $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 //Values in the query below are parameterized queries. $stmt = $conn->prepare("INSERT INTO users (Workout,first_name,last_name,gender,Email_Address,Password,User_Age,workout_options,Registration_Date) VALUES (?,?,?,?,?,?,?,?,?"); $stmt->bindParam(1,$YesOrNo); $stmt->bindParam(2,$fname); $stmt->bindParam(3,$lname); $stmt->bindParam(4,$Gender); $stmt->bindParam(5,$email); $stmt->bindParam(6,$Password); $stmt->bindParam(7,$UserAge); $stmt->bindParam(8,$workout_options); $stmt->bindParam(9,$Registration_Date); // insert a row if (isset($_POST['SubmitDetails'])) { $YesOrNo=$_POST["YesOrNo"]; $fname=$_POST["fname"]; $lname=$_POST["lname"]; $Gender=$_POST["Gender"]; $email=$_POST["email"]; $Password=$_POST["Password"]; $ConfirmPassword=$_POST["ConfirmPassword"]; //check if user entered the exact password twice. if($Password == $ConfirmPassword) { $hash = password_hash($Password, PASSWORD_DEFAULT); } // The first parameter is the password string that needs to be hashed, //and the second parameter specifies the algorithm that should be used for generating the hash. //encrypted by bcrypt algorithm. else { echo "Passwords are mismatched. Please try again."; }; $UserAge=$_POST["UserAge"]; $workout_options=$_POST["workout_options"]; $Registration_Date=date("Y-m-d H:i:s"); $stmt->execute(); /* insert another row $firstname = "Mary"; $lastname = "Moe"; $email = "mary@example.com"; $stmt->execute(); // insert another row $firstname = "Julie"; $lastname = "Dooley"; $email = "julie@example.com"; $stmt->execute(); */ echo "New records created successfully"; }} catch(PDOException $e) { echo "Error: " . $e->getMessage(); } $conn = null; //Disconnect. ?>
  11. Hello people i have been working on debugging my project according to your solutions. I have now switched to PDO and using prepared statements. My only problem is I cannot insert the registration date to the database. the column 'Registration_Date' in the database (MySQL) is in type 'DATETIME' , and I been digging for hours for the format I should be inserting the query,but no success there. I should mentioned the error message the MySQL server return is: Error: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined I have tried many possible syntaxes, and I have got many errors. Tried to fix them but without any success. I also suspect this variable: $Registration_Date is part of the issue. Please have a look in my updated code ,and you may be able to help me. Thank you so much!! PHP code: <?php require('password_compat-master/lib/password.php'); //backward compatibility for the passord_hash function. ini_set('error_reporting',E_ALL^E_NOTICE); //Server initial configuration. $servername = "localhost"; $username = "root"; $password = "3563077"; $dbname = "caf_users"; try { $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 //Values in the query below are parameterized queries. $stmt = $conn->prepare("INSERT INTO users (Workout,first_name,last_name,gender,Email_Address,Password,User_Age,workout_options,Registration_Date) VALUES (?,?,?,?,?,?,?,?,?"); $stmt->bindParam(':Workout', $YesOrNo); $stmt->bindParam(':first_name', $fname); $stmt->bindParam(':last_name', $lname); $stmt->bindParam(':gender', $Gender); $stmt->bindParam(':Email_Address', $email); $stmt->bindParam(':Password', $Password); $stmt->bindParam(':User_Age',$UserAge); $stmt->bindparam(':workout_options',$workout_options); $stmt->bindParam(':Registration_Date',$Registration_Date); // insert a row $YesOrNo=$_POST["YesOrNo"]; $fname=$_POST["fname"]; $lname=$_POST["lname"]; $Gender=$_POST["Gender"]; $email=$_POST["email"]; $Password=$_POST["Password"]; $ConfirmPassword=$_POST["ConfirmPassword"]; //check if user entered the exact password twice. if($Password == $ConfirmPassword) { $hash = password_hash($Password, PASSWORD_DEFAULT); } else { echo "Passwords are mismatched. Please try again."; }; $UserAge=$_POST["UserAge"]; $workout_options=$_POST["workout_options"]; $Registration_Date=date("Y-m-d H:i:s"); $stmt->execute(); /* insert another row $firstname = "Mary"; $lastname = "Moe"; $email = "mary@example.com"; $stmt->execute(); // insert another row $firstname = "Julie"; $lastname = "Dooley"; $email = "julie@example.com"; $stmt->execute(); */ echo "New records created successfully"; } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } $conn = null; //Disconnect. ?> Thanks in advance!!
  12. Will do what you guys mentioned. I will keep you guys posted asap.
  13. Hello again people. I have made some changes to my code to make it work, and also applied your advices to my code. It works really great and all, and no error code is being generated, but unfortunately it is still not getting my query inserted into the database. the only message I get is the echo I have placed to check whether database is connected or not, and it says it is connected. Please consider the updated code and tell me what's wrong now? Thanks. <html> <head> <meta charset="UTF-8"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" ></script> <!-- Load Jquery --> <script> $(document).ready(function(){ //Specify a function to execute when the DOM is fully loaded. $("button").click(function(){ // הפעלת פקודה על הכפתור. $("#SignUpButton").remove(); // Remove the SignUpButton onclick. }); }); </script> <!-- below is the tag that allows reading the css settings from an external .css file. --> <link rel="stylesheet" type="text/css" href="CSSFILE.css"> </head> <title> Welcome to Click-And-Fit website.Soon you'll be in better shape!</title> <body> <img src="Demo_Photo.jpg" class="Demo_Photo" alt="CAF Demo Image" height=350 width="300"> <img src="Click_and_Fit!.jpg" class="Logo" alt="Click And Fit logo" height="200" width="200"> <p style="text-align:center">Welcome to Click-And-Fit!<br><br>Would you like to make a change in your life? <br><br><FONT COLOR="#551A8B" ><b>Click-And-Fit</b></FONT><br><br> Let's make this change happen by sign up to our website with the following form beyond.<br><br> You need to provide some of your daily lifestyle habits. (e.g.:Like if you're a smoker)</p> <br><br><br> <div class="container"> <a href="" class="button"><strong>Already have an account?</strong></a> </div> <div align="center"> <form action="" id="SignUpForm" autocomplete="on" style="display:none" method="post"> <!-- Form is Hidden until the user is clicking the "Sign Up" button. --> <input type="hidden" name="Language" value="English"> Fill up the following fields:<br><br> First name:<input type="text" name="fname" required><br><br> Last name: <input type="text" name="lname" required><br><br> Age: <input type="number" name="UserAge" min="1" max="120" required><br><br> Gender: <input type="radio" name="Gender" value="male">Male<br> <input type="radio" name="Gender" value="Female">Female<br> E-mail Address: <input type="email" name="email" autocomplete="off" required><br><br> Pick your new password: <input type="password" maxlength=”40” name="Password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,40}"> Add password strength checker here.<br><br> <!-- Uses regular expression. --> Confirm Password: <input type="password" maxlength=”40” name="ConfirmPassword" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,40}"><br><br> <!-- A better way is to use onblur to check user's type match. --> <hr> <script> (function(){ $("#submit").click(function(){ $(".error").hide(); //Bind an event handler to the "error" JavaScript event. var hasError = false; var passwordVal = $("#Password").val(); var checkVal = $("#ConfirmPassword").val(); if (passwordVal == '') { $("#Password").after('<span class="error">Please enter a password.</span>'); hasError = true; } else if (checkVal == '') { $("#ConfirmPassword").after('<span class="error">Please re-enter your password.</span>'); hasError = true; } else if (passwordVal != checkVal ) { $("#ConfirmPassword").after('<span class="error">Passwords do not match.</span>'); hasError = true; } if(hasError == true) {return false;} }); }); </script> <script> //The validationMessage property of a DOM node contains the message the browser displays to the user when a node's validity is checked and fails. document.getElementById("name").validationMessage; document.getElementById("lname").validationMessage; document.getElementById("UserAge").validationMessage; document.getElementById("Gender").validationMessage; document.getElementById("email").validationMessage; document.getElementById("Password").validationMessage; document.getElementById("ConfirmPassword").validationMessage; </script> Now let's go through your prefered food. Check the appropriate boxed beyond.<br><br> This will help us to better understand your food discipline:<br> <p style="text-align:center"><b> Meat And Poultry:</b></p> <div id="MeatCheckBox"> <input type="checkbox" name="FoodTypes[]" value="Hamburger">Hamburger<br> <input type="checkbox" name="FoodTypes[]" value="Steak">Steak<br> <input type="checkbox" name="FoodTypes[]" value="GroundBeef">Ground Beef<br> <input type="checkbox" name="FoodTypes[]" value="Bacon">Bacon<br> <input type="checkbox" name="FoodTypes[]" value="Beef">Beef<br> <input type="checkbox" name="FoodTypes[]" value="Salami">Salami<br> <input type="checkbox" name="FoodTypes[]" value="Chicken">Chicken (In all its forms)<br> <input type="checkbox" name="FoodTypes[]" value="NoMeat">I don't eat meat at all (Vegeterian/Vegan)<br> </div> <p style="text-align:center"><b> Fish And Seafood:</b></p> <div id="FishAndSeaFood"> <input type="checkbox" name="FoodTypes[]" value="Fish">Fish<br> <input type="checkbox" name="FoodTypes[]" value="Sushi">Sushi<br> <input type="checkbox" name="FoodTypes[]" value="CannedFish">Canned Fish<br> <input type="checkbox" name="FoodTypes[]" value="Oysters">Seafood<br> <input type="checkbox" name="FoodTypes[]" value="SmokedSalmon">Smoked Salmon<br> </div> <div id="Vegetables"> <p style="text-align:center"><b> Do you eat vegtables?</b></p><br> <input type="radio" name="YesOrNo" value="Yes">Yes <!-- Give both options the same name,Because they are related. --> <input type="radio" name="YesOrNo" value="No">No<br> </div> <hr> <p>Do you workout as part of your lifestyle?</p><br> <input type="radio" name='workout_options' value='valuable' data-id="DoWorkout" class="workout_options" /> I do workout occasionally <input type="radio" name='workout_options' value='valuable' data-id="DoNotWorkout" class="workout_options" /> I am not working out<br><br><br> <section> <div id=DoWorkout class="workout_options"><p>We see you're not having any exercise at the moment.<br><br>Did you know that doing some kind of activity like running or cardio 3 times a week improve your life quality?<br><br>We'll help you go straight from zero to hero!</p></div> <div id=DoNotWorkout class="workout_options">What type of workout you're working on at the moment? Please choose from the options beyond:<br><br><br> <input type="checkbox" name="Cardio" value="Cardio" data-id="Cardio"/>Cardio/Aerobics<br><br> <input type="checkbox" name=" Weight_Lifting" value=" Weight_Lifting" data-id="Weight_Lifting"/>Weight Lifting/ Anaerobics</div><br> </section> <input type="submit" value="Submit Details" name="SubmitDetails" id="SubmitDetails"> </div> </form> <p style="text-align:center;"><a href="#" id="Learn_More"> Learn more about Click-And-Fit</a></p> <div id="clickme"> <p align="center"><button type="submit" id="SignUpButton" name="SignUpButton" class="SignUpButton"><p style="font-size:30px;">Sign Up</p><br><span style="font-family:Consolas;font-size:20px; "> (I am ready for the challenge!)</span></button></p></div> <!-- Show form on click. --> <script> $( "#clickme" ).click(function() { $( "#SignUpForm" ).show( "slow", function() { // Animation complete. }); }); </script> <!-- script for the exercise options --> <script type="text/javascript"> $(':radio').change(function (event) { // when any radio button changes, var id = $(this).data('id'); // get the id from data-id $('#' + id) // find the div with that id. .addClass('workout_options') // give it the class .siblings().removeClass('workout_options'); // and remove the class from all it’s siblings // siblings are nodes before and after with the same parent. }); </script> </body> </html> PHP Code: <?php require('password_compat-master/lib/password.php'); //backward compatibility for the passord_hash function. // connnecting to MYSQL with PDO. // Connection data (server_address, database, username, password) $hostdb = "localhost"; $namedb = 'caf_users'; $userdb = "root"; $passdb = '3563077'; if (isset($_POST['SubmitDetails'])) { $YesOrNo=$_POST["YesOrNo"]; $fname=$_POST["fname"]; $lname=$_POST["lname"]; $Gender=$_POST["Gender"]; $email=$_POST["email"]; $Password=$_POST["Password"]; $ConfirmPassword=$_POST["ConfirmPassword"]; //check if user entered the exact password twice. if($Password == $ConfirmPassword) { $hash = password_hash($Password, PASSWORD_DEFAULT); } // The first parameter is the password string that needs to be hashed, //and the second parameter specifies the algorithm that should be used for generating the hash. //encrypted by bcrypt algorithm. else { echo "Passwords are mismatched. Please try again."; }; $UserAge=$_POST["UserAge"]; // Display message if successfully connect, otherwise retains and outputs the potential error try { $conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb); //Initiate connection witht the PDO object instance. $conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8 echo 'Connected to database.'; // Define an insert query $sql = "INSERT INTO `users` ('Workout','first_name','last_name','gender','Email_Address','Password','User_Age') VALUES ($YesOrNo,$fname,$lname,$Gender,$email,$Password,$UserAge)"; $count = $conn->exec($sql); $conn = null; // Disconnect if($count !== false) echo 'Number of rows added: '. $count; } catch(PDOException $e) { echo $e->getMessage(); } } ?>
  14. Sorry, here's a better one: <html> <head> <meta charset="UTF-8"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" ></script> <!-- Load Jquery --> <script> $(document).ready(function(){ //Specify a function to execute when the DOM is fully loaded. $("button").click(function(){ // הפעלת פקודה על הכפתור. $("#SignUpButton").remove(); // Remove the SignUpButton onclick. }); }); </script> <!-- below is the tag that allows reading the css settings from an external .css file. --> <link rel="stylesheet" type="text/css" href="CSSFILE.css"> </head> <title> Welcome to Click-And-Fit website.Soon you'll be in better shape!</title> <body> <img src="Demo_Photo.jpg" class="Demo_Photo" alt="CAF Demo Image" height=350 width="300"> <img src="Click_and_Fit!.jpg" class="Logo" alt="Click And Fit logo" height="200" width="200"> <p style="text-align:center">Welcome to Click-And-Fit!<br><br>Would you like to make a change in your life? <br><br><FONT COLOR="#551A8B" ><b>Click-And-Fit</b></FONT><br><br> Let's make this change happen by sign up to our website with the following form beyond.<br><br> You need to provide some of your daily lifestyle habits. (e.g.:Like if you're a smoker)</p> <br><br><br> <div class="container"> <a href="" class="button"><strong>Already have an account?</strong></a> </div> <div align="center"> <form action="" id="SignUpForm" autocomplete="on" style="display:none" method="post"> <!-- Form is Hidden until the user is clicking the "Sign Up" button. --> <input type="hidden" name="Language" value="English"> Fill up the following fields:<br><br> First name:<input type="text" name="fname" required><br><br> Last name: <input type="text" name="lname" required><br><br> Age: <input type="number" name="UserAge" min="1" max="120" required><br><br> Gender: <input type="radio" name="Gender" value="male">Male<br> <input type="radio" name="Gender" value="Female">Female<br> E-mail Address: <input type="email" name="email" autocomplete="off" required><br><br> Pick your new password: <input type="password" maxlength=”40” name="Password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,40}"> Add password strength checker here.<br><br> <!-- Uses regular expression. --> Confirm Password: <input type="password" maxlength=”40” name="ConfirmPassword" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,40}"><br><br> <!-- A better way is to use onblur to check user's type match. --> <hr> <script> (function(){ $("#submit").click(function(){ $(".error").hide(); //Bind an event handler to the "error" JavaScript event. var hasError = false; var passwordVal = $("#Password").val(); var checkVal = $("#ConfirmPassword").val(); if (passwordVal == '') { $("#Password").after('<span class="error">Please enter a password.</span>'); hasError = true; } else if (checkVal == '') { $("#ConfirmPassword").after('<span class="error">Please re-enter your password.</span>'); hasError = true; } else if (passwordVal != checkVal ) { $("#ConfirmPassword").after('<span class="error">Passwords do not match.</span>'); hasError = true; } if(hasError == true) {return false;} }); }); </script> <script> //The validationMessage property of a DOM node contains the message the browser displays to the user when a node's validity is checked and fails. document.getElementById("name").validationMessage; document.getElementById("lname").validationMessage; document.getElementById("UserAge").validationMessage; document.getElementById("Gender").validationMessage; document.getElementById("email").validationMessage; document.getElementById("Password").validationMessage; document.getElementById("ConfirmPassword").validationMessage; </script> Now let's go through your prefered food. Check the appropriate boxed beyond.<br><br> This will help us to better understand your food discipline:<br> <p style="text-align:center"><b> Meat And Poultry:</b></p> <div id="MeatCheckBox"> <input type="checkbox" name="FoodTypes[]" value="Hamburger">Hamburger<br> <input type="checkbox" name="FoodTypes[]" value="Steak">Steak<br> <input type="checkbox" name="FoodTypes[]" value="GroundBeef">Ground Beef<br> <input type="checkbox" name="FoodTypes[]" value="Bacon">Bacon<br> <input type="checkbox" name="FoodTypes[]" value="Beef">Beef<br> <input type="checkbox" name="FoodTypes[]" value="Salami">Salami<br> <input type="checkbox" name="FoodTypes[]" value="Chicken">Chicken (In all its forms)<br> <input type="checkbox" name="FoodTypes[]" value="NoMeat">I don't eat meat at all (Vegeterian/Vegan)<br> </div> <p style="text-align:center"><b> Fish And Seafood:</b></p> <div id="FishAndSeaFood"> <input type="checkbox" name="FoodTypes[]" value="Fish">Fish<br> <input type="checkbox" name="FoodTypes[]" value="Sushi">Sushi<br> <input type="checkbox" name="FoodTypes[]" value="CannedFish">Canned Fish<br> <input type="checkbox" name="FoodTypes[]" value="Oysters">Seafood<br> <input type="checkbox" name="FoodTypes[]" value="SmokedSalmon">Smoked Salmon<br> </div> <div id="Vegetables"> <p style="text-align:center"><b> Do you eat vegtables?</b></p><br> <input type="radio" name="YesOrNo" value="Yes">Yes <!-- Give both options the same name,Because they are related. --> <input type="radio" name="YesOrNo" value="No">No<br> </div> <hr> <p>Do you workout as part of your lifestyle?</p><br> <input type="radio" name='workout_options' value='valuable' data-id="DoWorkout" class="workout_options" /> I do workout occasionally <input type="radio" name='workout_options' value='valuable' data-id="DoNotWorkout" class="workout_options" /> I am not working out<br><br><br> <section> <div id=DoWorkout class="workout_options"><p>We see you're not having any exercise at the moment.<br><br>Did you know that doing some kind of activity like running or cardio 3 times a week improve your life quality?<br><br>We'll help you go straight from zero to hero!</p></div> <div id=DoNotWorkout class="workout_options">What type of workout you're working on at the moment? Please choose from the options beyond:<br><br><br> <input type="checkbox" name="Cardio" value="Cardio" data-id="Cardio"/>Cardio/Aerobics<br><br> <input type="checkbox" name=" Weight_Lifting" value=" Weight_Lifting" data-id="Weight_Lifting"/>Weight Lifting/ Anaerobics</div><br> </section> <input type="submit" value="Sign Up!" id="submit"> </div> </form> <p style="text-align:center;"><a href="#" id="Learn_More"> Learn more about Click-And-Fit</a></p> <div id="clickme"> <p align="center"><button type="submit" id="SignUpButton" name="SignUpButton" class="SignUpButton"><p style="font-size:30px;">Sign Up</p><br><span style="font-family:Consolas;font-size:20px; "> (I am ready for the challenge!)</span></button></p></div> <!-- Show form on click. --> <script> $( "#clickme" ).click(function() { $( "#SignUpForm" ).show( "slow", function() { // Animation complete. }); }); </script> <!-- script for the exercise options --> <script type="text/javascript"> $(':radio').change(function (event) { // when any radio button changes, var id = $(this).data('id'); // get the id from data-id $('#' + id) // find the div with that id. .addClass('workout_options') // give it the class .siblings().removeClass('workout_options'); // and remove the class from all it’s siblings // siblings are nodes before and after with the same parent. }); </script> </body> </html> <?php // connnecting to MYSQL with PDO. // Connection data (server_address, database, username, password) $hostdb = 'localhost'; $namedb = 'caf_users'; $userdb = 'root'; $passdb = 'mypassword'; if (isset($_POST['SignUpButton'])) { $YesOrNo=$_POST["YesOrNo"]; $fname=$_POST["fname"]; $lname=$_POST["lname"]; $Gender=$_POST["Gender"]; $email=$_POST["email"]; //check if user entered the exact password twice. if ($_POST["password"] === $_POST["confirm_password"]) { $password=$_POST["password"]; $hash = password_hash($passwod, PASSWORD_DEFAULT);} // The first parameter is the password string that needs to be hashed, //and the second parameter specifies the algorithm that should be used for generating the hash. //encrypted by bcrypt algorithm. else { echo "Passwords are mismatched. Please try again."; }; $UserAge=$_POST["UserAge"]; // Display message if successfully connect, otherwise retains and outputs the potential error try { $conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb); //Initiate connection witht the PDO object instance. $conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8 echo 'Connected to database'; // Define an insert query $sql = "INSERT INTO `users` ('Workout','first_name','last_name','gender','Email_Address','Password','User_Age') VALUES ($YesOrno,$fname,$lname,$Gender,$email,$password,$UserAge)"; $count = $conn->exec($sql); $conn = null; // Disconnect if($count !== false) echo 'Number of rows added: '. $count; } catch(PDOException $e) { echo $e->getMessage(); } } ?>
  15. Hello everyone. It seems like my code is not working properly. i have tried both mysqli and PDO to insert data into database,but it only takes me back to same page again,without doing nothing in the database (been checking this a few times to be sure). both php and html code are on the same page. Could anyone point me to the missing link in my code? here's my code (HTML & PHP) : <form action="" id="SignUpForm" autocomplete="on" style="display:none" method="post"> <!-- Form is Hidden until the user is clicking the "Sign Up" button. --> <input type="hidden" name="Language" value="English"> Fill up the following fields:<br><br> First name:<input type="text" name="fname" required><br><br> Last name: <input type="text" name="lname" required><br><br> Age: <input type="number" name="UserAge" min="1" max="120" required><br><br> Gender: <input type="radio" name="Gender" value="male">Male<br> <input type="radio" name="Gender" value="Female">Female<br> E-mail Address: <input type="email" name="email" autocomplete="off" required><br><br> Pick your new password: <input type="password" maxlength=”40” name="Password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,40}"> Add password strength checker here.<br><br> <!-- Uses regular expression. --> Confirm Password: <input type="password" maxlength=”40” name="ConfirmPassword" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,40}"><br><br> <!-- A better way is to use onblur to check user's type match. --> <hr> <script> (function(){ $("#submit").click(function(){ $(".error").hide(); //Bind an event handler to the "error" JavaScript event. var hasError = false; var passwordVal = $("#Password").val(); var checkVal = $("#ConfirmPassword").val(); if (passwordVal == '') { $("#Password").after('<span class="error">Please enter a password.</span>'); hasError = true; } else if (checkVal == '') { $("#ConfirmPassword").after('<span class="error">Please re-enter your password.</span>'); hasError = true; } else if (passwordVal != checkVal ) { $("#ConfirmPassword").after('<span class="error">Passwords do not match.</span>'); hasError = true; } if(hasError == true) {return false;} }); }); </script> <script> //The validationMessage property of a DOM node contains the message the browser displays to the user when a node's validity is checked and fails. document.getElementById("name").validationMessage; document.getElementById("lname").validationMessage; document.getElementById("UserAge").validationMessage; document.getElementById("Gender").validationMessage; document.getElementById("email").validationMessage; document.getElementById("Password").validationMessage; document.getElementById("ConfirmPassword").validationMessage; </script> Now let's go through your prefered food. Check the appropriate boxed beyond.<br><br> This will help us to better understand your food discipline:<br> <p style="text-align:center"><b> Meat And Poultry:</b></p> <div id="MeatCheckBox"> <input type="checkbox" name="FoodTypes[]" value="Hamburger">Hamburger<br> <input type="checkbox" name="FoodTypes[]" value="Steak">Steak<br> <input type="checkbox" name="FoodTypes[]" value="GroundBeef">Ground Beef<br> <input type="checkbox" name="FoodTypes[]" value="Bacon">Bacon<br> <input type="checkbox" name="FoodTypes[]" value="Beef">Beef<br> <input type="checkbox" name="FoodTypes[]" value="Salami">Salami<br> <input type="checkbox" name="FoodTypes[]" value="Chicken">Chicken (In all its forms)<br> <input type="checkbox" name="FoodTypes[]" value="NoMeat">I don't eat meat at all (Vegeterian/Vegan)<br> </div> <p style="text-align:center"><b> Fish And Seafood:</b></p> <div id="FishAndSeaFood"> <input type="checkbox" name="FoodTypes[]" value="Fish">Fish<br> <input type="checkbox" name="FoodTypes[]" value="Sushi">Sushi<br> <input type="checkbox" name="FoodTypes[]" value="CannedFish">Canned Fish<br> <input type="checkbox" name="FoodTypes[]" value="Oysters">Seafood<br> <input type="checkbox" name="FoodTypes[]" value="SmokedSalmon">Smoked Salmon<br> </div> <div id="Vegetables"> <p style="text-align:center"><b> Do you eat vegtables?</b></p><br> <input type="radio" name="YesOrNo" value="Yes">Yes <!-- Give both options the same name,Because they are related. --> <input type="radio" name="YesOrNo" value="No">No<br> </div> <hr> <p>Do you workout as part of your lifestyle?</p><br> <input type="radio" name='workout_options' value='valuable' data-id="DoWorkout" class="workout_options" /> I do workout occasionally <input type="radio" name='workout_options' value='valuable' data-id="DoNotWorkout" class="workout_options" /> I am not working out<br><br><br> <section> <div id=DoWorkout class="workout_options"><p>We see you're not having any exercise at the moment.<br><br>Did you know that doing some kind of activity like running or cardio 3 times a week improve your life quality?<br><br>We'll help you go straight from zero to hero!</p></div> <div id=DoNotWorkout class="workout_options">What type of workout you're working on at the moment? Please choose from the options beyond:<br><br><br> <input type="checkbox" name="Cardio" value="Cardio" data-id="Cardio"/>Cardio/Aerobics<br><br> <input type="checkbox" name=" Weight_Lifting" value=" Weight_Lifting" data-id="Weight_Lifting"/>Weight Lifting/ Anaerobics</div><br> </section> <input type="submit" value="Sign Up!" id="submit"> </div> </form> PHP/PDO: <?php // connnecting to MYSQL with PDO. // Connection data (server_address, database, username, password) $hostdb = 'localhost'; $namedb = 'caf_users'; $userdb = 'root'; $passdb = 'mypassword'; if (isset($_POST['SignUpButton'])) { $yesOrNo=$_POST["YesOrNo"]; $firstName=$_POST["fname"]; $lastName=$_POST["lname"]; $userGender=$_POST["Gender"]; $emailAddress=$_POST["email"]; //check if user entered the exact password twice. if ($_POST["password"] === $_POST["confirm_password"]) { $password=$_POST["password"]; $hash = password_hash($passwod, PASSWORD_DEFAULT);} // The first parameter is the password string that needs to be hashed, //and the second parameter specifies the algorithm that should be used for generating the hash. //encrypted by bcrypt algorithm. else { echo "Passwords are mismatched. Please try again."; }; $userAge=$_POST["UserAge"]; // Display message if successfully connect, otherwise retains and outputs the potential error try { $conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb); //Initiate connection witht the PDO object instance. $conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8 echo 'Connected to database'; // Define an insert query $sql = "INSERT INTO `users` ('Workout','first_name','last_name','gender','Email_Address','Password','User_Age') VALUES ($YesOrno,$fname,$lname,$Gender,$email,$password,$UserAge)"; $count = $conn->exec($sql); $conn = null; // Disconnect if($count !== false) echo 'Number of rows added: '. $count; } catch(PDOException $e) { echo $e->getMessage(); } } ?> Thank you in advance, Osher.
×
×
  • Create New...

Important Information

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