Jump to content

Search the Community

Showing results for tags 'websql'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 2 results

  1. Hello, can anyone please suggest what change should I make in order to make login using email/username either in same field or 2 different fields. <?php // Initialize the session session_start(); // Check if the user is already logged in, if yes then redirect him to welcome page if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){ header("location: welcome.php"); exit; } // Include config file require_once "c.php"; // Define variables and initialize with empty values $username = $password = ""; $username_err = $password_err = $login_err = ""; // Processing form data when form is submitted if($_SERVER["REQUEST_METHOD"] == "POST"){ // Check if username is empty if(empty(trim($_POST["username"]))){ $username_err = "Please enter username."; } else{ $username = trim($_POST["username"]); } // Check if password is empty if(empty(trim($_POST["password"]))){ $password_err = "Please enter your password."; } else{ $password = trim($_POST["password"]); } // Validate credentials if(empty($username_err) && empty($password_err)){ // Prepare a select statement $sql = "SELECT id, username, password FROM users WHERE (username = ? OR email= ?)"; if($stmt = mysqli_prepare($link, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "s", $param_username); // Set parameters $param_username = $username; // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ // Store result mysqli_stmt_store_result($stmt); // Check if username exists, if yes then verify password if(mysqli_stmt_num_rows($stmt) == 1){ // Bind result variables mysqli_stmt_bind_result($stmt, $id, $username, $hashed_password); if(mysqli_stmt_fetch($stmt)){ if(password_verify($password, $hashed_password)){ // Password is correct, so start a new session session_start(); // Store data in session variables $_SESSION["loggedin"] = true; $_SESSION["id"] = $id; $_SESSION["username"] = $username; // Redirect user to welcome page header("location: welcome.php"); } else{ // Password is not valid, display a generic error message $login_err = "Invalid username or password."; } } } else{ // Username doesn't exist, display a generic error message $login_err = "Invalid username or password."; } } else{ echo "Oops! Something went wrong. Please try again later."; } // Close statement mysqli_stmt_close($stmt); } } // Close connection mysqli_close($link); } ?> also, here is my error code- <?php // Initialize the session session_start(); // Check if the user is already logged in, if yes then redirect him to welcome page if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){ header("location: welcome.php"); exit; } // Include config file require_once "c.php"; // Define variables and initialize with empty values $username = $password = ""; $username_err = $password_err = $login_err = ""; $email = $password = ""; $email_err = $password_err = $login_err = ""; // Processing form data when form is submitted if($_SERVER["REQUEST_METHOD"] == "POST"){ // Check if username is empty if(empty(trim($_POST["username"]))){ $username_err = "Please enter username."; } else{ $username = trim($_POST["username"]); } // Check if mail is empty if(empty(trim($_POST["email"]))){ $email_err = "Please enter mail"; } else{ $email = trim($_POST["email"]); } // Check if password is empty if(empty(trim($_POST["password"]))){ $password_err = "Please enter your password."; } else{ $password = trim($_POST["password"]); } // Validate credentials if(empty($username_err) && empty($email_err) && empty($password_err)){ // Prepare a select statement $sql = "SELECT id, username, email, password FROM users WHERE (username = ? OR email= ?)"; if($stmt = mysqli_prepare($link, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "s", $param_username); // Set parameters $param_username = $username; // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ // Store result mysqli_stmt_store_result($stmt); // Check if username exists, if yes then verify password if(mysqli_stmt_num_rows($stmt) == 1){ // Bind result variables mysqli_stmt_bind_result($stmt, $id, $username, $hashed_password); if(mysqli_stmt_fetch($stmt)){ if(password_verify($password, $hashed_password)){ // Password is correct, so start a new session session_start(); // Store data in session variables $_SESSION["loggedin"] = true; $_SESSION["id"] = $id; $_SESSION["username"] = $username; // Redirect user to welcome page header("location: welcome.php"); } else{ // Password is not valid, display a generic error message $login_err = "Invalid username or password."; } } } else{ // Username doesn't exist, display a generic error message $login_err = "Invalid username or password."; } } else{ echo "Oops! Something went wrong. Please try again later."; } // Close statement mysqli_stmt_close($stmt); } } // Close connection mysqli_close($link); } ?> Please check it!
  2. Greetings to all in the forum. I'm totally new to AppML which by the way i found very interesting. Followed the tutorial of https://www.w3schools.com/appml/appml_client.asp till the end of it https://www.w3schools.com/appml/appml_database.asp and trying to build the web application by using WebSQL. In the table customers i can delete an existing record and modified it, but i can't add a new one. Every time when i go to New button and adding new customer data, when i press Save button i got an error in Chrome console Uncaught TypeError: Cannot read property 'CustomerID' of undefined at AppML.putRecord (appml.js:527) at AppML.saveRecord (appml.js:593) at HTMLButtonElement.onclick (app2.html:1) Specifically got error in line 527 of appml.js { if (action === "UPDATE") { if (this.data.records[0][this.data.keyField] === "") {action = "ADD"; } } And in line 593 of appml.js this.saveRecord = function () { this.putRecord("UPDATE"); }; My HTML Prototype is the follow <!DOCTYPE html> <html lang="en-US"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>Untitled 1</title> <title>Customers</title> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <script src="appml.js"></script> <script src="https://www.w3schools.com/appml/2.0.3/appml_sql.js"></script> </head> <body> <div class="w3-container"> <div id="Form01" class="w3-container w3-light-grey w3-padding-large w3-margin-bottom" appml-data="local?model=model_customersform" appml-controller="myFormController" style="display:none;"> <div appml-include-html="inc_formcommands.htm"></div> <p> <label for="customername">Customer:</label> <input id="customername" class="w3-input w3-border"> </p> <p> <label for="address">Address:</label> <input id="address" class="w3-input w3-border"> </p> <p> <label for="city">City:</label> <input id="city" class="w3-input w3-border"> </p> <p> <label for="postalcode">Postal Code:</label> <input id="postalcode" class="w3-input w3-border"> </p> <p> <label for="country">Country:</label> <input id="country" class="w3-input w3-border"> </p> </div> <div appml-data="local?model=model_customerslist"> <h1>Customers</h1> <div appml-include-html="inc_listcommands.htm"></div> <div appml-include-html="inc_filter.htm"></div> <table class="w3-table-all"> <tr> <th></th> <th>Customer</th> <th>City</th> <th>Country</th> </tr> <tr appml-repeat="records"> <td style="cursor:pointer;width:34px;" onclick="appml('Form01').run({{CustomerID}})">&#9998;</td> <td>{{CustomerName}}</td> <td>{{City}}</td> <td>{{Country}}</td> </tr> </table> </div> </div> <script> function myFormController($appml) { if ($appml.message == "ready") {return -1;} if ($appml.message == "loaded") { document.getElementById("Form01").style.display=""; } } </script> </body> </html> Any help it's appreciated, i'm stuck at that point. I've tried some solutions but didn't worked. I have a feeling that something i am missing, cause i'm not an english native speaker. Any solutions? Thanks in advance.
×
×
  • Create New...