I'm very new guy on php. I have a website project on my course. I'm stuck on this part and could not move more. Need to help for solving this. I tried to reach email and password like on my code, this error says it's not like this.
I have an error like this:
Notice: Undefined index: email in C:\xampp\htdocs\CONFIG.PHP on line 6 Notice: Undefined index: password in C:\xampp\htdocs\CONFIG.PHP on line 7 Info could not write on database!
(solved with
if($_SERVER['REQUEST_METHOD'] == 'POST') {
//...
) but now any info does not go to database
config.php:
<?php
ob_start();
include "dbconnect.php";
$email=$_POST["email"];
$password=$_POST["password"];
$username=$_POST["username"];
$submit = isset($_POST['submit']) ? $_POST['submit'] : null;
$sql="select * from users where email = '".$email."' and password = '".$password."' and username = '".$username."'";
$query=mysql_query($sql);
$counter=mysql_num_rows($query);
if ($counter!=0){
echo "<font size= 3 >This user has been registered before. Please check information.</font>";
}else{
$sql2 = "INSERT INTO users(email, password, username) VALUES ('".$email."','".$password."','".$username."'";
$add = mysql_query($sql2);
if($submit){
echo "<br>You have registered successfully!
Please click. ";
header("Location:regedIndex.html");
}else{
echo "Info could not write on database!";
}
ob_end_flush();
}
?>
register.html:
<html>
<head>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<link type="text/css" rel="stylesheet" href="popupbox.css"/>
<link type="text/css" rel="stylesheet" href="main.css"/>
<script type="text/javascript" src="https://www.google.com/jsapi">
</script>
</head>
<body>
<div id="logo">
<div id="left" style="width: 500px;
height: 100px; margin: 10px 15px 10px 8px;">
<a href="index.php">
<img src="images/logo.png">
</a>
<div id="right">
</div>
</div>
<div id="login">
<div id="triangle"></div>
<h1>Register</h1>
<form action="config.php" method="post">
<input type="email" name="email" placeholder="Email" />
<input type="text" name="username" placeholder="Username" />
<input type="password" name="password" placeholder="Password" />
<input type="submit" value="Register"/>
</form>
</div>
</br></br></br></br></br></br></br></br></br></br></br></br></br></br>
<div id="contacts">
<footer id="footer">
<ul class="icons">
<li>
<a href="https://twitter.com/voteproject"> <img src="images/twitter.svg"></a>
<a href="https://facebook.com/voteproject"> <img src="images/facebook.svg"></a>
<a href="https://github.com/CS320VoteProject/VoteProject"> <img src="images/github.svg"></a>
</li>
</ul>
</footer>
</div>
</body>
</html>