Hello everyone,

My friend has been helping and he's been great however it's come to a halt :P

I'm working with MYSQL at the moment but am having a few issues with my code.

Index.php:

<html><link href="stylesheet.css" rel="stylesheet" type="text/css">
<head>
</head>
<body>
<div id="header"><img src="http://www.rhinosecurityltd.co.uk/templates/rhuk_milkyway/images/mw_joomla_logo.png" alt="Rhino Security"> </DIV>
<form name="Form" action="SQL.php">
<!--Intro-->
<h3>Introduction</h3>
Client/Company Name: <input type="text" name="clientname"><br>
Contact / Letter name: <input type="text" name="contactname"><br>
Notes: <textarea rows="5" cols="30" name="notes">
Notes
</textarea><br>
System Type <select name="system">
<option value="type1">type1</option>
<option value="type2">type2</option>
<option value="type3">type3</option>
<option value="type4">type4</option>
<option value="none" selected="selected">None</option>
</select><br>
Status <select name="status">
<option value="alive" "selected">Alive</option>
<option value="dead">Dead</option>
<option value="stop">Stop</option>
</select><br>
Signal Type<select name="signaltype">
<option value="signal 1" "selected">Signal 1</option>
<option value="signal 2">Signal 2</option>
<option value="signal 3">Signal 3</option>
</select><br>
Verification Method<select name="verification">
<option value="verify1" "selected">verify1</option>
<option value="verify2">verify2</option>
<option value="verify3">verify3</option>
</select><br>
</div>
<!--End of intro-->

<!--Start of Address etc-->
Address: <textarea rows="5" cols="30" name="address"></textarea><br>
Postcode: <input type="text" name="postcode"><br>
Telephone: <input type="text" name="telephone"><br>
Mobile: <input type="text" name="mobile"><br>
Mobile2: <input type="text" name="mobiletwo"><br>
Email: <input type="text" name="email"><br>
Main Area: <input type="text" name="mainarea"><br>
<!--End of Address-->

<!--Start of Dates-->
Installation Date: <input type="date" name="installation"><br>
Contract Type: <input type="text" name="Contract"><br>
Expiration date: <input type="date" name="expiration"><br>
Services Per Annum: <select name="SPA">
<option value="0anum">0</option>
<option value="1anum">1</option>
<option value="2anum">2</option>
<option value="none" selected="selected">None</option>
</select><br>
Next Service: <input type="date" name="nservice"><br>
Appointment Req: 
<!--End of Dates-->

<!--Start of Financial Details-->
Invoice Run: ??<br>
Invoice Code:??<br>
<!--End of Financial Details-->
<!--Start of Charges-->
Maintenance: <input type="number" name="maintenance"><br> 
Monitoring: <input type="number" name="monitoring"><br>
<!--End of Charges-->
<!--Start of Monitored System-->
Y/N: <select name="MS">
<option value="myes">Yes</option>
<option value="mno">No</option>
</select><br>
<!--End of Monitored System-->
<!--Start of Certificate details-->
Date: <input type="date" name="certdate"><br>
Certificate: ??
<!--End of Certificate details-->
<p>
<input type="submit" value="Submit">
</form> 
<div>
</body>
</html>

SQL.php:

<?php

    // Grab our POSTed form values
    // Note that whatever is enclosed by $_POST[""] matches the form input elements
    $clientname= $_POST["ClientName"];
    $contactname= $_POST["ContactName"];
        // Connect to our DB with mysql_connect(<server>, <username>, <password>)
        $sql_connection = mysql_connect("localhost", "xtrapsp_rhino", "passwrod");
        mysql_select_db("xtrapsp_Rhino", $sql_connection);

        $sql = "INSERT INTO Customers(
                    ClientName,
                    ContactName,
            ) VALUES (
                '$clientname',
                '$contactname',
                NOW()
            )";
    mysql_query(Mysql_real_escape_string($sql), $sql_connection);
    mysql_close($sql_connection);
?>

This is the code on: http://rhino.minepress.co.uk/

The problem I'm having is I don't know if it is submitting the information to the database, I have a Database called xtrapsp_Rhino

And inside that I have a table called Customers, inside that I have 3 different columns.

Picture:

http://i.imgur.com/z9BLD.png

Any help as to why it's not submitting ANY data?

$sql = "INSERT INTO Customers(
          ClientName,
          ContactName,
          Date column is missing here
        ) 
        VALUES (
          '$clientname',
          '$contactname',
          NOW()
        )";

If you don't have a date column, remove the comma after ContactName, and remove NOW (and the comma after $contactname).

Use mysql_real_escape_string, all lower case.

Hey, Thanks for the response.

<?php
    // Grab our POSTed form values
    // Note that whatever is enclosed by $_POST[""] matches the form input elements
    $clientname= $_POST["ClientName"];
    $contactname= $_POST["ContactName"];
        // Connect to our DB with mysql_connect(<server>, <username>, <password>)
        $sql_connection = mysql_connect("localhost", "xtrapsp_rhino", "password");
        mysql_select_db("xtrapsp_Rhino", $sql_connection);
        $sql = "INSERT INTO Customers(
                    ClientName,
                    ContactName
            ) VALUES (
                '$clientname',
                '$contactname'
            )";
    mysql_query(mysql_real_escape_string($sql), $sql_connection);
    mysql_close($sql_connection);
?>

Made All those changes :)

I'm not sure if it is something I have setup wrong in the Index.php Or the MYSQL. I still can't see why there is no data inside the MYSQL.

When I click in the customers Table I get this:

MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0009 sec )

Try it without the mysql_real_escape_string. Notice only now. It will mess up the quotes that are necessary around the values. If you want to use it, use it on the variables like this:

$clientname = mysql_real_escape_string($_POST["ClientName"]);
$contactname = mysql_real_escape_string($_POST["ContactName"]);
// ...
mysql_query($sql, $sql_connection) or die(mysql_error());

Thanks pritaeas, I realised that what was previous still works except I wasn't using the right $_POST names in relation to the DB :P

Silly me!

Thanks again Upvoted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.