0

I'm trying to build an html form and connecting it to a php file which is doing the query and insert the information to mysql database.

Here is my html code:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Add Record Form</title>

</head>

<body>

<form action="/joomla_31/insert.php" method="post">


<label for="MGMT_IP">MGMT IP</label>

<input type="text" name="MGMT_IP" id="MGMT_IP">

</p>

<p>

<label for="Vendor">Vendor</label>

<input type="text" name="Vendor" id="Vendor">

</p>

<p>

<label for="Version">Version</label>

<input type="text" name="Version" id="Version">

</p>

<p>

<label for="GUI_User">GUI User</label>

<input type="text" name="GUI_User" id="GUI_User">

</p>

<p>

<label for="GUI_Pass">GUI Pass</label>

<input type="text" name="GUI_Pass" id="GUI_Pass">

</p>


<input type="submit" value="submit">

</form>

</body>

</html>

And Here is my insert.php file:

<?php


$link = mysqli_connect("localhost", "root", "", "mysql");



// Check connection

if($link === false){

die("ERROR: Could not connect. " . mysqli_connect_error());

}



// Escape user inputs for security

$MGMT_IP = mysqli_real_escape_string($link, $_REQUEST['MGMT IP']);
$Vendor = mysqli_real_escape_string($link, $_REQUEST['Vendor']);
$Version = mysqli_real_escape_string($link, $_REQUEST['Version']);
$GUI_User = mysqli_real_escape_string($link, $_REQUEST['GUI User']);
$GUI_Pass = mysqli_real_escape_string($link, $_REQUEST['GUI Pass']);



// attempt insert query execution

$sql = "INSERT INTO `cloud_team` (MGMT IP, Vendor, Version, GUI User, GUI Pass) VALUES (`$customer_number`, `$customer_name`, `$MGMT_IP`, `$Vendor`, `$Version`, `$GUI_User`, `$GUI_Pass`)";

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);

?>

But every time I click on the submit button I get a blank page ... It is like it is redirecting the correct file (http://x.x.x.x/joomla_31/insert.php) .. but nothing executed ...no error displayed .. only a blank page

ac89live
  • 41
  • 7
  • [How to enable PHP error display](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) - this might help to debug your code – lumio Aug 27 '17 at 07:36
  • Thanks lumio , I edited the php.ini file from "display_errors = off" to "display_errors = on" Now I'm getting this error: Parse error: syntax error, unexpected '''' (T_CONSTANT_ENCAPSED_STRING) in C:\inetpub\wwwroot\joomla_31\joomla_31\insert.php on line 23 – ac89live Aug 27 '17 at 07:44
  • It seems that Joomla expects some other type of arguments – lumio Aug 27 '17 at 07:47
  • yeah , it was an extra ' in the code .. can't belive this took from me 2 hours to recognize O_o .. now moving to another error: ERROR: Could not able to execute INSERT INTO cloud_team (MGMT IP, Vendor, Version, GUI User, GUI Pass) VALUES (`101010111`, ``, ``, `Juniper`, ``, ``, ``, ``). 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 'MGMT IP, Vendor, Version, GUI User, GUI Pass) VA' at line 1 – ac89live Aug 27 '17 at 08:02
  • Please update your question then – lumio Aug 27 '17 at 08:34
  • thanks.. nevermind , problem resolved :) .. i used a different quotes for the columns : used this : '$customer_number' instead of this `$customer_number` how do i mark your answer as an accepted solution ? – ac89live Aug 27 '17 at 08:38
  • I added an answer – lumio Aug 27 '17 at 08:43

1 Answers1

0

Enable PHP error display to better debug your code. Look at this answer for more details.

lumio
  • 7,428
  • 4
  • 40
  • 56