0

All a bit new to HTML, PHP and phpMyAdmin link up. Was having trouble sending form information from HTML to PHP.

My HTML code Login.html:

<form role="form" action="insert.php" method="post">
                        <div class="row">
                            <div class="col-xs-6 col-sm-6 col-md-6">
                                <div class="form-group">
                        <input type="text" name="fn" id="fn" class="form-control input-sm" placeholder="First Name">
                                </div>
                            </div>
                            <div class="col-xs-6 col-sm-6 col-md-6">
                                <div class="form-group">
                                    <input type="text" name="ln" id="ln" class="form-control input-sm" placeholder="Last Name">
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <input type="location" name="loc" id="loc" class="form-control input-sm" placeholder="Location">
                        </div>
                                                <div class="form-group">
                            <input type="email" name="email" id="email" class="form-control input-sm" placeholder="Email Address">
                        </div>
                                                <div class=" form-group">
                          <h4 >Gender</h4>
                          <input type="radio" name="gender" value="male"> Male 
                          <input type="radio" name="gender" value="female"> Female
                        </div>

                    <input  type="submit" value="Register"  onClick="signup();" class="btn btn-info btn-block">

                    </form>

My PHP code insert.php

<?php
 $dbhost = "localhost";
 $dbuser = "root";
 $dbpass = "1234";
 $db = "client";
/*
$first=$_GET("fn");
$last=$_GET("ln");
$location=$_GET("loc");
$email=$_GET("email");
*/
$connect = mysqli_connect($dbhost,$dbuser,$dbpass, $db);

mysqli_query($connect, "insert into client () values($_POST[fn]', '$_POST[ln]', '$_POST[email]', '$_POST[loc]')"); 
/*mysqli_query($connect, "insert into client values('user','name','afggei@ggwp.com','tumbartk')");  */

?>

The Error I receive:

Notice: Undefined index: fn in C:\xampp\htdocs\marion\insert.php on line 14

Notice: Undefined index: ln in C:\xampp\htdocs\marion\insert.php on line 14

Notice: Undefined index: email in C:\xampp\htdocs\marion\insert.php on line 14

Notice: Undefined index: loc in C:\xampp\htdocs\marion\insert.php on line 14

The connection does establish and work as I've tested the below code.

mysqli_query($connect, "insert into client values('user','name','afggei@ggwp.com','tumbartk')");
Francisco
  • 10,918
  • 6
  • 34
  • 45
Addy
  • 348
  • 2
  • 5
  • 17
  • You need to quote your array elements. You can't do `$_POST[fn]` you need to do `$_POST['fn']` – Jonathan Apr 02 '17 at 22:44
  • phpMyAdmin is *not* your database. MySQL is. phpMyAdmin is just a tool to make managing your database easier. That's a very basic fundamental distinction that you should know *before* you start working with databases. – John Conde Apr 02 '17 at 22:44
  • Your script is at risk of [SQL Injection Attack](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Have a look at what happened to [Little Bobby Tables](http://bobby-tables.com/) Even [if you are escaping inputs, its not safe!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) Use [prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). – John Conde Apr 02 '17 at 22:44
  • 1
    Sidenote: Seeing the commented `$_GET("x")`'s, superglobals are arrays `[]` and not functions `()`. – Funk Forty Niner Apr 02 '17 at 22:47
  • @Augwa - if it's inside a double-quoted string, the quotes are disallowed (and will trigger a parse error) unless you surround the variable with curly braces. – Quietust Apr 02 '17 at 22:49
  • 1
    `$_POST[fn]'` and that's an error in values right there. – Funk Forty Niner Apr 02 '17 at 22:51
  • @Fred-ii- Got the answer. Thanks. It was the little ' before $_POST[fn]' causing the problem. – Addy Apr 02 '17 at 22:57

0 Answers0