0

I have following HTML form.

<!DOCTYPE html>
<meta charset="UTF-8">
<html>
<head>
<title>Registreerimine</title>
</head>
<body>
<strong>Registreerimiseks täida järgnevad väljad: </strong><br>
<br>
<form method="POST" action="registreerimine3.php">
<table>
<tr><td>Sinu Tieto e-maili aadress: </td><td><input type="text" name="email"></td></tr>
<tr><td>Eesnimi: </td><td><input type="text" name="eesnimi"></td></tr>
<tr><td>Perekonnanimi: </td><td><input type="text" name="perekonnanimi"></td></tr>
<tr><td>Parool: </td><td><input type="text" name="parool"></td></tr>
<tr><td>Parool uuesti: </td><td><input type="text" name="parooluuesti"></td></tr>
</table>
<br>
<input type="submit" value="Registreeri">
</form>
</body>
</html>

and following PHP code:

<?php

$con = mysql_connect("localhost","root","password");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 mysql_select_db("tieto", $con);


$email = mysql_real_escape_string($_POST['email']);
$eesnimi = mysql_real_escape_string($_POST['eesnimi']);
$perekonnanimi = mysql_real_escape_string($_POST['perekonnanimi']);
$parool =  $_POST['parool'];
$parool_uuesti =  $_POST['parooluuesti'];

$salt = rand(1000000,99999999);
$hashed_pwd = sha1('$parool'.$salt);
$sql="INSERT INTO kasutajad6 (email, eesnimi, perekonnanimi, parool, salt ) VALUES ('$email','$eesnimi', '$perekonnanimi', '$parool', '$salt')";

 if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

echo "Kasutaja loodud";

 mysql_close($con)

?>

When I try to insert data from HTML form into MySQL database, I get following message:

Notice: Undefined index: email in C:\xampp2\htdocs\registreerimine\registreerimine3.php on line 17

Everything I need is after that in database except e-mail. My Database is created with following SQL command:

mysql> create table kasutajad6 ( userID int(9) NOT NULL auto_increment,email var
char(45) NOT NULL, eesnimi varchar(45) NOT NULL, perekonnanimi varchar(45) NOT N
ULL, parool varchar(45), salt int(8), PRIMARY KEY(userID));
Query OK, 0 rows affected (0.73 sec)

The strange thing is, everything worked fine for a while, but i changed some code and it wont work anymore. Even if i undo changes.

It is a long question and I would be very thankful if someone answers me.

user244902
  • 143
  • 4
  • 14
  • At begining of PHP code add somethign like this `var_dump($_POST);`. This will show your POST and chack if all fields of this array are present. Your error message say there is no `email` in `$_POST`. You can post result here if you still have problem. – Volvox Apr 02 '14 at 14:02

2 Answers2

0

mysql_real_escape_string seems to be the problem here, it "returns the escaped string, or FALSE on error" - see http://uk1.php.net/mysql_real_escape_string.

If it's returning false, it could be causing an issue for you when inserting into your MySQL database.

It's also deprecated as of PHP 5.5.0. Deos it work when you remove the mysql_real_escape_string method from the $_POST['email'] variable?

Dave Harding
  • 481
  • 1
  • 4
  • 19
0

This error occurs when the variable is not set. Check if the variable $email is set (using isset()) and go through the following link.

I see that you have not named your input tag used to submit the form. Give a name to it <input type='submit' name='submit' value='Registreeri'> and put the whole script used for inserting the values inside an if(isset($_POST['submit'])) {} where submit is the name assigned to the input (submit) tag.

Community
  • 1
  • 1
Vagabond
  • 877
  • 1
  • 10
  • 23