Forum Moderators: coopster

Message Too Old, No Replies

Duplicating an Entry

         

brodie_r

4:15 am on Jun 3, 2006 (gmt 0)

10+ Year Member



I have jobs that include names, phone numbers, locations and they are stored in a database.

Example:
1 ¦ John Wig ¦ 2993459345 ¦ Location Park
2 ¦ Anne Smith ¦ 54358348534 ¦ Location Bush

I want to be able to duplicate say Job id 1 (john wig) and have it auto assign the next available job id (3).

My current ADD_JOB Page is:


<?php
if (isset($_POST['submit'])) { // Handle the form.

require_once ('mysql_connect.php'); // Connect to the db.

// Create a function for escaping the data.
function escape_data ($data) {
global $dbc; // Need the connection.
// End of function.
}
$message = NULL; // Create an empty new variable.

// Check for a first name.

$da = $_POST['date'];
$ti = $_POST['time'];
$lo = $_POST['location'];
$ma = $_POST['machine'];
$op = $_POST['operator'];
$do = $_POST['docket_no'];
$ra = $_POST['rate'];
$co = $_POST['comment'];

$on = $_POST['order_no'];
$cn = $_POST['contact_no'];
$by = $_POST['booked_by'];
$st = $_POST["status"];

$cl = $_POST['client_text'];
if(!$cl)
$cl = $_POST['client'];

if ($cl) { // If everything's OK.
// Make the query.
$query = "INSERT INTO jobs (client, date, time, location, machine, operator, order_no, contact_no, booked_by, status, docket_no, rate, comment) VALUES ('$cl', '$da', '$ti', '$lo', '$ma', '$op', '$on', '$cn', '$by', '$st', '$do', '$ra', '$co')";
$result = @mysql_query ($query); // Run the query.
if ($result) { // If it ran OK.

echo '<meta http-equiv="refresh" content="1.5;url=view_jobs_today.php">';
echo '<font face="Arial" size="2">Please Wait... Job being added<br>';
exit(); // Quit the script.

} else { // If it did not run OK.
$message = '<p><font face="Arial" size="2"><strong>ERROR:</strong> Job could not be added to the database</font></p><p>' . mysql_error() . '</p>';
}

mysql_close(); // Close the database connection.

} else {
$message .= '<p><font face="Arial" size="2">Error</font></p>';
}

} // End of the main Submit conditional.

// Print the error message if there is one.
if (isset($message)) {
echo '<font color="red">', $message, '</font>';
}
?><head>
<SCRIPT LANGUAGE="JavaScript" SRC="CalendarPopup.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
var cal = new CalendarPopup();
</SCRIPT>
</head>

<style type="text/css">
A {text-decoration: none; color: #999999; font-family: Arial, Helvetica, sans-serif;}
A:hover {text-decoration: none; color: #FF9900;}
INPUT {
BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; PADDING-LEFT: 3px; FONT-SIZE: 10pt; BORDER-LEFT: black 1px solid; COLOR: black; BORDER-BOTTOM: black 1px solid; FONT-FAMILY: arial, verdana, ms sans serif; BACKGROUND-COLOR: #ffffff
}
TEXTAREA {
BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; PADDING-LEFT: 3px; FONT-WEIGHT: normal; FONT-SIZE: 10pt; BORDER-LEFT: black 1px solid; COLOR: black; BORDER-BOTTOM: black 1px solid; FONT-FAMILY: arial, verdana, ms sans serif; BACKGROUND-COLOR: #ffffff
}
SELECT {
BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; PADDING-LEFT: 3px; FONT-SIZE: 10pt; BORDER-LEFT: black 1px solid; COLOR: black; BORDER-BOTTOM: black 1px solid; FONT-FAMILY: arial, verdana, ms sans serif; BACKGROUND-COLOR: #ffffff
}
.style7 {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 12px;
}
.style11 {font-size: 14}
.style12 {color: #FF0000}
</style>
<form name="add_job" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" class="style1">
<fieldset>
<center><strong><span class="style12"><font face="Arial">Add Job </font></span></span></span></center>
<table width="492" border="0" cellspacing="3" cellpadding="2" align="center">
<tr><font face="Arial" size="2"> </font>
<td align="left" valign="middle"><div align="left" class="style7 style11">Client:</div></td>
<font face="Arial" size="2">
<td><label><font face="Arial" size="2">
<?php
require_once ('mysql_connect.php');
$sql = mysql_query("SELECT * FROM client ORDER BY `list`");
echo '<select name="client">';
while ($row = mysql_fetch_array($sql)) {
$sub = $row["list"];
$sub_id = $row["list"];
echo '<option value="' . htmlentities($sub_id) . '"';
echo '>' . htmlentities($sub) . '</option>';
}echo "</select>";
echo " or <b>Other:</b> ";
echo "<input type='text' name='client_text'>";
?>
</font></label></td>
</font></tr>
<tr><font face="Arial" size="2">
</font><td width="109" align="left" valign="middle"><div align="left" class="style7 style11">Phone:</div></td>
<font face="Arial" size="2">
<td width="366"><label><font face="Arial" size="2">
<input name="contact_no" type="text" id="contact_no" value="<?php if (isset($_POST['contact_no'])) echo $_POST['contact_no'];?>" size="15" maxlength="75" />
</font></label></td>
</font></tr>
<tr>
<td align="left" valign="middle"><div align="left" class="style7 style11">Date:</div></td>
<td><font face="Arial" size="2">
<input type="text" name="date" size="12" maxlength="25" value="" />
<A HREF="#" onClick="cal.select(document.forms['add_job'].date,'anchor1','yyyy-MM-dd'); return false;"
NAME="anchor1" ID="anchor1"><img src="cal_icon.gif" width="24" height="14" border="0" /></A>
</font></td>
</tr>
<tr>
<td align="left" valign="middle"><div align="left" class="style7 style11">Time:</div></td>
<td><font face="Arial" size="2">
<input type="text" name="time" size="12" maxlength="25" value="<?php if (isset($_POST['time'])) echo $_POST['time'];?>" />
</font></td>
</tr>
<tr>
<td align="left" valign="middle"><div align="left" class="style7 style11">Location:</div></td>
<td><font face="Arial" size="2">
<input type="text" name="location" size="25" maxlength="100" value="<?php if (isset($_POST['location'])) echo $_POST['location'];?>" />
</font></td>
</tr>
<tr>
<td align="left" valign="middle"><div align="left" class="style7 style11">Machine:</div></td>
<td><font face="Arial" size="2">
<?php
require_once ('mysql_connect.php');
$sql = mysql_query("SELECT * FROM machine ORDER BY `list`");
echo '<select name="machine">';
while ($row = mysql_fetch_array($sql)) {
$sub = $row["list"];
$sub_id = $row["list"];
echo '<option value="' . htmlentities($sub_id) . '"';
echo '>' . htmlentities($sub) . '</option>';
}echo "</select>";
?>
</font></td>
</tr>
<tr>
<td width="109" align="left" valign="middle"><div align="left" class="style7 style11">Operator:</div></td>
<td><font face="Arial" size="2">
<?php
require_once ('mysql_connect.php');
$sql = mysql_query("SELECT * FROM operator ORDER BY `list`");
echo '<select name="operator">';
while ($row = mysql_fetch_array($sql)) {
$sub = $row["list"];
$sub_id = $row["list"];
echo '<option value="' . htmlentities($sub_id) . '"';
echo '>' . htmlentities($sub) . '</option>';
}echo "</select>";
?>
</font></td>
</tr>
<tr>
<td align="left" valign="middle"><div align="left" class="style7 style11">Order No:</div></td>
<td><font face="Arial" size="2">
<input name="order_no" type="text" id="order_no" value="<?php if (isset($_POST['order_no'])) echo $_POST['order_no'];?>" size="12" maxlength="25" />
</font></td>
</tr>
<tr>
<td align="left" valign="middle"><div align="left" class="style7 style11">Invoice No:</div></td>
<td><font face="Arial" size="2">
<input type="text" name="docket_no" size="12" maxlength="25" value="<?php if (isset($_POST['docket_no'])) echo $_POST['docket_no'];?>" />
</font></td>
</tr>
<tr>
<td align="left" valign="middle"><div align="left" class="style7 style11">Rate:</div></td>
<td><font face="Arial" size="2">
<input type="text" name="rate" size="5" maxlength="5" value="<?php if (isset($_POST['rate'])) echo $_POST['rate'];?>" />
</font></td>
</tr>
<tr>
<td align="left" valign="middle"><div align="left" class="style7 style11">Comment:</div></td>
<td><textarea name="comment" cols="40"><?php if (isset($_POST['comment'])) echo $_POST['comment'];?></textarea></td>
</tr>
<tr>
<td align="left" valign="middle"><div align="left" class="style7 style11">Booked By: </div></td>
<td><font face="Arial" size="2">
<input name="booked_by" type="text" id="booked_by" value="<?php if (isset($_POST['booked_by'])) echo $_POST['booked_by'];?>" size="12" maxlength="20" />
</font></td>
</tr>
<tr>
<td align="left" valign="middle"><div align="left" class="style7 style11">Status:</div></td>
<td><font face="Arial" size="2">
<?php
require_once ('mysql_connect.php');
$sql = mysql_query("SELECT * FROM status");
echo '<select name="status">';
while ($row = mysql_fetch_array($sql)) {
$sub = $row["list"];
$sub_id = $row["list"];
echo '<option value="' . htmlentities($sub_id) . '"';
echo '>' . htmlentities($sub) . '</option>';
}echo "</select>";
?>
</font></td>
</tr>
<tr>
<td align="left" valign="top">&nbsp;</td>
<td><input type="submit" name="submit" value="Add Job" /></td>
</tr>
</table>
</form>

brodie_r

6:59 am on Jun 3, 2006 (gmt 0)

10+ Year Member



I have been mucking around with:

insert into `jobs` select * from `jobs` EXCEPT col1 where job_id=50

col1 = job_id column... the job id, of 50 exists, and im just testing to see if i can copy the contents of that row across.

brodie_r

7:33 am on Jun 3, 2006 (gmt 0)

10+ Year Member



Figured out how to do it:

Query Line:

INSERT INTO jobs (client, date, time, location, machine, operator, order_no, contact_no, booked_by, status, docket_no, rate, comment)
SELECT client, date, time, location, machine, operator, order_no, contact_no, booked_by, status, docket_no, rate, comment
FROM jobs
WHERE job_id = 50

dreamcatcher

8:53 am on Jun 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



brodie_r, glad you got it sorted out. :)

dc