Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script Execution question

Status
Not open for further replies.

Netwrkengeer

IS-IT--Management
Apr 4, 2001
184
US
I'am trying to write a php script to access a mysql database. I have a small script that connects to the database that lets me add and delete stuff manualy. But I want the script to automatically execute at 1:00AM, then grab info from "Table A" in the database and dump it into "Table B" in the same database. Do you know of a script or method of doing this.

thanks
Robert.

And here is the script I wrote.

<html>

<body>



<?php



$db = mysql_connect(&quot;localhost&quot;, &quot;root&quot;);

mysql_select_db(&quot;JBHdb&quot;,$db);



if ($submit) {

// here if no ID then adding else we're editing

if ($id) {

$sql = &quot;UPDATE users SET first='$first',last='$last',address='$address',position='$position' WHERE id=$id&quot;;

} else {

$sql = &quot;INSERT INTO users (first,last,address,position) VALUES ('$first','$last','$address','$position')&quot;;

}

// run SQL against the DB

$result = mysql_query($sql);

echo &quot;Record updated/edited!<p>&quot;;

} elseif ($delete) {

// delete a record

$sql = &quot;DELETE FROM users WHERE id=$id&quot;;

$result = mysql_query($sql);

echo &quot;$sql Record deleted!<p>&quot;;

} else {

// this part happens if we don't press submit

if (!$id) {

// print the list if there is not editing

$result = mysql_query(&quot;SELECT * FROM users&quot;,$db);

while ($myrow = mysql_fetch_array($result)) {

printf(&quot;<a href=\&quot;%s?id=%s\&quot;>%s %s</a> \n&quot;, $PHP_SELF, $myrow[&quot;id&quot;], $myrow[&quot;first&quot;], $myrow[&quot;last&quot;]);

printf(&quot;<a href=\&quot;%s?id=%s&delete=yes\&quot;>(DELETE)</a><br>&quot;, $PHP_SELF, $myrow[&quot;id&quot;]);

}

}



?>

<P>

<a href=&quot;<?php echo $PHP_SELF?>&quot;>ADD A RECORD</a>

<P>

<form method=&quot;post&quot; action=&quot;<?php echo $PHP_SELF?>&quot;>

<?php



if ($id) {

// editing so select a record

$sql = &quot;SELECT * FROM users WHERE id=$id&quot;;

$result = mysql_query($sql);

$myrow = mysql_fetch_array($result);

$id = $myrow[&quot;id&quot;];

$first = $myrow[&quot;first&quot;];

$last = $myrow[&quot;last&quot;];

$address = $myrow[&quot;address&quot;];

$position = $myrow[&quot;position&quot;];

// print the id for editing



?>

<input type=hidden name=&quot;id&quot; value=&quot;<?php echo $id ?>&quot;>

<?php

}



?>

First name:<input type=&quot;Text&quot; name=&quot;first&quot; value=&quot;<?php echo $first ?>&quot;><br>

Last name:<input type=&quot;Text&quot; name=&quot;last&quot; value=&quot;<?php echo $last ?>&quot;><br>

Address:<input type=&quot;Text&quot; name=&quot;address&quot; value=&quot;<?php echo $address ?>&quot;><br>

Position:<input type=&quot;Text&quot; name=&quot;position&quot; value=&quot;<?php echo $position ?>&quot;><br>

<input type=&quot;Submit&quot; name=&quot;submit&quot; value=&quot;Enter information&quot;>

</form>



<?php



}



?>



</body>

</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top