0

I created Simple from with database

Database:

CREATE TABLE IF NOT EXISTS klient (
    idklienta int(20) NOT NULL AUTO_INCREMENT,
    imie varchar(20) NOT NULL,
    nazwisko varchar(20) NOT NULL,
    nick varchar(20) NOT NULL,
    numer varchar(20) NOT NULL,
    email varchar(50) NOT NULL,
    telefon varchar(15) NOT NULL,
    dataiczaszam datetime NOT NULL,
    PRIMARY KEY (idklienta)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

PHP code:

require("connect.php");
connection();

$name=$_POST['name'];
$surname=$_POST['surname'];
$nick=$_POST['nick'];
$mail=$_POST['email'];
$telefon=$_POST['telefon'];
$kod=$_POST['kod'];
if (!empty($_POST['name'] && $_POST['surname'] && $_POST['nick'] && $_POST['email'] && $_POST['telefon']) && $_POST['kod']){
    $query ="INSERT INTO klient (idklienta,imie,nazwisko,nick,numer,email,telefon,kod) values ('null',$name','$surname','$nick','$mail','$telefon','$kod')";
    mysql_query($query);
    mysql_close();
}

conncet.php

$db_name='calendar';
$host='localhost';
$user='root';
$pass='';
@msql_connect($host, $user, $pass) or die('brak polaczenia z msql');
@msql_select_db($db_name) or die('brak polaczenia z baza danych');

index.php (form)

<form  action="register.php"  method="post">
      <fieldset>
            <table align="center">
                <tr>
                    <td>Imię</td>
                    <td><input  type="text" name="name" required></td>
                </tr>

                    <td>Nazwisko</td>
                    <td><input id="nazwisko"type="text" name="surname"required></td>
                </tr>
                <tr>
                    <td>Nick allergo</td>
                    <td><input  type="text" name="nick" required></td>
                </tr>
                <tr>
                    <td>Numer aukcji</td>
                    <td><input type="text" name="numer"required></td>
                </tr>
                <tr>
                    <td>Kod werfikacji</td>
                    <td><input type="text" name="kod"required></td>
                </tr>
                <tr>
                    <td>E-mial</td>
                    <td><input type="email" name="email" required/></td>
                </tr>
                <tr>
                    <td>Telefon</td>
                    <td><input type="phone" name="telefon"required/></td>
                <tr>

            </table>
     </fieldset>        
    <input id="add"type="submit" name="add" value="Wyślij">
    </tr>
    </form>

but I can't insert data in database . What am I doing wrong?

Matthias J. Sax
  • 59,682
  • 7
  • 117
  • 137

3 Answers3

0

there are 8 fields in the first brackets and only 7 values in your 2nd brackets of your insert statement:

$query ="INSERT INTO klient (idklienta,imie,nazwisko,nick,numer,email,telefon,kod) values ('null',$name','$surname','$nick','$mail','$telefon','$kod')"; 

there are some other issues, too. (Take a look at your quotation marks) The null-value of your autoincrement-field should not be in quotation marks.

But this seems to be the main issue. Do not use mysql_* functions. Use prepared statements!

steven
  • 4,868
  • 2
  • 28
  • 58
0

I correct my php code connect.php

<?php 
$con= new mysqli("localhost","root","","calendar");

    if ($con->connect_error) { 
    // w przypadku błędu (od wersji PHP 5.3), wyświetli się odpowiedni komunikat 
    die('Connect Error ('.$con->connect_errno.') '. $con->connect_error); 
    // w przypadku błędu (do wersji PHP 5.3), wyświetli się odpowiedni komunikat 
    if (mysqli_connect_error()) { 
       die('Connect Error (' . mysqli_connect_errno() . ') ' 
       . mysqli_connect_error()); 
    } 
}
?>

register.php

<?php 

require_once('connect.php');

    $name=$_POST['name'];
    $surname=$_POST['surname'];
    $nick=$_POST['nick']; //nick allegro
    $numer=$_POST['numer']; //numer aukcji
    $kod=$_POST['kod'];
    $eami=$_POST['email'];
    $phone=$_POST['telefon'];

        $query ="INSERT INTO klient (idklienta,imie,nazwisko,nick,numer,email,telefon,kod) 
        values (null,'$name','$surname','$nick',$numer','$eami','$phone','$kod')";
        mysqli_query($con,$query);


    if ($con->query($query) === TRUE) {
          echo "New record created successfully";
    } else {
            echo "Error: " . $query . "<br>" . $con->error;
    }

        $con->close();

?>

index.php

<form  action="register.php"  method="post" enctype="multipart/form-data">
      <fieldset>
        <legend>Dane osobowe</legend>
            <table align="center">
                <tr>
                    <td>Imię</td>
                    <td><input  type="text" name="name" required></td>
                </tr>

                    <td>Nazwisko</td>
                    <td><input id="nazwisko"type="text" name="surname"required></td>
                </tr>
                <tr>
                    <td>Nick allergo</td>
                    <td><input  type="text" name="nick" required></td>
                </tr>
                <tr>
                    <td>Numer aukcji</td>
                    <td><input type="text" name="numer"required></td>
                </tr>
                <tr>
                    <td>Kod werfikacji</td>
                    <td><input type="text" name="kod"required></td>
                </tr>
                <tr>
                    <td>E-mial</td>
                    <td><input type="email" name="email" required/></td>
                </tr>
                <tr>
                    <td>Telefon</td>
                    <td><input type="phone" name="telefon"required/></td>
                <tr>

            </table>
     </fieldset>
   <br><br>         
    <input id="add"type="submit" name="add" value="Wyślij">
    </tr>
    </form>

show error Error: INSERT INTO klient (idklienta,imie,nazwisko,nick,numer,email,telefon,kod) values (null,'dsgfgfd','hfghfhgr','fhgfg',ghfg','ghfg@gmail.com','54576567556','ghfgh') You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '','ghfg@gmail.com','54576567556','ghfgh')' at line 2

  • you have again a missing `'` before `$numer'`! Please do not ask another question as an answer. Update your original question instead! – steven Nov 11 '15 at 15:13
-1

you are not providing enctype="multipart/form-data"in the form tag. try to insert this and let the form know about type of data posted. Your issue will be resolved.

Muhammad Azam
  • 328
  • 1
  • 4
  • 14
  • she is sending data at least and form should know that what type of data you are sending – Muhammad Azam Nov 12 '15 at 05:12
  • Please read the accepted answer of this thread: http://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean The HTMLs default `application/x-www-form-urlencoded` is correct for the given use case. Like the author of the given thread says: use `multipart/form-data` when your form includes any `` elements. And there are no files to post here! Although it should work it doesnt solve the issue here. There are many bugs posted here but this is not one of them. – steven Nov 12 '15 at 07:18