0

I have an issue inserting data to table in php,the problem I am facing maybe it is not difficult to solve but Im new in php development and could not solve it, here is my code

  <table class="table-fill">

<tbody class="table-hover">
<tr>
<td class="text-left"><input type = "text" class = "form-control" 
               name = "name"></td>
<td class="text-left">name</td>
</tr>
<tr>
<td class="text-left"><input type = "text" class = "form-control" 
               name = "Quantity" id="QTY"></td>
<td class="text-left">QTY</td>
</tr>
<tr>
<td class="text-left"><input type = "text" class = "form-control" 
                             name = "Type" id="type"></td>
<td class="text-left">type</td>
</tr>
<tr>
<td class="text-left"><input type = "text" class = "form-control" 
               name = "price" id="prs"></td>
<td class="text-left">price</td>
</tr> 
<tr>
<td class="text-left"><input type="file" name="fileToUpload" id="fileToUpload"></td>
<td class="text-left">image</td>
</tr>
<tr>
    <td class="text-left">  <input type="submit" value="Submit1" name="Submit1"></td>
<td class="text-left">Register</td>
</tr>
</tbody>
</table>
                        

 </div>
        <div id="footer">
  <div>
   
  </div>
 </div>
         <?php
 
   $dbhost = 'localhost';
   $dbuser = 'root';
   $dbpass = '';
   
    
   $conn = mysql_connect($dbhost, $dbuser, $dbpass);
   
   if(! $conn ) {
      die('Could not connect: ' . mysql_error());
   }
  
   if (isset($_post('Submit1')))
   {
   $name=filter_input(INPUT_POST,'name');
   $QTY=filter_input(INPUT_POST,'Quantity');
   $type=filter_input(INPUT_POST,'Type');
   $sql = "INSERT INTO products (ProductName, Quantity,Price)
    VALUES ('$name','$QTY','$type')";


//('$_POST['name']','$_POST['Quantity']','$_POST['Type']')";      
   mysql_select_db('pharmacynew');
   $retval = mysql_query( $sql, $conn );
   
   if(! $retval ) {
      die('Could not enter data: ' . mysql_error());
   }
   
   echo "Entered data successfully\n";
   
   mysql_close($conn);
}       // put your code here
        ?>
    </body>
</html>

the problem Iam facing when I run the page ,it shows me this error "Fatal error: Cannot use isset() on the result of a function call (you can use "null !== func()" instead) " Can any body tell me why is this problem appearing and how to overcome it, many thanks

1 Answers1

1

The problem is in this line:

if (isset($_post('Submit1')))

By using regular brackets ( and ) you're trying to use $_post as a function instead of a variable. That's not allowed within isset().

You need to use angled brackets [ and ] to read values from the $_post array (which should be $_POST in uppercase, by the way).

Simply change that line to

if (isset($_POST["Submit1"]))
JustCarty
  • 3,839
  • 5
  • 31
  • 51
rickdenhaan
  • 10,857
  • 28
  • 37