I can't figure this annoying thing out I've tried it over and over but still getting this error: Notice: Undefined index: example1 in G:\xampp\htdocs\testing\whatever.php on line 15 Notice: Undefined index: example2 in G:\xampp\htdocs\testing\whatever.php on line 16 Please help :s The code: <?php $sql = mysql_connect("localhost","root","") or die (mysql_error()); if (!isset($sql)) {echo "Could not connect to DB";} $select_db = mysql_select_db("test", $sql); if (!isset($select_db)) { echo "Could not connect to DB";} $example1=($_POST['example1']); $example2= ($_POST['example2']); mysql_query ("INSERT INTO test (test1, test2) VALUE ('$example1', '$example2')"); ?> <html> <body> <form action="whatever.php" method="post"> Username: <input type="text" name="example1" /><br> Password: <input type="password" name="example2" /><br> <input type="submit" value ="register" /> </form> </body> </html>
If $_POST['example1'] is undefined, $example1 is also undefined. $example1 = isset($_POST['example1'] ? $_POST['example1'] : ''; $example2 = isset($_POST['example2'] ? $_POST['example2'] : ''; That will eliminate your error. If will insert blanks, though, if the POST values are undefined. You may want to use Javascript to make sure they have some values before submitting the page. Also, it's VALUES(, not VALUE(.