User input textarea rendering \n\r instead of linebreak - php

I have a textarea element on my personal website. It is used as a comment section, when users submit information, I automatically receive an email with the data. The problem that I am having is, whenever a user inserts a line break (by pressing return) the email will render something like this:
Hello Mike,\r\n\great website\r\n\keep in touch!\r\n\
Instead of:
Hello Mike,
Great Website
keep in touch!
Here is my code, was wondering if anyone can help me! Thank you
<?php
// This connects to database
$connection = mysqli_connect ('localhost', 'username', 'password', 'database');
$message_sent = false;
function updateForm () {
global $connection;
if ( isset ($_POST['submit'])) {
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
global $connection;
$name = $_POST['name'];
$email = $_POST['email'];
$userComment = $_POST['comment'];
$name = mysqli_real_escape_string($connection, $name);
$email = mysqli_real_escape_string($connection, $email);
$userComment = mysqli_real_escape_string($connection, $userComment);
// Submits email code
$to = "michaelrivasnyc#gmail.com";
$subject = "You have a new form submission";
$body = "";
$body .= "From: ".$name. "\r\n";
$body .= "email: ".$email. "\r\n";
$body .= "message: ".($userComment). " ";
// email information going to be sent to user
$userSubject = "Thanks for submitting form.";
$userBody = "Thank you for submitting form on michaelrivas.net, we will be in touch.";
mail($to, $subject,$body);
mail($email, $userSubject, $userBody);
$message_sent = true;
} else {
$message_sent = false;
}
$name = mysqli_real_escape_string ($connection, $name);
$email = mysqli_real_escape_string ($connection, $email);
$userComment = mysqli_real_escape_string ($connection, $userComment);
$query = "INSERT INTO email (names, email, comment) ";
$query .= "VALUES ('$name' , '$email' , '$userComment') ";
$result = mysqli_query($connection, $query);
if (!$result) {
die('Connection error' . mysqli_error ());
} else {
echo "<br>" . "<br>" . "You have been added to my email list, Thanks for staying in touch";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-126337947-3"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-126337947-3');
</script>
<!-- Icons, scripts, CSS, and other attachments. These should be the same
for all pages minus the <header> class with is the front page photo -->
<link href="images/radio-tower.png" rel="icon" type="image/x-icon"/>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Mina" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Timmana" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="JS/JS4web.js"></script>
</head>
<fie>
<title>Michael Rivas</title>
<!-- Top Navigation Menu -->
<div>
<div class="navBar">
<div id="myLinks">
Home
Projects
Contact
</div>
<a href="javascript:void(0);" class="icon" onclick="myFunction()">
<i class="fa fa-bars"></i>
</a>
</div>
<h1 id="textAboveForm">Keep in touch</h1>
<div id="formFields">
<form action="contactform.php" method="post" >
<input style="font-size: 16px;" id="firstnameinput" type="text" name="name" placeholder="Name" required>
<input style="font-size: 16px;" id="emailinput" type="text" name="email" placeholder= "email" required>
<br>
<textarea id="commentBox" name="comment" placeholder= "Drop a note"></textarea>
<br>
<input id="submitbutton" type="submit" name= "submit" value= "Submit">
<?php updateForm ();?>
</form>
</div>
</body>
</html>

You are misusing mysqli_real_escape_string(). It would be best that you forget this function even exists. It is the root cause of your problem. Remove it from your code and use parameterized prepared statements.
$name = $_POST['name'];
$email = $_POST['email'];
$userComment = $_POST['comment'];
// send an email
$query = "INSERT INTO email (names, email, comment) VALUES (? , ? , ?) ";
$stmt = $connection->prepare($query);
$stmt->bind_param('sss', $name, $email, $userComment);
$stmt->execute();

Related

PHPMailer won´t send emails

I´m working on netbeans, on winsows and with xampp. I believe it has something to do with the version of PHPMailer, I see examples with
PHPAutoload.php
but with the version I downloaded from gitHub I don´t see that file. Everything look fine, it does insert into the data base but got to this part of the code
$msg = "Something wrong happened! Please try again!";
I pasted the PHPMailer folder into c:/xampp/htdocs/pojectmail/PHPMailer.
Here is my register.php code
<?php
$msg = "";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if (isset($_POST['submit'])) {
$con = new mysqli('localhost', 'root', '', 'research_phpEmailConfirmation');
$name = $con->real_escape_string($_POST['name']);
$email = $con->real_escape_string($_POST['email']);
$password = $con->real_escape_string($_POST['password']);
$cPassword = $con->real_escape_string($_POST['cPassword']);
if ($name == "" || $email == "" || $password != $cPassword)
$msg = "Please check your inputs!";
else {
$sql = $con->query("SELECT id FROM users WHERE email='$email'");
if ($sql->num_rows > 0) {
$msg = "Email already exists in the database!";
} else {
$token = 'qwertzuiopasdfghjklyxcvbnmQWERTZUIOPASDFGHJKLYXCVBNM0123456789!$/()*';
$token = str_shuffle($token);
$token = substr($token, 0, 10);
$hashedPassword = password_hash($password, PASSWORD_BCRYPT);
$con->query("INSERT INTO users (name,email,password,isEmailConfirmed,token)
VALUES ('$name', '$email', '$hashedPassword', '0', '$token');
");
include_once "PHPMailer/PHPMailer.php";
include_once "PHPMailer/Exception.php";
$mail = new PHPMailer();
$mail->setFrom('hello#codingpassiveincome.com');
$mail->addAddress($email, $name);
$mail->Subject = "Please verify email!";
$mail->isHTML(true);
$mail->Body = "aa";
if ($mail->send()) {
$msg = "You have been registered! Please verify your email!";
} else {
$msg = "Something wrong happened! Please try again!";
}
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Register</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
</head>
<body>
<div class="container" style="margin-top: 100px;">
<div class="row justify-content-center">
<div class="col-md-6 col-md-offset-3" align="center">
<img src="images/logo.png"><br><br>
<?php if ($msg != "") echo $msg . "<br><br>" ?>
<form method="post" action="register.php">
<input class="form-control" name="name" placeholder="Name..."><br>
<input class="form-control" name="email" type="email" placeholder="Email..."><br>
<input class="form-control" name="password" type="password" placeholder="Password..."><br>
<input class="form-control" name="cPassword" type="password" placeholder="Confirm Password..."><br>
<input class="btn btn-primary" type="submit" name="submit" value="Register">
</form>
</div>
</div>
</div>
</body>
</html>

Information don't post in database

I try to implement an sign in form based on webcam image, apparently, i don't errors in code, but information don't posted in database.
Here is my index with php code for insert information in database:
<?php
if (isset($_POST['desc'])) {
if (!isset($_POST['iscorrect']) || $_POST['iscorrect'] == "") {
echo "Sorry, important data to submit your question is missing. Please press back in your browser and try again and make sure you select a correct answer for the question.";
exit();
}
if (!isset($_POST['type']) || $_POST['type'] == "") {
echo "Sorry, there was an error parsing the form. Please press back in your browser and try again";
exit();
}
require_once("scripts/connect_db.php");
$name = $_POST['name'];
$email = $_POST['email'];
$name = mysqli_real_escape_string($connection, $name);
$name = strip_tags($name);
$email = mysqli_real_escape_string($connection, $email);
$email = strip_tags($email);
if (isset($_FILES['image'])) {
$name = $_FILES['image']['tmp_name'];
$image = base64_encode(
file_get_contents(
$_FILES['image']['tmp_name']
)
);
}
$sql = mysqli_query($connection, "INSERT INTO users (name,email,image) VALUES ('$name', '$email','$image')")or die(mysqli_error($connection));
header('location: index.php?msg=' . $msg . '');
$msg = 'merge';
}
?>
<?php
$msg = "";
if (isset($_GET['msg'])) {
$msg = $_GET['msg'];
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Licenta Ionut</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<!-- font files -->
<link href='//fonts.googleapis.com/css?family=Muli:400,300' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Nunito:400,300,700' rel='stylesheet' type='text/css'>
<!-- /font files -->
<!-- css files -->
<link href="css/style.css" rel='stylesheet' type='text/css' media="all" />
<link href="web.js" rel='stylesheet' type='text/css' media="all" />
<script type="text/javascript" src="web.js"></script>
<!-- /css files -->
</head>
<body>
<p style="color:#06F;"><?php echo $msg; ?></p>
<h1>LogIn with Webcam Password</h1>
<div class="log">
<div class="content1">
<h2>Sign In Form</h2>
<form>
<input type="text" name="userid" value="USERNAME" onfocus="this.value = '';" onblur="if (this.value == '') {
this.value = 'USERNAME';
}">
<input type="password" name="psw" value="PASSWORD" onfocus="this.value = '';" onblur="if (this.value == '') {
this.value = 'PASSWORD';}">
<div class="button-row">
<input type="submit" class="sign-in" value="Sign In">
<input type="reset" class="reset" value="Reset">
<div class="clear"></div>
</div>
</form>
</div>
<div class="content2">
<h2>Register</h2>
<form action="index.php", name="index.php" method="post" enctype="multipart/form-data">
<input type="text" id="name" name="name" value="Nume">
<input type="text" id="email" name="email" value="EmailAdress">
<br>
<script type="text/javascript" src="webcam.js"></script>
<script language="JavaScript">
document.write(webcam.get_html(320, 240));
</script>
<div class="button-row">
<input class="sign-in" type=button value="Configure" onClick="webcam.configure()" class="shiva">
<input class="reset" type="submit" value="Register" id="image" onClick="take_snapshot()" class="shiva">
</div>
</form>
</div>
<div class="clear"></div>
</div>
</body>
</html>
And here is the script for connection to database:
<?php
$db_host = "localhost";
// Place the username for the MySQL database here
$db_username = "Ionut";
// Place the password for the MySQL database here
$db_pass = "1993";
// Place the name for the MySQL database here
$db_name = "users";
// Run the connection here
$connection=mysqli_connect("$db_host","$db_username","$db_pass") or die (mysqli_connect_error());
mysqli_select_db($connection,"$db_name") or die ("no database");
?>
I don't find error in code and i need your advice/help!
Thank you for interest about my problem!
To solve a problem like this, break the problem into parts.
(1) First, what is the PHP file receiving? At the top of the PHP file, insert:
<?php
echo '<pre>';
print_r($_POST);
echo '</pre>';
die('-----------------------------------');
(2) If that doesn't reveal the problem, next step is to duplicate the PHP file and in the second copy, HARD CODE the information you will be submitting at the top (replacing the PHP data that would normally be submitted):
<?php
$_POST['desc'] = 'TEST - Description';
$_POST['iscorrect'] = 'what it should be';
$_POST['type'] = 'TEST - Type';
etc
Then, run that modified file and see if the data is submitted.
(3) If that doesn't reveal the problem, keep working with the duplicate PHP file and add echo statements at various places to see where the file is breaking. For example:
$name = $_POST['name'];
$email = $_POST['email'];
$name = mysqli_real_escape_string($connection, $name);
echo 'HERE 01';
$name = strip_tags($name);
$email = mysqli_real_escape_string($connection, $email);
$email = strip_tags($email);
echo 'HERE 02';
if (isset($_FILES['image'])) {
$name = $_FILES['image']['tmp_name'];
$image = base64_encode(
file_get_contents(
$_FILES['image']['tmp_name']
)
);
}
echo 'HERE 03';
$sql = mysqli_query($connection, "INSERT INTO users (name,email,image) VALUES ('$name', '$email','$image')")or die(mysqli_error($connection));
echo 'HERE 04: $sql = ' .$sql;

Fatal error: Call to a member function setAttribute() on a non-object

I am trying to setup a newseltter, but in my newsletter class I keep getting the error: Fatal error: Call to a member function setAttribute() on a non-object
I have been converting the file from an older non pdo version.
<?php
class NEWSLETTER{
private static $email;
private static $datetime = null;
private static $valid = true;
function __construct($conn){
$this->db = $conn;
}
public function signup($email){
if(!empty($_POST)){
self::$email = $_POST['email'];
self::$datetime = date('Y-m-d H:i:s');
if(empty(self::$email)){
$status = "Error";
$message = "No email entered.";
self::$vaild = false;
}else if(!filter_var(self::$email, FILTER_VALIDATE_EMAIL)){
$status = "Error";
$message = "Vaild email required.";
self::$valid = false;
}
if(self::$valid){
$this->db->setAttribute(PDO::ATTR_ERRMODE_EXCEPTION);
$exist = $this->prepare("SELECT COUNT (*) FROM newsletter WHERE email='$email'");
$exist->execute();
$data_exists = ($exist->fetchColumn() > 0) ? true : false;
if(!$data_exists){
$sql = "INSERT INTO newsletter (email, date) VALUES (:email, :datetime)";
$q = $pdo->prepare($sql);
$q->execute(array(':email'=>self::$email, ':datetime'=>self::$datetime));
if($q){
$status = "Success";
$message = "You have been subscribed to the Epic Owl newsletter.";
}else{
$status = "Error";
$message = "An error occurred, try again.";
}
}else{
$status = "Error";
$message = "You have already subscribed at an earlier date.";
}
}
$data = array('status' => $status, 'message' => $message);
echo json_encode($data);
}
}
}
?>
<?php
ini_set('display_errors', '1');
require_once './includes/conn.php';
if(!empty($_POST['email'])){
$email = $_POST['email'];
$newsletter->signup($email);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>EpicOwl UK | CMS Admin Panel Mail List</title>
<meta charset="utf-8">
<link rel="shortcut icon" href="../images/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="../css/main.css">
</head>
<body>
<div id="header">
<img id="logo" src="../images/logo.png" />
<div id="navigation">
<ul>
<li>Home</li>
<li>Admin Panel</li>
</ul>
</div>
</div>
<div id="content">
<form method="post">
<br /><h2>Signup to the Epic Owl Newsletter(NOT WORKING! STILL BEING DEVELOPED!)</h2>
<input type="text" name="email" placeholder="Your Email Address" /><br /><br />
<input type="submit" name="submit" value="Signup" /><br /><br /><br /><br />
</form>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="./includes/js/lib.js"></script>
</div>
<div id="footer">
<p class="copyright">© EpicOwl UK. All Rights Reserved.</p>
</div>
</body>
</html>
$pdo is not defined anywhere in your class.
You should call setAttribute() and prepare() on your db connection, i.e. $this->db->setAttribute() provided $this->db is actually a valid connection to a DB.

Inserting data into database not working

I am writing simple blog in PHP/MySQL and I have a problem to insert some data into my database. I am trying to add comment always receive an error - Comment not added. I can't figure it out what is wrong with the code. Is anybody able to help?
<?php
if(!isset($_GET['id'])) {
header('Location: index.php');
exit();
} else {
$id = $_GET['id'];
}
if(!is_numeric($id)) {
header('Location: index.php');
}
// Include database connection
include('includes/db_connect.php');
$sql = "SELECT post_title, post_body FROM posts WHERE post_id='$id'";
$query = $db->query($sql);
//echo $query->num_rows;
if($query->num_rows != 1) {
header('Location: index.php');
exit();
}
if(isset($_POST['submit-comment'])) {
$email = $_POST['email'];
$name = $_POST['name'];
$comment = $_POST['comment'];
$email = $db->real_escape_string($email);
$name = $db->real_escape_string($name);
$comment = $db->real_escape_string($comment);
$id = $db->real_escape_string($id);
if($email && $name && $comment) {
$sqlComment = "INSERT INTO comments (post_id, email, name, comment) VALUES ('$id','$email','$name','$comment')";
$queryComment = $db->query($sqlComment);
if($queryComment) {
echo "Comment was added";
} else {
echo "Comment not added";
}
} else {
echo "Error";
}
}
?>
<! DOCTYPE html >
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--><html class=""><!--<![endif]-->
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Blog System</title>
<link rel="stylesheet" href="css/application.css" type="text/css">
<style type="text/css">
label {
display: block;
}
</style>
</head>
<body>
<div id="container">
<div id="post">
<?php
$row = $query->fetch_object();
echo "<h2>" . $row->post_title . "</h2>";
echo "<p>" . $row->post_body . "</p>";
?>
</div>
<hr>
<div id="add-comments">
<form action="<?php echo $_SERVER['PHP_SELF'] . '?id=' . $id ?>" method="post">
<label for="email">Email Address:</label>
<input type="text" name="email" id="email"><br>
<label for="name">Name:</label>
<input type="text" name="name" id="name"><br>
<label for="comment">Comment</label>
<textarea name="comment" id="comment" cols="30" rows="10"></textarea><br>
<br><br>
<input type="submit" name="submit-comment" value="Post your comment" id="postyourcomment">
</form>
</div>
</div>
<script type="text/javascript" src="js/application.min.js"></script>
</body>
</html>
<?php
if(isset($_POST['submit-comment'])) {
if(!isset($_GET['id'])) {
header('Location: index.php');
exit();
} else {
$id = $_GET['id'];
}
if(!is_numeric($id)) {
header('Location: index.php');
}
// Include database connection
include('db_connect.php');
$sql = "SELECT post_title, post_body FROM posts WHERE post_id=".$id." ";
$query = $db->query($sql);
//echo $query->num_rows;
if($query->num_rows != 1) {
header('Location: index.php');
exit();
}
$email = $_POST['email'];
$name = $_POST['name'];
$comment = $_POST['comment'];
$email = $db->real_escape_string($email);
$name = $db->real_escape_string($name);
$comment = $db->real_escape_string($comment);
$id = $db->real_escape_string($id);
if($email && $name && $comment) {
$sqlComment = "INSERT INTO comments (post_id, email, name, comment) VALUES (".$id.",'".$email."','".$name."','".$comment."')";
$queryComment = $db->query($sqlComment);
if($queryComment) {
echo "Comment was added";
} else {
echo "Comment not added";
}
} else {
echo "Error";
}
}
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Blog System</title>
<link rel="stylesheet" href="file:///C|/Users/Jaydeep Jivani/Desktop/css/application.css" type="text/css">
<style type="text/css">
label {
display: block;
}
</style>
</head>
<body>
<div id="container">
<div id="post">
<?php
$row = $query->fetch_object();
echo "<h2>" . $row->post_title . "</h2>";
echo "<p>" . $row->post_body . "</p>";
?>
</div>
<hr>
<div id="add-comments">
<form action=<?=$_SERVER['PHP_SELF']?> method="get">
<input type="hidden" name="id" value=<?=$id?> />
<label for="email">Email Address:</label>
<input type="text" name="email" id="email"><br>
<label for="name">Name:</label>
<input type="text" name="name" id="name"><br>
<label for="comment">Comment</label>
<textarea name="comment" id="comment" cols="30" rows="10"></textarea><br>
<br><br>
<input type="submit" name="submit-comment" value="Post your comment" id="postyourcomment">
</form>
</div>
</div>
<script type="text/javascript" src="file:///C|/Users/Jaydeep Jivani/Desktop/js/application.min.js"></script>
</body>
</html>
Thank you everyone for help. I found a problem which was related to my database, unfortunately I constructed table with comment_id and forgot to add AI attribute.
Thanks to #tadman I was able to rewrite my code and here is the final working result:
if(isset($_POST['submit-comment'])) {
$email = $_POST['email'];
$name = $_POST['name'];
$comment = $_POST['comment'];
$email = $db->real_escape_string($email);
$name = $db->real_escape_string($name);
$comment = $db->real_escape_string($comment);
$id = $db->real_escape_string($id);
if($email && $name && $comment) {
// Prepare statemnt
$sqlComment = "INSERT INTO comments (post_id, email, name, comment) VALUES (?, ?, ?, ?)";
$queryComment = $db->prepare($sqlComment);
$queryComment->bind_param('ssss', $id, $email, $name, $comment);
// Execute prepared statement
$queryComment->execute();
if($queryComment) {
echo "Comment was added.";
} else {
echo "There was a problem. Error: " . mysqli_error($db);
}
// Close statement
$queryComment->close();
} else {
echo "Error";
}

php form submit not working correctly

I have a page in which the user can log in. A php script check the login values.
The problem is, when I enter my details in the form, I get redirected to the .php page but I get a blank screen. When I refresh that screen, it says "Unsuccesfull" because my email and password values aren't set anymore because of the refresh.
Why do I get a blank page after pressing "Log in"?
<!DOCTYPE html>
<html>
<head>
<title>Grippee - Login</title>
<link rel="stylesheet" href="style2.css" />
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<link rel="stylesheet" href="themes/customtheme.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<a class="ui-btn-left" href="index.html" data-icon="back">Terug</a>
<h1><span>Login</span></h1>
<a class="ui-btn-right" href="#" data-icon="info">i & €</a>
</div>
<div data-role="content" data-position="relative">
<div class="loginform">
<form id="loginForm" action="login.php" method="POST">
<span>Email adres:</span>
<input type="text" name="email" id="email"></input>
<span>Wachtwoord:</span>
<input type="password" name="password" id="password"></input>
<input type="submit" value="Login" />
</form>
</div>
</div>
<div data-role="footer" data-position="fixed"></div>
</div>
</body>
</html>
The PHP:
<?php
$email = "";
$password = "";
if (isset($_POST["email"]))
{
$email = $_POST["email"];
echo ($email);
}
else {
echo("Something is wrong");
}
if (isset($_POST["password"]))
{
$password = $_POST["password"];
echo($password);
}
$mysqli = new mysqli('localhost', 'qq', 'qq', 'qq', 3306);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$result = $mysqli->query("SELECT id FROM Consument WHERE email = '$email' AND wachtwoord = '$password'");
$rows = $result->num_rows;
if ($rows == 1)
echo ("Logged in!");
else
echo ("Unsuccesfull!");
?>
the query is not correct.
use this:
$result = $mysqli->query("SELECT * FROM Customer WHERE email = " . $email . " AND wachtwoord = " . $password);
I modified a bit your php. Give a try with it. Even like this is not the best approach but..
<?php
//enable all kind of errors to can debug properly
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
$email = "";
$password = "";
if ( isset($_POST["email"]) && isset($_POST["password"]))
{
$email = $_POST["email"];
$password = $_POST["password"];
echo ($email);
echo($password);
$mysqli = new mysqli('localhost', 'qq', 'qq', 'qq', 3306);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$result = $mysqli->query("SELECT * FROM Customer WHERE email = '".$email."' and wachtwoord = '".$password."'");
$rows = mysql_num_rows($result);
if ($rows == 1)
echo ("Logged in!");
else
echo ("Unsuccesfull!");
}
else {
echo("Something is wrong");
}
?>

Categories