Jump to content

Recommended Posts

Posted (edited)

when i execute code on my localhost and on 000webhost then it works fine but shows error on this host .

my php file's php code is this

 

<?php
// define variables and set to empty values
  $email = $password = "";
 $errors = array();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  
       $con=mysqli_connect("localhost","deep958","<removed>");
  mysqli_select_db($con,"deep958_togetherwe");
  
  
  
  if (empty($_POST["email"])) {
    $errors['email']  = "Email is required";
  } else {
    $email = test_input($_POST["email"]);
    // check if e-mail address is well-formed
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
          $errors['email'] = "Invalid email format"; 
    }
else{
$a="select * from signup where email= '$email'";
   $aresult=mysqli_query($con,$a);
   $anum=mysqli_num_rows($aresult);
 
$b="select * from login where email= '$email'";
$bresult=mysqli_query($con,$;
$bnum=mysqli_num_rows($bresult);
 
if($anum==1) {$errors['email'] = "This email is not verified.Click <a href='\New folder\confirmation.php'>here</a> to verify it.";}
elseif($bnum==0) {$errors['email'] = "This email doesn't exist. Plz click <a href='\New folder\signup.php'>here</a> to sign up";}
 
 
}
 
  }
 
 
 
   if (empty($_POST["password"])) {
    $errors['password']  = "Password is required";
  } else {
    $password = $_POST["password"];
    // check if password is well-formed
     if (!preg_match_all('$\S*(?=\S{6,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])(?=\S*[\W])\S*$', $password)){
          $errors['password'] = "Invalid password"; 
    }
else{
    $row=mysqli_fetch_array($bresult);
$bpassword=$row['password'];
    if($password != $bpassword)
$errors['password']= "password is incoreecrt";
}
  }
  
 
 
  
    
   if(count($errors)==0)
{ session_start();
      $_SESSION['user']="$email";
 header("Location: /public_html/New folder/videos.php");
 exit();
}
  
  
  
}
 
function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
 
 
 
 
?>

 

 

and errors that it is showing is in the image

Edited by Krydos
Removed password
  • Like 1
Posted

You didn't post the whole file... Here's the missing beginning of the file:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Together We</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 <link href="https://fonts.googleapis.com/css?family=Open+Sans:400i,600i" rel="stylesheet">


  <link rel="stylesheet" type="text/css" href="lstylesheet.css">

  <style>
.error {color: #FF0000;}
</style>


</head>

<body id="myPage">



<?php
You obviously have html before any of the php code you posted. You're going to get that error if you use any of the session or header commands after already posting html to the page.
  • Like 1
Posted

yeah , but first i check whether the filled entries are correct or not . and if entries are correct then starts a session .

how should i modify my code for this purpose so that no error occur??

Posted

Create the session at the start of your file like everyone else does, then populate its values only if the conditions are met.

 

Generally when sessions are used they're started in every file, every time, right near the top (often the command itself will be in an include file).

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...