0

Sorry, I admit, a little speak english :( so, I would like to ask for your help, a relatively simple problem. Given a form, which appears in openModal, clicking on a link(Add new):

   <a href="#openModal">Add New</a>
     <div id="openModal" class="modalDialog">
      <div>
        <a href="#close" title="Close" class="close">X</a>
          <form action="upload.php" method="post"> 
           <table align="center" class="table-form">
             <tr>
                 <td><label for='username' >Username:</label></td>
                 <td><input name='username' id='username' value='' type='text'></td>
             </tr>   
             <tr>
                  <td><label for='e-mail'>e-mail:</label></td>
                  <td><input name='e-mail' id='e-mail' value='' type='text'></td>
             </tr>    
             <tr>
                  <td colspan="2" align="center"><button type="submit" name="Submit">Save</button></td>
             </tr>
           </table>   
         </form>    
      </div>
    </div>

and click save and run the upload.php, and skips the upload.php page, if successfully saved to the database, php file and print, that "Successfully uploaded!" This is upload.php:

<?php
     $db= mysql_connect("localhost","root","");
     if(!$db)
     {
         echo "Could not connect to the database";
         exit;
     }
     $db_selected = mysql_select_db("test",$db);
     if(!$db_selected)
     {
         die("CAN'T USE THIS DATABASE: ".mysql_error());
     }
    if($_POST["username"] !="" && $_POST["e-mail"] !="")
    {
       $id = mysql_insert_id();
       $username = $_POST["username"];
       $e-mail = $_POST["e-mail"];
       $sql = "INSERT INTO `test` VALUES ('$id','$username','$e-mail')";
       $result = mysql_query($sql,$db);
       echo "Sucessfully upload!<br />\n";       
    }

?>

The connections are good, but I would like, that not to redirect the upload.php, if successful upload, but remains open to the modal, and in open modal appear to be successful upload (which provides the upload.php), and can be ok, and return to the main page!

I hope that was understandable, to help, thank you in advance! :)

s.isti91
  • 31
  • 2
  • you have to use javascript call to model when php script ends – CodeGuy Feb 16 '16 at 10:09
  • http://stackoverflow.com/questions/1960240/jquery-ajax-submit-form http://stackoverflow.com/questions/1960240/jquery-ajax-submit-form/6960586#6960586 http://stackoverflow.com/questions/30661043/show-modal-dialog-after-form-submitted https://teamtreehouse.com/community/keep-a-modal-window-open-after-form-submission – CodeGuy Feb 16 '16 at 10:12

0 Answers0