skip to Main Content

I am trying to build a Chrome plugin. In the main folder, I have a popup.html which runs by default and uses the following syntax in manifest.json

"browser_action": {
   "default_icon": "icon.png",
   "default_popup": "popup.html"
  },

the popup.html is working absolutely fine

what is my popup.html is doing?

It is inputting email from the user and storing it in local phpmyadmin.
Following is the code of popup.html

<!doctype html>
<html style="min-width:350px;">
  <head>
    <title>Welcome</title>   
  </head>
  <body>
<h3> Enter email </h3>

<form action=”info.php” method=”post”>
Enter email: <input type=”email” name=”email” />
<input type="submit" value="Submit" >
</form>

  </body>
</html>

The form action is linked to info.php where the php connects the database and inserts the data into the table in phpMyAdmin.
Following is the info.php code

<html>

<body>

<?php 
$con = mysql_connect('127.0.0.1','root','');
if (!$con)
{
    echo'Could not connect to the server';
}
if (!mysqli_select_db($con,'test'))
{
    echo 'Database Not Selected';
}
$Email = $_POST[email];

$sql = "INSERT INTO test_table(Email) VALUES ('$Email')";
if(!mysqli_query($con,$sql))
{
    echo 'Could not add to database';
}

else
{
    echo 'Thank you the data is added';
}

header("refresh:2; url=popup.html");
?>
</body>

</html>

What problem am I facing?
After I enter the email in the input field it gives an error that Your file was not found It may have been moved or deleted.
ERR_FILE_NOT_FOUND

Maybe I am getting this error because info.php has to added in the manifest file? If this is the problem then how can I add multiple urls in the manifest.json file?

2

Answers


  1. Chosen as BEST ANSWER

    with @wOxxOm help the problem was solved. In the popup.html instead of giving info.html directly, it would have been through the server such as http://localhost/foldername/info.php


  2. Your header won’t work, since you have already echoed output.

    Instead of outputting immediately, stick the output into an $html variable.

    This might not completely fix your issue? But it will fix the header.

    <?php 
    
    $html = '';
    
    $con = mysql_connect('127.0.0.1','root','');
    if (!$con)
    {
        $html .= 'Could not connect to the server';
    }
    if (!mysqli_select_db($con,'test'))
    {
        $html .= 'Database Not Selected';
    }
    $Email = $_POST[email];
    
    $sql = "INSERT INTO test_table(Email) VALUES ('$Email')";
    if(!mysqli_query($con,$sql))
    {
        $html .= 'Could not add to database';
    }
    
    if (empty($html)) {
        header("refresh:2; url=popup.html");
    } 
    
    echo $html;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search