Çalışmayan bir MySQL veritabanı eklemek için sorguyu yerleştirin.

0 Cevap php

I'm trying to insert values from a form and insert it onto a MySQL database. But it does not work. I'm a beginner,please help.

Here is my Code:

<?php

function register(){

    $name = $_POST['name'];
    $address = $_POST['address'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
//echo $name;

$con = mysqli_connect("localhost", "root", "", "LinuxCreditSociety");
$rs = $con->query("insert into cust_mst (customer_id,customer_name,customer_address,customer_mobile,email_id)values(1003,'$name','$address','$phone','$email')");
$rs->free();
$con->close();
}

?>


<html>
    <head>
        <title>Registration</title>
    <link rel="stylesheet" type="text/css" href="phpcss.css"></link>
    </head>
    <body>
        <div style="position:absolute;left:300px;top:5px">
            <h1 align="center"><font face="Purisa" size="20" color="purple">Linux Credit Society</font></h1>
        </div>
        <div style="position:absolute;right:160px;top:5px"><img src="linux.jpg" height="150" /></div>
        <div style="position:absolute;left:140px;top:5px"><img src="linux.jpg" height="150" /></div>


    <form method="post">
        <div class="st1">
         Name:</br></br>
         Address:</br></br>
         Email-id:</br></br>
         Phone#:</br></br>
        </div>
        <div class="st2">
            <div style="position:absolute;top:5px">
                <input type="text" name="name">
            </div>
            <div style="position:absolute;top:78px">
                <input type="text" name="address"> 
            </div>
            <div style="position:absolute;top:148px">
              <input type="text" name="email">
            </div>
            <div style="position:absolute;top:218px">
                <input type="text" name="phone">
            </div>
            <div style="position:absolute;top:290px;">
            <input type="submit" value="Register">  
            </div>
        </div>
    </form>
            <div style="position:absolute;top:320px;">
                    <?php
                            if(isset($_POST['submit']) && $_POST['submit'] == "Register")
                                register();
                  ?>
            </div>
    </body>
</html>

And this is how I have created my database:

create database LinuxCreditSociety;

use LinuxCreditSociety;

create table cust_mst(
customer_id int,
customer_name varchar(50),
customer_address varchar(70),
customer_mobile double,
email_id varchar(50));

insert into cust_mst values(1001, 'Jack Mathew', 'Bandra', '9998887770', 'jackm@yahoo.com');

insert into cust_mst values(1002, 'Jill Roberts', 'Dadar', '999665550', 'jillr@rediff.com');

EDIT:

Beyler Ben sadece bir değişiklik yaptı ve ben de iğneleri üzerinde çalışacak thankyou.Now bu çalıştı!

Here is what I did:

Ben sadece gelen çağrı değişti ->

    <?php
                        if(isset($_POST['submit']) && $_POST['submit'] == "Register")
                            register();
              ?>

Bu ->

<?php
                                if(isset($_POST['name']) && $_POST['name'] != "")
                                    register();
                      ?>

0 Cevap