-1

I have a problem please I need help, is there a way that if I click the lock button the student who doesn't exist on the table vote_logs will automatic put into the other table which is unvoted_logs(table),. For example in the student table there is an idno c120-115 and also it was saved in the table vote_logs my problem is if the vote is time's up then click the button of lock.php, I want that it will automatic put the student records who did not exist in table vote_logs to unvoted_logs. Need some help guys

Sample of data structure

Here is my lock.php:

<?php
include '../connection/connect.php';
include '../dbcon.php';


$stat='lock';
$sqla = "UPDATE student SET status=?";

$qa = $db->prepare($sqla);
$qa->execute(array($stat));     

//here is the part where I want to store the student who didn't exist in vote_logs
$stud = mysql_query(" SELECT st.* FROM student st LEFT  JOIN studentvotes sv ON st.idno = sv.idno AND st.syearid = sv.syearid
WHERE sv.idno IS NULL AND st.syearid = '$no' AND user_type='3'") or die(mysql_error());

//should I put insert? don't what's next

Header ('Location:lock_unlock.php');
?>
Phiter
  • 14,570
  • 14
  • 50
  • 84
miming
  • 103
  • 8
  • 1
    Please show us what you've tried, and could you please try to format your question a bit better? It's really hard to understand what you want ;) – Keith M Jan 21 '16 at 01:18
  • 1
    What would you prefer pure PHP or using a SQL stored procedure? – FrozenFire Jan 21 '16 at 01:20
  • if you want to autosave if an action is performed on one table in order to perform an action on another, then consider using a trigger. Seems to be the case here. – Funk Forty Niner Jan 21 '16 at 01:26
  • I wnt to choose the php – miming Jan 21 '16 at 01:26
  • Plus, looking at your code, you seem to be mixing MySQL APIs. `mysql_` does not support prepared statements. Making your question that much more unclear. – Funk Forty Niner Jan 21 '16 at 01:31
  • What can you suggest sir ,? is there a way to automatically store in the database? – miming Jan 21 '16 at 01:35
  • 1
    Trigger => http://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html - And if you want to use PHP, you'll need to use a cron job and seperate files for your SQL. – Funk Forty Niner Jan 21 '16 at 01:37

2 Answers2

0

I believe that the use of triggers is the best solution to your problem. Please read this post.

Using MySQL triggers to log all table changes to a secondary table

I'm just putting the link because there are many examples of how to make the Internet the registration logs with triggers.

Community
  • 1
  • 1
calraiden
  • 1,686
  • 1
  • 27
  • 37
0

Here is another suggestion and this may be the answer. Use

mysqldump -u... -p... mydb t1 t2 t3 > mydb_tables.sql

either write that in php or in bash and drop it in crontab folder so it'll automatically backup the table. You can also use crontab -e to set the backup interval.

unixmiah
  • 3,081
  • 1
  • 12
  • 26