Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm working on a php code that connects to mysql database using beans. I have written this code for inserting record into the database using a form. However, the recode cannot be added to the database, and I dont know why. the same problem happens with the update..

Please anybody can check the code and tell me where is the problem.

<?php
        if(isset($_POST['submitted'])) {
            $dbhost='localhost:8888';
            $dbuser='root';
            $dbpass='root';
            $dbname='clients';
            $conn=mysql_connect($dbhost,$dbuser,$dbpass,$dbname);


            $cardnum = $_POST['cardnum'];
            $fname = $_POST['fname'];
            $lname = $_POST['lname'];
            $idnum = $_POST['idnum'];
            $mobnum = $_POST['mobnum'];
            $visit = $_POST['visit'];

            $sqlinsert = "INSERT INTO clients (cardnum, fname, lname, idnum, mobnum, visit)
                VALUES ('$cardnum', '$fname', '$lname', '$idnum', '$mobnum', '$visit')";

            if(!mysqli_query($conn, $sqlinsert)) {
            die("Error inserting new record");

        }
        $newrecord = "One record added successfuly";
        }

        ?>

<html>
    <head>
        <title>
            <b>Add New Client</b>
        </title>
    </head>
    <body bgcolor="#F0FFFF">
    <br/> <br/> <br/>
    <font size="4" face="WildWest" color="#4EE2EC"><b>Insert Data for the Client</b></font>
    <br/>
    <form method="post" action="Add.php">
    <input type="hidden" name="submitted" value="true"/>
    <fieldset>
        <lable><font color="#48CCCD">  Card Number: </font><input type="text" name="cardnum" size="30"/> </lable><br/>
        <lable><font color="#48CCCD"> First Name: </font><input type="text" name="fname" size="30"/> </lable><br/>
        <lable><font color="#48CCCD"> Last Name: </font><input type="text" name="lname" size="30"/> </lable><br/>
        <lable><font color="#48CCCD">ID Number: </font><input type="text" name="idnum" size="30"/> </lable><br/>
        <lable><font color="#48CCCD"> Mobile Number: </font><input type="text" name="mobnum" size="30"/> </lable><br/>
        <lable><font color="#48CCCD"> Visits:</font><input type="text" name="visit" size="30"/> </lable><br/>
    </fieldset>
    <br/>
    <input type="submit" value="Add" aligh="right"/>
    <?php
    echo $newrecord
    ?>
    </form>
    </body>
</html>
share|improve this question
    
u are mixing mysql_* and mysqli_* –  Abhik Chakraborty Apr 7 at 7:24
    
even when I use one of them, I got the same problem –  Dalia Apr 7 at 7:28
    
use mysqli_connect($dbhost,$dbuser,$dbpass,$dbname); for connecting to your database –  suhail Apr 7 at 7:37
    
I'm getting the same error :'( –  Dalia Apr 7 at 16:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.