[:en]SQL: if statement[:]

[:en]Several examples to check login or register user online:

connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

// Change character set to utf8
mysqli_set_charset($conn,"utf8");

// Change Time Zone
date_default_timezone_set("Asia/Hong_Kong");

// Select database
$dbname = $_GET['dbname'];
mysqli_select_db($conn,"$dbname");

$FirstName = date("Y-m-d");
$LastName = date("h:i:sa");
$Street = $_GET["Street"];
$City = $_GET['City'];
$State = $_GET['State'];
$Zip = $_GET['Zip'];
$Email = $_GET['Email'];
$inc = $_GET['inc'];
$score = $_GET['score'];
$Phone = $_GET['Phone'];
$Recorder = $_GET['Recorder'];
$version = $_GET['version'];
$station = $_GET['station'];
$announce2 = $_GET['announce2'];
$phone2 = $_GET['phone2'];
$email2 = $_GET['email2'];

$sql1 = "SELECT * FROM userlog WHERE G>1 AND E='$City'";
 
$check = mysqli_fetch_array(mysqli_query($conn,$sql1));

if(isset($check)){
 $sql = "UPDATE userlog SET B='$FirstName', C='$LastName', F='$State',G='$Zip', H='$Email', J='$score', N='$station', O='$announce2' WHERE E='$City'";
 }else{ 
 $sql = "INSERT INTO userlog (B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q) VALUES ('$FirstName', '$LastName', '$Street', '$City', '$State', '$Zip', '$Email', '$inc','$score', '$Phone', '$Recorder', '$version', '$station', '$announce2', '$phone2', '$email2')";
}

if ($conn->query($sql) === TRUE) {
    echo "Login successful-->>".$Zip.$sql;
} else {
    echo "Error: " . $sql . "
" . $conn->error; } $conn->close(); ?> ?>

The other examples to check online:

Set up a “connect.php’ file


Then check if the user already exists...


Or the other method:

1. init.php

connect_error) {
    die("Connection failed: " . $con->connect_error);
} 

 ?>  

2. Then check valid user name or password:

query($sql3) === TRUE) {
    echo "Login successful-->>".$phone.$sql3;
} else {
    echo "Error: " . $sql . "
" . $con->error; } }else{ echo 'Invalid telephone number or password'; } if ($con->query($sql2) === TRUE) { echo "Updated successfully"; } else { echo ""; } } $con->close(); ?>

3. Update user password and register the login:

query($sql) === TRUE) {
 // Register the login
 $sql2 = "SELECT * FROM userlog WHERE E='$phone'";
$check2 = mysqli_fetch_array(mysqli_query($con,$sql2));
if(isset($check2)){
 $sql3 = "UPDATE userlog SET B='$date', C='$time',F='$password' WHERE E='$phone'";
 }else{ 
 $sql3 = "INSERT INTO userlog (B, C, E, F) VALUES ('$date', '$time', '$phone', '$password')";
 }

if ($con->query($sql3) === TRUE) {
    echo "Login successful-->>".$phone.$sql3;
} else {
    echo "Error: " . $sql . "
" . $con->error; } } else { echo ""; } } $con->close(); ?>

or Several enquires at the same time

 
 query($sql3) === TRUE) {
           // step 4: check if the uploading absence is successful
                  $sql = "SELECT D FROM absence
                         WHERE B = '$date'
                         ORDER BY D ASC
                         LIMIT 100";
          }else {
             // failed to upload absence
               echo "Error";
              }
         }    
        }              
      
$result = $con->query($sql);
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
	   echo $row["D"].'#';
	   
    }
} else {
    echo $sql;
}
$con->close();
?>  

Multiple updates at the same time:

    query($sql) === TRUE) {
    echo "new name".$sql;
} else {
   echo "Error: " . $sql . "
" . $con->error; } $con->close(); ?>

[:]

Print Friendly, PDF & Email
Scroll to Top