PHP - Stop Records Duplicating
Hi,
Was just wondering if I could get help with this programming problem, I am programming a diary system that people can use to book appointments within time slots on a current day. I have the below code reading from three database tables (one for appointment details, one for the profile of whom booked the appointment and lastly a LEFT JOIN table of times from 09:00:00 to 17:30:00). The functionality of this diary of time slots is where there is a booked slot, slip the appointment attendee into that slot so the avaible link is not seen so no one can book over the appointment. This is where the problem comes into play, if there is an appointment expanding lets say 45 minutes which means other time slots will be taken, it just echos out the same appointment details so then I am getting it duplicating. for example down below; 09:00:00 - Booked Appointment (name) - Duration: 30 Minutes 09:15:00 - Booked Appointment (name) - Duration: 30 Minutes 09:30:00 - Booked Appointment (name) - Duration: 30 Minutes Now what I would like the solution to is if there is a way to maybe stop the duplication by showing the first row of the start time of the appointment and then change the the next rows to unavailable? Or even collapsing the time rows so if an appointment is booked at 09:00:00 for 30 mnutes, then the next available time slot would be 09:45:00 so the record would not duplicate. Here is a screenshot to help you a bit better - http://img185.imageshack.us/img185/7981/72314500.png Here is my source code, would appreciate any suggestions on how I would do this! <?php include('connection.php'); //Query $comment = "SELECT * FROM timeslots LEFT OUTER JOIN (SELECT time,endtime,status,firstname,secondname,duration FROM appointments INNER JOIN profile ON profile.id=appointments.id WHERE appointments.DATE = '" .$_GET['date']."') AS a ON a.time <= timeslots.timeslot AND a.endtime >= timeslots.timeslot"; $commentresult = mysql_query($comment); // If commentresult = false then query return fail if ($commentresult == false) { die("Your Query isn't working correctly! :-( "); } // If commentresult = true then echo below information with results if (mysql_num_rows($commentresult) >= 1) { // Start Rows while($cr = mysql_fetch_array($commentresult)) { // Start While Loop { // Process While Loop $_GET['time'] = $cr['timeslot']; $status = $cr['status']; if($status=="") { // Start IF Status // echo Available echo "<table border='0' width='800'> <tr><td width='35'><div class='content'>".$cr['timeslot']."</div></td> <td width='100'><div class='content'><a href='book_slot.php?date=".$_GET['date']."&id=".$_GET['id']."&time=".$_GET['time']."'>Available</a></div></td> <td width='100'><div class='content'></div></td> <td width='120'><div class='content'></div></td> </tr></table>"; } // End IF Status else { // Start ELSE status // echo Appointment within Time Slot echo "<table border='0' width='800'> <tr><td width='35'><div class='content'>".$cr['timeslot']."</div></td> <td width='100'><div class='content'>".$cr['status']."</div></td> <td width='120'><div class='content'>".$cr['firstname']." ".$cr['secondname']."</div></td> <td width='120'><div class='content'>".$cr['duration']." Minutes</div></td> </tr></table>"; } // End ELSE Status } // End Process While Loop } // End Loop } // End Row // Else statement else { echo "<img src='info.png'> There are no appointments for this day!"; } // Close database connection mysql_close($dbconnection); ///////////////////////////// ?> Similar Tutorials
I have a hopefully small issue on a form submitting data to the mysql database table and email. The email side works fine as does the adding the data to the database table but if I upload two files, it stores the support ticket twice in the database table where as I want to store just once and the files be stored as a array in the database table. I got the code from the link https://www.codexworld.com/upload-multiple-images-store-in-database-php-mysql/
<?php require_once "registerconfig.php"; if (isset($_POST['submit'])) { // File upload configuration $targetDir = "support-ticket-images/"; $allowTypes = array('pdf','doc','docx','jpg','png','jpeg','gif'); $statusMsg = $errorMsg = $insertValuesSQL = $errorUpload = $errorUploadType = ''; // Escape user inputs for security $ticket_subject = htmlentities($_POST['ticket_subject'], ENT_QUOTES); $ticket_message = strip_tags($_POST['ticket_message'], ENT_QUOTES); $ticket_status ='PENDING SUPPORT'; $username = htmlentities($_SESSION["user_name"], ENT_QUOTES); $user_id = htmlentities($_SESSION["user_id"], ENT_QUOTES); $fileNames = array_filter($_FILES['files']['name']); if(!empty($fileNames)){ foreach($_FILES['files']['name'] as $key=>$val){ // File upload path $fileName = basename($_FILES['files']['name'][$key]); $targetFilePath = $targetDir . $fileName; // Check whether file type is valid $fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION); if(in_array($fileType, $allowTypes)){ // Upload file to server if(move_uploaded_file($_FILES["files"]["tmp_name"][$key], $targetFilePath)){ // Image db insert sql $insertValuesSQL .= "('".$ticket_subject."','".$ticket_message."','".$fileName."','".$ticket_status."','".$username."', '".$user_id."'),"; }else{ $errorUpload .= $_FILES['files']['name'][$key].' | '; } }else{ $errorUploadType .= $_FILES['files']['name'][$key].' | '; } } if(!empty($insertValuesSQL)){ $insertValuesSQL = trim($insertValuesSQL, ','); // Insert image file name into database $insert = $link->query("INSERT INTO DB TABLE NAME (ticket_subject, ticket_message, file_name, ticket_status, user_name, user_id) VALUES $insertValuesSQL"); if($insert){ $to = "emailaddress"; $subject = "A new support ticket has been submitted"; $message = " <strong>$username</strong> has just created a support ticket, below is the support ticket <br /><br /> <u>Support Ticket Details</u> <br /><br> <strong>Support Ticket Subject</strong>: $ticket_subject <br/><br><strong>Support Ticket Message</strong>: $ticket_message <p><strong><u>Support Ticket Files</u></strong> <br> <img src='$fileName'> "; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // More headers $headers .= 'From: <noreply@emailaddress>' . "\r\n"; $mail=mail($to,$subject,$message,$headers); $errorUpload = !empty($errorUpload)?'Upload Error: '.trim($errorUpload, ' | '):''; $errorUploadType = !empty($errorUploadType)?'File Type Error: '.trim($errorUploadType, ' | '):''; $errorMsg = !empty($errorUpload)?'<br/>'.$errorUpload.'<br/>'.$errorUploadType:'<br/>'.$errorUploadType; header("location: support-ticket-confirmation?user=$username"); }else{ $statusMsg = "Sorry, there was an error uploading your file."; } } }else{ $statusMsg = 'Please select files to upload.'; } // Display status message echo $statusMsg; } ?> The structure of the db table column is file_name, VARCHAR(255), latin1_swedish_ci, NOT NULL I need to stop things from duplicating the insert of products into a table on refresh. Im stumped! This is the insert page that forwards to the display page. Code: [Select] <?php session_start(); $UserID = session_id(); $SKU = $_POST['SKU']; $QTY = $_POST['QTY']; include("database.php"); mysql_select_db("brandysbeanies", $con); $result = mysql_query("SELECT * FROM Products WHERE SKU='$SKU'"); while($row = mysql_fetch_array($result)) { $Name = $row[1]; $Image1 = $row[4]; $Image2 = $row[17]; $Image3 = $row[18]; $Image4 = $row[19]; $Description = $row[3]; $Cost = $row[5]; $Price = $row[6]; $Ship = $row[9]; $Option1 = $row[10]; $Option2 = $row[11]; $Option3 = $row[12]; $Option4 = $row[13]; $Option5 = $row[14]; } $time_1 = strtotime("now"); $today_date = date("ymd",$time_1); $today_time = date("his",$time_1); $Total = $Price * $QTY; $Shipping = $Ship * $QTY; $ID = "$today_date$today_time"; include("database.php"); mysql_select_db("brandysbeanies", $con); $sql="INSERT INTO productorders (ClientID,OrderID,Productname,Productdescription,Cost,Price,Quantity,Shipping,Total,Photo) VALUES ('$UserID','$ID','$Name','$Description','$Cost','$Price','$QTY','$Shipping','$Total','$Image1')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } include("cart.php"); ?> This is the display page. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title></title> <meta http-equiv="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)" /> <meta name="created" content="Mon, 06 Sep 2010 07:35:27 GMT" /> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta name="description" content="" /> <meta name="keywords" content="" /> <meta http-equiv="Page-Enter" content="revealtrans(duration=2,transition=22)"> <style type="text/css"> a:link {text-decoration: none;} a:visited {text-decoration: none;} </style> <style type="text/css"> BODY { SCROLLBAR-FACE-COLOR: #0E98E0; SCROLLBAR-HIGHLIGHT-COLOR: #000000; SCROLLBAR-SHADOW-COLOR: #000000; SCROLLBAR-3DLIGHT-COLOR: #000000; SCROLLBAR-ARROW-COLOR: #000000; SCROLLBAR-TRACK-COLOR: #000000; SCROLLBAR-DARKSHADOW-COLOR: #000000; background-image:url('Images/background.gif'); } </style> <style type="text/css"> div.Object1 { position:absolute; top:0%; left:0%; z-index:2; width:100%; height:20%;} div.Object2 { position:absolute; top:20%; left:0%; z-index:2; width:100%; height:80%;} </style> </head> <body> <div class="Object1"> <table border="0" width="100%" cellpadding="5" cellspacing="5"><tr><td> <font size="7" face="AR CHRISTY"><b><u>YOUR SHOPPING CART</u></b></font> </td></tr></table> </div> <div class="Object2"> <table border='1' width='100%'> <tr><!-- Row 1 --> <td colspan="2" width='70%' align='left' valign='top'><font size="4" face="AR CHRISTY"><b>PRODUCT</b></font></td><!-- Col 2 --> <td width='15%' align='center' valign='top'><font size="4" face="AR CHRISTY"><b>QUANTITY</b></font></td><!-- Col 3 --> <td width='15%' align='center' valign='top'><font size="4" face="AR CHRISTY"><b>PRICE</b></font></td><!-- Col 4 --> </tr> <?PHP $UserID = session_id(); include("database.php"); mysql_select_db("brandysbeanies", $con); $result = mysql_query("SELECT * FROM productorders WHERE ClientID='$UserID'"); while($row = mysql_fetch_array($result)) { echo" <tr><!-- Row 2 --> <td width='20%' align='center' valign='top'><a href='Products3.php?SKU=$row[0]' style='color:#000000;'><img src='$row[10]' width=60% height=60% alt='' border='1'></a></td><!-- Col 2 --> <td width='50%' align='left' valign='top'><font size='3' face='Comic Sans MS'><b>$row[3]</b><br>$row[4]</font></td><!-- Col 2 --> <td width='15%' align='center' valign='top'><font size='3' face='Comic Sans MS'>$row[7]</font></td><!-- Col 3 --> <td width='15%' align='center' valign='top'><font size='3' face='Comic Sans MS'>$row[9]</font></td><!-- Col 4 --> </tr>"; } echo" <tr><!-- Row 2 --> <td width='85%' colspan=3 align='right' valign='top'><font size='4' face='AR CHRISTY'><b>SHIPPING</b></font></td><!-- Col 3 --> <td width='15%' valign='top'></td><!-- Col 4 --> </tr>"; echo" <tr><!-- Row 2 --> <td width='85%' colspan=3 align='right' valign='top'><font size='4' face='AR CHRISTY'><b>TOTAL</b></font></td><!-- Col 3 --> <td width='15%' valign='top'></td><!-- Col 4 --> </tr>"; ?> </table> </div> </body> </html> I am having trouble showing reports for a given date range. Currently if I specify something like 11/03/2010 to 11/05/2010 I get results for all years within that month and day such as I may get results for 11/03/2008 11/03/2009 11/03/2010 11/04/2008 11/04/2009 11/04/2010 11/05/2008 11/05/2009 11/05/2010. I am using the following code $result = mysql_query("SELECT * FROM report WHERE date>='$date_begin' and date<='$date_end' ORDER BY 'date'",$db); I use the following format in my date feild mm/dd/yyyy My script is finally working as intended, but I want to add some additional data results. I am trying to resolve how I can display a count of ONLY the records updated by my query: // START :: Query to replace matches mysql_query("UPDATE orig_codes_1a AS a JOIN old_and_new_codes_1a AS b ON concat(a.orig_code_1, a.orig_code_2) = concat(b.old_code_1, b.old_code_2) SET a.orig_code_1 = b.new_code_1, a.orig_code_2 = b.new_code_2") or die(mysql_error()); // END :: Query to replace matches In this query I count ALL records selection: // START :: Create query to be displayed as final results of original codes table. $result = mysql_query("SELECT * FROM orig_codes_1a") or die(mysql_error()); I want to display a count on this part of the query: ....concat(a.orig_code_1, a.orig_code_2) = concat(b.old_code_1, b.old_code_2).... Hi ,im face little problem in duplicating rows. it's not easy task wht i need: i got this rows right now id----------position-------------A_Q_ID 1---------------1--------------------5----- 2---------------2--------------------5----- 3---------------3--------------------5----- 4---------------1--------------------6----- 5---------------2--------------------6----- 6---------------3--------------------6----- what i need is to duplicat all the rows and have them inserted after the rows i allready have like that: id------------position-------------A_Q_ID 7-----------------1--------------------7----- 8-----------------2--------------------7----- 9-----------------3--------------------7----- 10---------------1--------------------8----- 11---------------2--------------------8----- 12---------------3--------------------8----- i tryed few ways without success . any idea how to do that please? i cannot get the logic on doing it thanks Eventually I will have around 5 or 6 queries that will be replicated in several different pages, albeit with a slight difference in each (generally just a change in the WHERE part). I have been thinking about placing these common queries in a separate file and calling that file with an 'include' on the pages the query is needed. My two questions are.... Would this be more beneficial than place the query in the page itself and would there be any downside (as in loading times) if I placed all of these queries in one external file (ie. would this cause all the queries to load each time. Thanks in advance for any advice. Steve Hi All, I have an insert/update that i am using in several places across my site, it works fine everywhere apart from on one page. I am clearly missing something but cant for the life of me work it out. My php: if ($_SERVER['REQUEST_METHOD']=='POST') { $jobId = $_SESSION['current_job_id']; $qty = $_POST['drinkItemQty']; // prepare insert query $stmt = $conn->prepare("INSERT INTO ssm_drink_order (drink_qty, job_id, drink_id) VALUES (?,?,?) ON DUPLICATE KEY UPDATE drink_qty = VALUES(drink_qty)" ); foreach ($_POST['drinkItemId'] as $k => $diid) { if ($qty[$k] > 0) { $stmt->bind_param("iii", $qty[$k], $jobId, $diid); $stmt->execute(); } if ($qty[$k] < 1) { $stmt1 =$conn->prepare("DELETE FROM ssm_drink_order WHERE job_id = ?"); $stmt1->bind_param('i', $jobId); $stmt1->execute(); } } } the page html <tbody> <tr> <th style="width:70%;" class="text-center">Drink Item</th> <th class="text-center">Quantity</th> </tr> <tr> <td> House Gin <input name="drinkItemId[]" type="hidden" value="2"> </td> <td class="text-center"> <input name="drinkItemQty[]" type="number" value="999" class="text-center"> </td> </tr> <tr> <td> House Brandy <input name="drinkItemId[]" type="hidden" value="4"> </td> <td class="text-center"> <input name="drinkItemQty[]" type="number" value="" class="text-center"> </td> </tr> <tr> <td> House Vodka <input name="drinkItemId[]" type="hidden" value="1"> </td> <td class="text-center"> <input name="drinkItemQty[]" type="number" value="" class="text-center"> </td> </tr> <tr> <td> House Whiskey <input name="drinkItemId[]" type="hidden" value="3"> </td> <td class="text-center"> <input name="drinkItemQty[]" type="number" value="" class="text-center"> </td> </tr> </tbody> Any help is as ever greatly appreciated I am have a query with a limit of 3 i want it to echo the first two in one li class and the 3 in another li class. This is what i have, but i know the logic is not right, but i cant figure it out Code: [Select] </div> <?php echo "<ul class='services-list'>"; //echo "<li class='bubble'>"; $i = 1; foreach ($rows_class as $record_class ){ ?> <li class="bubble"><a href="viewclass.php?class_id=<?php echo base64_encode($record_class[class_id]) ?>" /><h6 class="title"><img src="./images/services/picture-services.png" class="picture" alt="logo" /><? echo $record_class[class_title]; ?></h6></a><p><?php $string = $record_class['description']; echo substr(strip_tags($string), 0, 200); ?></p> <?php if( $i % 2 === 0 && $record_class !== end($rows_class) ) { echo "</li>\n<li class='bubble last'>\n";?> <?php } elseif ( $record_class === end($rows_class) ) { echo "</li>\n "; } $i++; } ?> </ul> Hello there, I have made a ban form on my website. It is all going good until I open phpmyadmin. There is two records from one submission. Usually the second record has some missing information. There should not be a duplicate and I do not understand why it is happening. If anybody could explain what is causing this would be great. Here is the page. <?php session_start(); require_once 'database.php'; if(isset($_SESSION['mod'])) { $userid = $_SESSION['user']; if(isset($_GET['action']) && strcasecmp($_GET['action'], "file") == 0) // checks to see if form is submitted { $username = $_POST['user']; $time = $_POST['time']; $reason = $_POST['reason']; $u_time = date("U"); $r_time = date("m-j-Y g:i A"); if($time == "00") { // if the time is a permaban $sql=mysql_query("SELECT * FROM user WHERE username='$username'") or die("Error 1"); $data=mysql_query($sql); $user_ip = $data['last_ip']; if ($user_ip != 127.0.01) { // admin stuff ;) $p_ban=mysql_query("INSERT INTO ip_ban (ip,real_time,unix_time,days_left,reason) VALUES ('$user_ip','$r_time','$u_time','99999999999','$reason')") or die("Error 2"); echo 'The user '.$username.' has been banned.'; }else{ // if it is an admin echo 'You cannot ban that user.'; } }else{ // not a perma ban if($username != "admin") // admin stuff { $temp_ban=mysql_query("INSERT INTO blacklist (email,reason,end_date,appeal,unixtime) VALUES ('$username','$reason','$time','No','$u_time')") or die("Error 3"); echo 'The user '.$username.' has been banned.'; }else{ echo 'You cannot ban that user.'; } } }else{ $user_ban = $_GET['user']; if(isset($user_ban)) { ?> <form name="file_ban" method="post" action="?action=file"> Username: <input type="text" name="user" value="<?php echo $user_ban; ?>"><br /> Length of Ban: <select name="time"> <option value="1">1 Day</option> <option value="3">3 Days</option> <option value="5">5 Day</option> <option value="7">1 Week</option> <option value="15">15 Days</option> <option value="30">1 Month</option> <option value="90">3 Months</option> <option value="99999999999">∞ Infinity (Permaban)</option> <option value="00">IP Ban (Does not expire)</option> </select><br /> Reason: <br /> <textarea name="reason" cols="50" row="4"></textarea><br /> <input type="submit" value="Ban"> <?php }else{ } } }else{ // If session is not set header("Location: index.php"); } ?> If you need any explanation of what anything does, just please ask. Thank you! Is there a php method/function that can count how many records in a table have the same id. For example you have two tables relating to one another there for there is reason for a coloum to have the same id as another. I've got query. Howdy, The following code wil geenrate a dynamic pull-down list based on column values. Can someone help me tweak it so that is will NOT display a duplicate record value. That is, if the sponsors values in the table were Hart, Michaels, Michaels, Morella ...it would only display Hart, Michaels, Morella in the pull-down menu. <form name="form0"> <? $result = @mysql_query("select distinct sponsor from table ORDER BY sponsor ASC"); if (mysql_num_rows($result) > 0) { print "<select name=\"link\">"; ?> <option <?php if(empty($_GET['sponsor'])){ echo "selected=\"selected\""; } ?> value="<? echo "$page_name" ?>">SELECT A SPONSOR</option> <? while ($row = mysql_fetch_array($result)) { print "<option "; if($_GET['sponsor'] == $row['sponsor'] ){ echo "selected=\"selected\""; } print " value=\"index?sponsor=" . $row['sponsor'] . "\">" . $row['sponsor'] . "</option>\n"; } print "</select>"; } ?> </form> Thank you. ~Wayne Hey again guys, i am building a site admin page and i want to do a php script with will show the heading and the date of my news database into a table, and on the right or left side of each row i want to put 2 small icons one which will remove the specific record and one which will open a new small window with the whole record viewing. any idears? again my tables are movies| ID(PK) - Titles - Category(FK) - URL 0 Name 1 www.xyz.com categories| ID(PK) - Category 1 Comedy say i create a query SELECT * FROM movies WHERE Category="1" and it gave me all the movies from my table that is in the comedy category which should look like this: ID - Title - Category - URL 0 Name Comedy www.xyz 1 xyz Comedy www.abc etc.. How can i add a drop down menu beside each movie listed in that result that would let me change the category for it and save it ? like this, ID - Title - Category - URL 0 Name Comedy www.xyz [Dropdown] 1 xyz Comedy www.abc [Dropdown] [Save Button] being a newbie im going to guess that i will need a INSERT in here somewhere and not really sure how i would write my result echos. i have been trying all kinds of "update records" forms and cant get them right so i figured it may be easier to just try and create my own. if i could get some example or if you have more simple suggestions Hi, I was thinking of creating a table for this current code and place only 3 options in a row, however I do not know how to execute a command which will allow me to do so, I have attached 2 pictures to describe what I will like to achieve. Below is my code as well. Any advice? Thanks $query = ("SELECT * FROM tutor_preferred_district ORDER BY district_id ASC"); $sql = mysqli_query($dbc, $query) or die(mysql_error()); while($data = mysqli_fetch_array($sql)) { echo'<table>'; echo '<input name="district" type="checkbox" id="'.$data['district_id'].'" value="'.$data['district_id'].'">'; echo '<label for="'.$data['district_id'].'">'.$data['district_name'].'</label>'; echo'<table>'; } Hi all Complete noob here..... What I have to do is create a new database every year, but I can't just import last years data completely, only records when needed. I can do it myself in PHPMyAdmin, but I don't want my employees touching mysql directly. What I am trying to do is write a php script that will serach for a reocrd in last years database and if it exists insert it into the new database if it doesn't exists bring up a form so it can be entered. Any help would be greatly appreciated. Thanx ZZ I have a DB with 10 fields Records are entered under a date There can be 1 to 30 records for a given date I need to copy all records of a given date with the 10 fields of each... Into the same DB only changing the original date to a new date Sounds easy, but so far I haven't been able to make it work. Any nudge in the right directiion would be much appreciated. I want to display my records in form of 5 rows and then want to display a Next click for other 5 records and so on until all the records are displayed. Can any body give me an idea. |