-1

hi people i have these two scripts for fill a database table on my PC , with an HTML form . the HTML code works perfect but the php it just does not work , i have specified everything ,but it just doesn't work , when i give click on submit the browser just pop ups a download option but nothing else...

<html>
<head>
<tittle>
<h1 > <b> FORMAT FOR TECHNICAL ISSUES
<link rel="stylesheet" href="/var/www/html/proyecto/css/styles.css">
 </b> </h1>
</tittle>
<hr> </hr>
</head>
<body>
<div>
 <img src="logo.png" width=100%   /img>
<hr> </hr>
<form method="POST" action="">   
<input type="text" placeholder="NOMBRE" name="Nombre"  maxlenght="30" size="20px" id="nombre"  > 
<input type="text" name="Extension"  placeholder=EXTENSION  maxlength="5" id="extension">
<br>
<hr> </hr>
<br>
<br>
<h2> CAMPAIGN /CAMPAÑA </h2>
<br>
<label for="Campaign"> Select your campaign:</label>
<select name="Campaign" id="campaign"  >Campaign
    <option value="Procall">Procall</option>
    <option value="Tigo">Tigo</option>
    <option value="Spanish">Spanish</option>
</select>
<hr> </hr>
<h2> KIND OF FAILURE </h2>
<label for="Tipo de incidente">Select the type of incident:</label>
<select id="incident"  name="incidente"  placeholder="Tipo de incidente">incident
    <option value="Slow Computer">Slow Computer</option>    
    <option value="Headset fail"> Headset Fail </option>
    <option value="Zoiper Issue">Zoiper Issue </option>
       <option value="Crm Issue">Crm Issue </option>
       <option value="Spark Issue">Spark Issue </option>
       <option value="Vc Dialer Issue">VC Dialer Issue </option>
       <option value="Network Issue">Network Issue </option>
</select>
<input type"text" id="description"  name="Description" placeholder=DESCRIPTION style="width:300px;height:100px">
<br></br>
<h2>FAILURE DATE </h2>
<label for="failure date"> Enter the day and hour when failure occurred :</label>
<input name="failure_date"   type="date-time-local" placeholder="yyyy/mm/dd/hh/mm"  id="failure date" min="2018-05-01T08:30" max="2018-12-30T22:30"  >
<br>
<hr></hr>
<label for="did you lose a call?" id="lost_call" >Did you lose any call?:</label>
<br>
 <input type="radio" name="lost call" value="yes " id="lost_call" > Yes , i lost a call.
<br> 
<input type="radio" name="lost_call" value="no" id="lost_call" >No i have not lost any call
<br
<br>
<label id="lost docmuent"  for="did you lose any document?"> Did you lose any document or information?:</label>
<br>
<input type="radio" name="document" value="yes"> Yes i lost one or more documents
<br>
<input type="radio" name="document" value="no"> No have not lost any document. 
<br>
<br>
<label for="did you have to log out?" id="logout" > Did you have to logout?:</label>
<br>
<input type="radio" name="logout" value="yes">Yes i had to logout
<br>
<input type="radio" name="logout" value="no">no  i didn't have  to logout
<br>
<br>
<br>
<br>
<input type="submit">
 </form>
 </div>
 </body>
 </html>

and here is the php script for the action and connect to the sql database

<?php
 $con = mysql_connect("localhost","root","m0l0t0v" );
 if (!$con) {
      die('Could not connect: ' . mysql_error());
}
mysql_select_db("it", $con);
$sql="INSERT INTO tec-issues (Nombre,Extension ,Campaign ,incidente,Description,failure_date,lost_call,document,logout )
VALUES
('$_POST[Nombre]', '$_POST[Extension]', '$_POST[Campaign]', '$_POST[incidente]', '$_POST[Description]', '$_POST[failure_date]', '$_POST[lost_call]', '$_POST[document]', '$_POST[logout]' )";
if (!mysql_query($sql,$con)) {
      die('Error: ' . mysql_error());
} 
echo "1 record added";
mysql_close($con)
?>

PLEASE HELP ME EVERYTHING IS CORRECT , BUT IT JUST DONT WORK

user3783243
  • 5,368
  • 5
  • 22
  • 41
average
  • 1
  • 6
  • Can you be more specific about what exactly "doesn't work?" – WillardSolutions May 22 '18 at 21:12
  • wel i created a database and a table , that i specified in the php script to insert the values , but when i fill the fields of the form , only opens a pop up where gives the option to download the script ,but it does not write nothing on the table , the database remains empty – average May 22 '18 at 21:16
  • 1
    Possibly relevant: [Apache is downloading php files instead of displaying them](https://stackoverflow.com/questions/18422140/apache-is-downloading-php-files-instead-of-displaying-them). – showdev May 22 '18 at 21:21
  • Turn on error reporting, check your logs, do other basic debugging things.... – WillardSolutions May 22 '18 at 21:24
  • When you get this working you will be open to SQL injections. Don't use `mysql_*` functions anymore. – user3783243 May 22 '18 at 21:25
  • Are you running a webserver and PHP module? – showdev May 22 '18 at 21:54
  • i think , i installed apache and php7.0 , so i guess – average May 22 '18 at 21:59
  • so I'm guessing your PHP file is saved as `.php`? – hungrykoala May 23 '18 at 00:05
  • yes sir , it is saved , it is throwing me this output:Call to undefined function mysql_connect() , it is because i must use mysqli – average May 23 '18 at 00:07

1 Answers1

-1

Check syntax for mysql_select_db it should be mysql_select_db($con,"dbname") and please use mysqli prefix instead of mysql because it is safer.

I recommend using msqli_escape_string for every data you get from POST or GET to protect from sql injection

SloCompTech
  • 116
  • 1
  • 7