Goran Goran - 1 month ago 6
MySQL Question

Cron php update/insert one sql table from another and delete data from old table

Hi eny can help me to resolve this problem? I need every dey on 18:00h to copy all data from table "texirequest" to table "dispo" and delete all data on table "texirequest" after chek table "dispo" if "dauer_auftrag" is value 1 copy all data to "texirequest" using Cronjob

<?php
$dauerauftrag_array = array(1);
$con = mysql_connect("localhost","admin","password");
if(!$con) {
die('could not connect: '.mysql_error());
}
mysql_select_db('admin_transport', $con);

foreach($dauerauftrag_array AS $dauerauftrag) {
$result = mysql_query("SELECT * FROM dispo WHERE dauer_auftrag = '".$dauerauftrag."'");
while($row = mysql_fetch_array($result)) {
mysql_query("INSERT INTO texirequest (id, driver_id, driver_email, driver_name, sender_id, name, typ, sbehalt, Transportar, bfahrer, zinfo, ein_stieg, aus_stieg, dauer_auftrag, status, phoneM, phoneF, termin, termin_austirg, phone, droplocation, location, latitude, longitude, timedate, accept)
VALUES ('".$row['id']."', '".$row['driver_id']."', '".$row['driver_email']."', '".$row['driver_name']."', '".$row['sender_id']."', '".$row['name']."', '".$row['typ']."', '".$row['sbehalt']."', '".$row['Transportar']."', '".$row['bfahrer']."', '".$row['zinfo']."', '".$row['ein_stieg']."', '".$row['aus_stieg']."', '".$row['dauer_auftrag']."', '".$row['status']."', '".$row['phoneM']."', '".$row['phoneF']."', '".$row['termin']."', '".$row['termin_austirg']."', '".$row['phone']."', '".$row['droplocation']."', '".$row['location']."', '".$row['latitude']."', '".$row['longitude']."', '".$row['timedate']."', '".$row['accept']."') ON DUPLICATE KEY UPDATE id = '".$row['id']."', '".$row['driver_id']."', '".$row['driver_email']."', '".$row['driver_name']."', '".$row['sender_id']."', '".$row['name']."', '".$row['typ']."', '".$row['sbehalt']."', '".$row['Transportar']."', '".$row['bfahrer']."', '".$row['zinfo']."', '".$row['ein_stieg']."', '".$row['aus_stieg']."', '".$row['dauer_auftrag']."', '".$row['status']."', '".$row['phoneM']."', '".$row['phoneF']."', '".$row['termin']."', '".$row['termin_austirg']."', '".$row['phone']."', '".$row['droplocation']."', '".$row['location']."', '".$row['latitude']."', '".$row['longitude']."', '".$row['timedate']."', '".$row['accept']."'");
}
}
mysql_close($con);
?>



Error Notice: Use of undefined constant admin_transport - assumed
'admin_transport' in /var/www/vhosts/xyz.com/httpdocs/admin/test1.php
on line 7


my texirequest Table

CREATE TABLE `texirequest` (
`id` int(11) NOT NULL,
`driver_id` varchar(100) NOT NULL,
`driver_email` varchar(100) NOT NULL,
`driver_name` varchar(100) NOT NULL,
`sender_id` varchar(100) NOT NULL,
`name` varchar(100) NOT NULL,
`typ` varchar(100) NOT NULL,
`sbehalt` varchar(100) NOT NULL,
`Transportar` varchar(100) NOT NULL,
`bfahrer` varchar(100) NOT NULL,
`zinfo` varchar(100) NOT NULL,
`ein_stieg` varchar(100) NOT NULL,
`aus_stieg` varchar(100) NOT NULL,
`dauer_auftrag` varchar(100) NOT NULL,
`status` varchar(100) NOT NULL,
`phoneM` varchar(100) NOT NULL,
`phoneF` varchar(100) NOT NULL,
`termin` varchar(100) NOT NULL,
`termin_austirg` varchar(100) NOT NULL,
`phone` varchar(100) NOT NULL,
`droplocation` varchar(100) NOT NULL,
`location` text NOT NULL,
`latitude` varchar(100) NOT NULL,
`longitude` varchar(100) NOT NULL,
`timedate` text NOT NULL,
`accept` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


and this is my "dispo" table

CREATE TABLE `dispo` (
`id` int(11) NOT NULL,
`driver_id` varchar(100) NOT NULL,
`driver_email` varchar(100) NOT NULL,
`driver_name` varchar(100) NOT NULL,
`sender_id` varchar(100) NOT NULL,
`name` varchar(100) NOT NULL,
`typ` varchar(100) NOT NULL,
`sbehalt` varchar(100) NOT NULL,
`Transportar` varchar(100) NOT NULL,
`bfahrer` varchar(100) NOT NULL,
`zinfo` varchar(100) NOT NULL,
`ein_stieg` varchar(100) NOT NULL,
`aus_stieg` varchar(100) NOT NULL,
`dauer_auftrag` varchar(100) NOT NULL,
`status` varchar(100) NOT NULL,
`phoneM` varchar(100) NOT NULL,
`phoneF` varchar(100) NOT NULL,
`termin` varchar(100) NOT NULL,
`termin_austirg` varchar(100) NOT NULL,
`phone` varchar(100) NOT NULL,
`droplocation` varchar(100) NOT NULL,
`location` text NOT NULL,
`latitude` varchar(100) NOT NULL,
`longitude` varchar(100) NOT NULL,
`timedate` text NOT NULL,
`accept` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Answer

Is admin_transport is variable or DB name. If it's a db name use quotes around the name, if it's a variable $ is missing before variable name.