1

I have done a program who show a list of youtube video and when I click on one of them, I open a bootstrap modal. There I want input some data to video_time_table. It is working whithout problems, but I need to input the video_id_nr from the video_name_table into the video_time_table to link them together. It working OK on my first try. Next try it stop on the insert_timestamp.php. The data is inserted into the database but the page is empty and only show message "Successfully inserted". After some 10 minutes it working correct one time again.

Here is a link to the original code: http://technotip.com/2208/insert-data-into-mysql-jquery-ajax-php/

I have tried to close the page and reopen it, but still it not working until I have waited about 10 minutes. Then when I reload de pages it work one time again.

This is the input of the video_id_nr in the modal :

    <div class="form-group">
    <label>Video id number</label>
    <input type="text" class="form-control" name="video_id_nr" value='<? 
    php echo $videoId ?>'>
    </div> 

This is the database code: insert_timestamp.php where the program is trapped second try. It start working 10 minutes later.

   <?php require_once('connVideoAlbum.php');
   mysql_select_db($database_connKomponent, $connKomponent);    
   $startime = $_POST['event_start_time'];
   $stoptime = $_POST['event_stop_time']; 
   $info = $_POST['event_info'];
   $video_id_nr = $_POST['video_id_nr']; 
   $squery ="INSERT INTO video_time_table(event_start_time,
   event_stop_time,event_info,video_id_nr) 
   VALUES ('$startime','$stoptime','$info','$video_id_nr')";
   if(mysql_query($squery, $connKomponent)){
   echo "Succsessfully inserted";
   }else{ 
   echo "Insertion failed";
   }       
   mysql_close();
   ?>

This is the javascript:

    $("#sub").click( function() {
    $.post( $("#myForm").attr("action"),
    $("#myForm :input").serializeArray(),
    function(info){ $("#result").html(info);
    });
    clearInput();
    });

    $("#myForm").submit( function() {
    return false;    
    });
Machavity
  • 30,841
  • 27
  • 92
  • 100
  • The `INSERT` statement as written is subject to SQL injection and represents a security issue that should be addressed before doing anything else with the code. – Jason Aller Jun 04 '19 at 15:34
  • I cleaned this up some, but you really need to stop using `mysql_` functions, as [current versions of PHP have removed them](https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). So not only is your code outdated, so is your version of PHP. – Machavity Jun 05 '19 at 03:34
  • [Your script is also at risk for SQL Injection Attacks.](//stackoverflow.com/q/60174) – Machavity Jun 05 '19 at 03:35
  • Use prepared statements. I believe php comes with a mysqli library that can help you out. https://www.w3schools.com/php/php_mysql_prepared_statements.asp – Tim Hunt Jun 05 '19 at 03:40

0 Answers0