how to work with this code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
santunu
Forum Newbie
Posts: 1
Joined: Tue Aug 26, 2014 5:01 am

how to work with this code

Post by santunu »

Hi this is my code run a script concept is when user check in first time user data insert to a table called tbl1 and at the same time we add a mysql event so that after few times later data from tbl1 move from tbl2 and tbl1 row data will delete i am set a cookie for event so that it will run after check box sumit i get the event and i also get the cookie on client computer and at the first time when user click on checkbox data inserting is also ok but problem is no data remove from the data base i mean from tbl1 and nothing insert in tbl2 after 3 minutes as i set event to do my code is

This is my script when any registed user click on checkbox then he insert tbl1 table and we set a cookie and run events after 36 minute event will run and insert data in to another table called tbl2 my code is

Code: Select all

 <form action="course01.php" method="POST">
    <input type="checkbox" name="chk1" value="701" />I am agree with the course terms and condition<br/>

    <input type="submit" name="submit" value="enrolment"/>

    </form>
    </body>
    </html>

    <?php
    include("config.php");
    session_start();
    $user=$_SESSION['sess_user'];
    $checkbox1=$_POST['chk1'];
    if ($_POST["submit"]=="enrolment")
    {
    $result = mysql_query("SELECT id,name,url FROM tbl0 WHERE id = '".$checkbox1."'");
    if (!$result) {
        echo 'Could not run query: ' . mysql_error();
        exit;
    }
    $row = mysql_fetch_row($result);

    echo $row[0]; 
    echo $row[1]; // the email value
    echo $row[2];

    setcookie('joytestcookie','".$user."',time()+3600);
    setcookie('joytestcookie2','".$row[1]."',time()+3600);
    $query= "INSERT INTO tbl1 (course_id,course_name,course_url,username,entry_date) values ('".$row[0]."','".$row[1]."','".$row[2]."','".$user."',localtime())";

    mysql_query($query) or die (mysql_error());

    $insertquery="CREATE EVENT $_cookie['joytestcookie2']
        ON SCHEDULE  AT CURRENT_TIMESTAMP + INTERVAL 3 MINUTE
        DO
          BEGIN
           insert into tbl2 (username,course_name) select username,couse_name from course_entry where name='".$_COOKIE['joytestcookie']."';
            delete from tbl1 where name ='".$_COOKIE['joytestcookie']."';
                  END";

     mysql_query($insertquery) or die (mysql_error());
    echo "Record is inserted";
    header("Location: z.php");  

    }

    ?>
Last edited by Celauran on Tue Aug 26, 2014 6:21 am, edited 1 time in total.
Reason: Please wrap your code in syntax tags.
Post Reply