inserting into database

Hi,

I am new to php and currently I am trying to add info to a database. The database is ERP and the table is customers.

I created the html file below and the php file below. The problem is that the php is not posting the data into the table.

Please can you have a look and let me know what I am doing incorrect.

HTML:

[code]<!doctype html>

Add New Customer

Business Name:

Vat:

Address:

Telephone Number:

Cell Number:

Email Address:

Fax Number:

Contact Person:

[/code] PHP:

[php]<!doctype html>

Untitled Document <?php /* Attempt MySQL server connection. Assuming you are running MySQL server with default setting (user 'root' with no password) */ $link = mysqli_connect("localhost", "ash", "********"); $selected = mysql_select_db("ERP",$dbhandle) or die("Could not select server"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } // Escape user inputs for security $businessname = mysqli_real_escape_string($link, $_POST['businessname']); $vat = mysqli_real_escape_string($link, $_POST['vat']); $address = mysqli_real_escape_string($link, $_POST['address']); $telephonenumber = mysqli_real_escape_string($link, $_POST['telephonenumber']); $cellphonenumber = mysqli_real_escape_string($link, $_POST['cellphonenumber']); $emailaddress = mysqli_real_escape_string($link, $_POST['emailaddress']); $faxnumber = mysqli_real_escape_string($link, $_POST['faxnumber']); $contactperson = mysqli_real_escape_string($link, $_POST['contactperson']); // attempt insert query execution $sql = "INSERT INTO customers (businessname, vat, address, telephonenumber, cellphonenumber, emailaddress, faxnumber, contactperson) VALUES ('$businessname', '$address', '$telephonenumber', '$cellphonenumber', '$emailaddress', '$faxnumber', '$contactperson' )"; if(mysqli_query($link, $sql)){ echo "Records added successfully."; } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // close connection mysqli_close($link); ?> [/php] Any help will be appreciated.

thank you

You are mixing Mysqli with mysql.

By the way, you do not have a properly normalized database design. What if a Company has more than one phone number, more than one email, more than one contact, a mailing address and a physical address and a shipping address?

Hi,

Thank you for the info.

I have had a look and will take you advice and add the additional input fields.

Please can you assist in the code?

Your insert statement is incorrect, the column count is incorrect.

Sponsor our Newsletter | Privacy Policy | Terms of Service