PHP - Unique Form Entry To Mysql Db Situation
I spent several hours trying to figure this thing out. Thought I had it nailed, but still getting duplicate record entries into the MySQL DB when I do NOT want them.
Here's the plot:
People filling out the possible attendance form for a Ham Radio event *sometimes* bring a 2nd person (either a spouse or a friend). The 2nd person may, or may not, also has a Callsign which I need to put INSERT the same MySQL Callsign column. In any event, to also identify the 2nd person as coming 'with' the 1st person.
MOST of the attendees are individuals with NO 2nd person.
My entry form has these primary fields:
callsign
fullname
AND...
callsign2
fullname2
What I came up with was to process the MySQL INSERT for the primary callsign & fullname into their respective MySQL DB Columns (which works fine), and then........... immediately following the main Query INSERT, to do a substitution type thing depending on whether or not a form entry was made in the callsign2 field, AND/OR, the fullname2 field.
This partially works, but if there is ONLY a primary callsign and fullname in the form, I'm still getting a duplicate record entry which includes the callsign in the `with` column (which should ONLY take place IF there is a 2nd person indicated).
Confusing?
Here is what I have been wrestling with to try and accomplish the objective, and now my eyes are glazed over ;-(
// TRICKY PART HERE // If a 2nd Callsign AND a Fullname if ($callsign2 != ' ' && $fullname2 != ' ') { // Still make reference to the primary Callsign in the MySQL DB `with` column $with = $callsign; // Assignment to allow 2nd Callsign to be entered in the MySQL `callsign` column $callsign=$callsign2; $fullname=$fullname2; $sql="INSERT INTO `mytable` (`callsign`, `fullname`, `with`) VALUES ('$callsign', '$fullname', '$with')"; // If NO 2nd Callsign BUT a Fullname } elseif ($callsign2 = ' ' && $fullname2 != ' ') { // Make reference to the primary Callsign in the MySQL DB `with` column $with = $callsign; $callsign=$callsign2; $fullname=$fullname2; $sql="INSERT INTO `mytable` (`callsign`, `fullname`, `with`) VALUES ('$callsign', '$fullname', '$with')"; } else { // The only thing I could thing of to (hopefully) NOT make a 2nd entry // record in the MySQL DB IF there is NO 2nd person referenced $with = $callsign; } if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); }This mostly works EXCEPT if only a single (primary) person entry. The recap the objetives: 1. If ONLY a primary/single person entry on the form: * callsign & fullname get INSERTed into the `callsign` and `fullname` columns in the DB as ONLY one record entry 2. If BOTH a primary and 2nd person on the form: A. IF the 2nd person has a Callsign, then the 2nd record entry would be: * callsign2 & fullname2 get INSERTed into the `callsign` & `fullname` columns in the 2nd DB as a separate record entry * callsign of the primary person also gets INSERTED into the `with` column in the same 2nd DB record entry B. IF the 2nd person does NOT have a callsign, then the 2nd record entry would be: * fullname2 gets INSERTed into the `fullname` column in the DB as a separate 2nd DB record entry * callsign of the primary person also gets INSERTED into the `with` column in the same 2nd DB record entry I obvioiusly have overlooked something, but just can't seem to figure it out at this point {SIGH}. Thanks for any enlightenment. -FreakingOUT Similar TutorialsI have a mysql table which will store users email addresses (each is unique and is the primary field) and a timestamp. I have added another column called `'unique_code' (varchar(64), utf8_unicode_ci)`. What I would very much appreciate assistance with is; a) Generating a 5 digit alphanumeric code, ie: 5ABH6 b) Check all rows the 'unique_code' column to ensure it is unique, otherwise re-generate and check again c) Insert the uniquely generated 5 digit alphanumeric code into `'unique_code'` column, corresponding to the email address just entered. d) display the code on screen. What code must I put and where? **My current php is as follows:** Code: [Select] require "includes/connect.php"; $msg = ''; if($_POST['email']){ // Requested with AJAX: $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); try{ if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ throw new Exception('Invalid Email!'); } $mysqli->query("INSERT INTO coming_soon_emails SET email='".$mysqli->real_escape_string($_POST['email'])."'"); if($mysqli->affected_rows != 1){ throw new Exception('You are already on the notification list.'); } if($ajax){ die('{"status":1}'); } $msg = "Thank you!"; } catch (Exception $e){ if($ajax){ die(json_encode(array('error'=>$e->getMessage()))); } $msg = $e->getMessage(); } } Alright, wasn't quite sure how to summarize this in the title, but I want to: Check if a user status is "active" or not based on the UserName input. I have a table witch holds: Code: [Select] VarChar Username Var CharPassWord int Active Ted TedsPW 1 something like the above(assuming it formatted correctly. In my php script I will want to input a variable for Username to check for: inputUN in this example would be "Ted". $UserNameToCheck = $_GET['inputUN']; Then I want to check for that UserName in the database, if it exists, I want pull the value for the "Active" field for just that UserName and echo it. Thanks for any help. I am trying to set up a item entry page form.png: Upon submission it shows unsuccessful even though I have checked the fields on mysql table and seem to be good am I missing something? Code: [Select] <form action="" method="post" enctype="multipart/form-data" name="Product_Entry"> <TABLE> <TR> <TD>Product ID</TD><TD><input name="SKU_ProductID" value="<?php if (isset($_post['SKU_ProductID'])) echo $_POST['SKU_ProductID']; ?>" type="text" size="11" maxlength="11" /></TD> </TR> <TR> <TD>Merchant SKU ID</TD><TD><input name="SKU_MerchSKUID" value="<?php if (isset($_post['SKU_MerchSKUID'])) echo $_POST['SKU_MerchSKUID']; ?>" type="text" size="18" maxlength="30" /></TD> </TR> <TR> <TD>Game Title</TD><TD><input name="Game_Title" value="<?php if (isset($_post['Game_Title'])) echo $_POST['Game_Title']; ?>" type="text" size="40" maxlength="40" /></TD> </TR> <TR> <TD>Platform</TD><TD><input name="Platform" value="<?php if (isset($_post['Platform'])) echo $_POST['Platform']; ?>" type="text" size="20" maxlength="20" /></TD> </TR> <TR> <TD>Genre</TD><TD><input name="Genre" value="<?php if (isset($_post['Genre'])) echo $_POST['Genre']; ?>" type="text" size="11" maxlength="11" /></TD> </TR> <TR> <TD>Weight</TD><TD><input name="Weight" value="<?php if (isset($_post['Weight'])) echo $_POST['Weight']; ?>" type="text" size="7" maxlength="7" /></TD> </TR> <TR> <TD>Supplier</TD><TD><input name="Supplier" Value="<?php if (isset($_post['Supplier'])) echo $_POST['Supplier']; ?>" type="text" size="25" maxlength="25" /></TD> </TR> <TR> <TD>Suppliers Price</TD><TD><input name="Supplier_Price" value="<?php if (isset($_post['Supplier_Price'])) echo $_POST['Supplier_Price']; ?>" type="text" size="10" maxlength="12" /></TD> </TR> <TR> <TD>Cashback</TD><TD><input name="Cashback" value="<?php if (isset($_post['Cashback'])) echo $_POST['Cashback']; ?>" type="text" size="6" maxlength="8" /></TD> </TR> <TR> <TD>Cashback Amount</TD><TD><input name="Cashback_Amount" value="<?php if (isset($_post['Cashback_Amount'])) echo $_POST['Cashback_Amount']; ?>" type="text" size="7" maxlength="11" /></TD> </TR> <TR> <TD><input type="hidden" name="submitted" value="true"/></TD><TD><input name="Submit" type="submit" value="Add_Product" /></TD> </TR></form></TABLE> <?php # Product Entry $page_title = 'Product Entry'; if (isset($_POST['Submit'])) { $errors = array(); if (empty($_POST['SKU_ProductID'])) { $errors[] = 'Please enter Product ID.'; } else { $sid = trim($_POST['SKU_ProductID']); } if (empty($_POST['SKU_MerchSKUID'])) { $errors[] = 'Please enter Merchant SKU.'; } else { $mid = trim($_POST['SKU_MerchSKUID']); } if (empty($_POST['Game_Title'])) { $errors[] = 'Please enter Game Title.'; } else { $gt = trim($_POST['Game_Title']); } if (empty($_POST['Platform'])) { $errors[] = 'Please enter Platform.'; } else { $pl = trim($_POST['Platform']); } if (empty($_POST['Genre'])) { $errors[] = 'Please enter Genre.'; } else { $ge = trim($_POST['Genre']); } if (empty($_POST['Weight'])) { $errors[] = 'Please enter Weight.'; } else { $we = trim($_POST['Weight']); } if (empty($_POST['Supplier'])) { $errors[] = 'Please enter Supplier.'; } else { $sup = trim($_POST['Supplier']); } if (empty($_POST['Supplier_Price'])) { $errors[] = 'Please enter Supplier Price.'; } else { $sp = trim($_POST['Supplier_Price']); } if (empty($_POST['Cashback'])) { $errors[] = 'Please enter Cashback %.'; } else { $cb = trim($_POST['Cashback']); } if (empty($_POST['Cashback_Amount'])) { $errors[] = 'Please enter Cashback Amount.'; } else { $cba = trim($_POST['Cashback_Amount']); } if (empty($errors)) { require_once ('connect.php'); [b]$q = "INSERT INTO `Products` (`SKU_ProductID`, `SKU_MerchSKUID`, `Game_Title`, `Platform`, `Genre`, `Weight`, `Supplier`, `Supplier_Price`, `Cashback`, `Cashback_Amount`) VALUES ('$sid', '$mid', '$gt', '$pl', '$ge', '$we', '$sup', '$sp', '$cb', '$cba')"; $r = @mysql_query ($dbc, $q); if ($r) { // If it ran OK. // Print a message: echo '<h1>Thank you!</h1> <p>Product Inserted!</p><p><br /></p>'; } else { // If it did not run OK. // Public message: echo '<h1>System Error</h1> <p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; // Debugging message: echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } // End of if ($r) IF. mysqli_close($dbc); // Close the database connection.[/b] // Include the footer and quit the script: include ('includes/footer.html'); exit(); } else { echo '<H1>Error!</H1> <p class="error">The Following error(s) occurred:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } } ?> If there is anything else needed let me know I am using php to upload a file to my server, and at the same time inserting the files name and url into my mysql database.
$sql = "UPDATE uploads SET name = '$name', url='$target_path'"; $statement = $dbh->prepare($sql); $statement->execute();This is working, however, when I upload a new file, rather than making a new entry in my database, it just overwrites the first one. I'm quite new at mysql so was wondering how I would make it add new entrys instead of overwriting the current one? I have a mysql unique index on two columns: UNIQUE KEY `page_id` (`page_id`,`tag_id`) I have a mysql query like this: Code: [Select] mysql_query("insert into link_tags (page_id, tag_id) values ($page_id, $tag_id)"); If I run that, what would be the best way for php not to fail if the key already exists? within a while loop, would this be best? Code: [Select] if(mysql_query("insert into link_tags (page_id, tag_id) values ($page_id, $tag_id)")) continue; Or would the code above (first code) be sufficient enough? Hi, First off: I got a table with two columns and 100.000 rows. Some of the rows are duplicates (allowing me to "weight" the chance of some rows being hit the first time the script runs) Allright. This i what I want to do: When the user clicks a button: 1. Generate a random selected row from the table (this I allready accomplished using this code: Code: [Select] <?php //CODE FROM WWW.GREGGDEV.COM function random_row($table, $column) { $max_sql = "SELECT max(" . $column . ") AS max_id FROM " . $table; $max_row = mysql_fetch_array(mysql_query($max_sql)); $random_number = mt_rand(1, $max_row['max_id']); $random_sql = "SELECT * FROM " . $table . " WHERE " . $column . " >= " . $random_number . " ORDER BY " . $column . " ASC LIMIT 1"; $random_row = mysql_fetch_row(mysql_query($random_sql)); if (!is_array($random_row)) { $random_sql = "SELECT * FROM " . $table . " WHERE " . $column . " < " . $random_number . " ORDER BY " . $column . " DESC LIMIT 1"; $random_row = mysql_fetch_row(mysql_query($random_sql)); } return $random_row; } //USAGE $randomdata = random_row('MYTABLE', 'MYCOLUMN'); echo $randomdata[2]; // Where [2] is the data I want to extract. ?> This script works fine. The problem is that I want to exclude the results that have allready been shown. With me? Therefore, since I have duplicate rows of certain data, I need to exclude all the rows that are the same. I have a couple of solutions, but I can't seem to fit it into this script. (I will not use the ORDER_BY_RAND() query; it'll be too slow for a table with 100.000 rows) SO: Here's ideas I've come up with that might work, but because of my limited experience with PHP and MySQL, haven't been able to accomplish. 1) Insert a "temporary" column in the table which is filled with 1 and 0's where 1 indicates that the row has allready been taken? (If possible) 2) Use PHP sessions to store the previously generated rows? 3) Create a temporary table, which fills up with the allready generated rows by the random script? 4) Create a unique txt-file (e.g: _USERSIPADRESS__.txt) which can be used to save and extract data from the random script? (fopen, fwrite and so fourth) I hope you understand what I'm trying to do Any suggestions would be highly appreciated. Thank you. Hello guys, How do I total unique id's with php or MySQL. For instance in MySQL I have... ID 1 1 3 4 2 1 1 3 How can I total all of the 1's, all of the twos, all of the threes and so forth. I have four 1's, one 2, two 3's and so forth... I tried adding a group field to my user table so I can show different content to different users but when I do the check and then if/else the required info it doesn't seem to do it. I think I've got a mistake in my query: <?php include ('header.php'); ?> </center> <?php $username = mysql_real_escape_string($_POST['username']); $checkadmin = mysql_query("SELECT Group FROM users WHERE Username = '".$username."'"); if('$checkadmin' == GroupA) { ?> Welcome Admin! <?php } else { ?> You are not authorised. <?php } include ('footer.php') ?> Whats wrong with it? Cheers. I am trying to write a script that runs through a CSV file and inserts unique values in a mysql database and spits the duplicate out into a new CSV. I can find the duplicates when I load it into an array, but when I insert them into a MySQL database, I cannot determine if they are duplicates. If I use INSERT IGNORE, it will run the whole file, and reject the duplicates. This is fine, except I need to create a file of the duplicate entries. What is the best way to determine if the insert attempt was rejected? I could do a select to see if the row is there, spit it out...insert if not, but I was thinking there should be a way for MySQL to talk back to me to cut the queries in half... Any ideas? Thanks I wrote a site for work that holds employee schedule. By demand of my manager she would like an edit function with out having to re-enter the hole thing. She is very BLOND!! the layout has to stay the same other wise she will never figure it out. i need to be query the db pull the info, edit it and send it back or get it info and then delete then enter new. this is the code i already use to query the info from the db: Code: [Select] <? ini_set("display_errors", "1"); error_reporting(E_ALL); include("dbinfo.php"); mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM schedule ORDER BY date DESC LIMIT 2"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $date=mysql_result($result,$i,'date'); $urn=mysql_result($result,$i,'urn'); $date0=mysql_result($result,$i,'date0'); $date1=mysql_result($result,$i,'date1'); $date2=mysql_result($result,$i,'date2'); $date3=mysql_result($result,$i,'date3'); $date4=mysql_result($result,$i,'date4'); $date5=mysql_result($result,$i,'date5'); $date6=mysql_result($result,$i,'date6'); $date7=mysql_result($result,$i,'date7'); $day=mysql_result($result,$i,"day"); $day1=mysql_result($result,$i,"day1"); $day2=mysql_result($result,$i,"day2"); $day3=mysql_result($result,$i,"day3"); $day4=mysql_result($result,$i,"day4"); $day5=mysql_result($result,$i,"day5"); $day6=mysql_result($result,$i,"day6"); $day7=mysql_result($result,$i,"day7"); $row1=mysql_result($result,$i,"row1"); $row2=mysql_result($result,$i,"row2"); $row3=mysql_result($result,$i,"row3"); $row4=mysql_result($result,$i,"row4"); $row5=mysql_result($result,$i,"row5"); $row6=mysql_result($result,$i,"row6"); $row7=mysql_result($result,$i,"row7"); $row8=mysql_result($result,$i,"row8"); $row9=mysql_result($result,$i,"row9"); $row10=mysql_result($result,$i,"row10"); $row11=mysql_result($result,$i,"row11"); $row12=mysql_result($result,$i,"row12"); $row13=mysql_result($result,$i,"row13"); $row14=mysql_result($result,$i,"row14"); $row15=mysql_result($result,$i,"row15"); $row16=mysql_result($result,$i,"row16"); $row17=mysql_result($result,$i,"row17"); $row18=mysql_result($result,$i,"row18"); $row19=mysql_result($result,$i,"row19"); $row20=mysql_result($result,$i,"row20"); $row21=mysql_result($result,$i,"row21"); $row22=mysql_result($result,$i,"row22"); $row23=mysql_result($result,$i,"row23"); $row24=mysql_result($result,$i,"row24"); $row25=mysql_result($result,$i,"row25"); $row26=mysql_result($result,$i,"row26"); $row27=mysql_result($result,$i,"row27"); $row28=mysql_result($result,$i,"row28"); $row29=mysql_result($result,$i,"row29"); $row30=mysql_result($result,$i,"row30"); $row31=mysql_result($result,$i,"row31"); $row32=mysql_result($result,$i,"row32"); $row33=mysql_result($result,$i,"row33"); $row34=mysql_result($result,$i,"row34"); $row35=mysql_result($result,$i,"row35"); $row36=mysql_result($result,$i,"row36"); $row37=mysql_result($result,$i,"row37"); $row38=mysql_result($result,$i,"row38"); $row39=mysql_result($result,$i,"row39"); $row40=mysql_result($result,$i,"row40"); $row41=mysql_result($result,$i,"row41"); $row42=mysql_result($result,$i,"row42"); $row43=mysql_result($result,$i,"row43"); $row44=mysql_result($result,$i,"row44"); $row45=mysql_result($result,$i,"row45"); $row46=mysql_result($result,$i,"row46"); $row47=mysql_result($result,$i,"row47"); $row48=mysql_result($result,$i,"row48"); $row50=mysql_result($result,$i,"row50"); $row51=mysql_result($result,$i,"row51"); $row52=mysql_result($result,$i,"row52"); $row53=mysql_result($result,$i,"row53"); $row54=mysql_result($result,$i,"row54"); $row55=mysql_result($result,$i,"row55"); $row56=mysql_result($result,$i,"row56"); $row57=mysql_result($result,$i,"row57"); $row58=mysql_result($result,$i,"row58"); $row59=mysql_result($result,$i,"row59"); $row60=mysql_result($result,$i,"row60"); $row61=mysql_result($result,$i,"row61"); $row62=mysql_result($result,$i,"row62"); $row63=mysql_result($result,$i,"row63"); $row64=mysql_result($result,$i,"row64"); $row65=mysql_result($result,$i,"row65"); $drive1=mysql_result($result,$i,"drive1"); $drive2=mysql_result($result,$i,"drive2"); $drive3=mysql_result($result,$i,"drive3"); $drive4=mysql_result($result,$i,"drive4"); $drive5=mysql_result($result,$i,"drive5"); $drive6=mysql_result($result,$i,"drive6"); $drive7=mysql_result($result,$i,"drive7"); $drive8=mysql_result($result,$i,"drive8"); $drive9=mysql_result($result,$i,"drive9"); $drive10=mysql_result($result,$i,"drive10"); $drive11=mysql_result($result,$i,"drive11"); $drive12=mysql_result($result,$i,"drive12"); $drive13=mysql_result($result,$i,"drive13"); $drive14=mysql_result($result,$i,"drive14"); $drive15=mysql_result($result,$i,"drive15"); $drive16=mysql_result($result,$i,"drive16"); $drive17=mysql_result($result,$i,"drive17"); $drive18=mysql_result($result,$i,"drive18"); $drive19=mysql_result($result,$i,"drive19"); $drive20=mysql_result($result,$i,"drive20"); $drive21=mysql_result($result,$i,"drive21"); $drive22=mysql_result($result,$i,"drive22"); $drive23=mysql_result($result,$i,"drive23"); $drive24=mysql_result($result,$i,"drive24"); $drive25=mysql_result($result,$i,"drive25"); $drive26=mysql_result($result,$i,"drive26"); $drive27=mysql_result($result,$i,"drive27"); $drive28=mysql_result($result,$i,"drive28"); $drive29=mysql_result($result,$i,"drive29"); $drive30=mysql_result($result,$i,"drive30"); $drive31=mysql_result($result,$i,"drive31"); $drive32=mysql_result($result,$i,"drive32"); $drive33=mysql_result($result,$i,"drive33"); $drive34=mysql_result($result,$i,"drive34"); $drive35=mysql_result($result,$i,"drive35"); $drive36=mysql_result($result,$i,"drive36"); $drive37=mysql_result($result,$i,"drive37"); $drive38=mysql_result($result,$i,"drive38"); $drive39=mysql_result($result,$i,"drive39"); $drive40=mysql_result($result,$i,"drive40"); $drive41=mysql_result($result,$i,"drive41"); $drive42=mysql_result($result,$i,"drive42"); $drive43=mysql_result($result,$i,"drive43"); $drive44=mysql_result($result,$i,"drive44"); $drive45=mysql_result($result,$i,"drive45"); $drive46=mysql_result($result,$i,"drive46"); $drive47=mysql_result($result,$i,"drive47"); $drive48=mysql_result($result,$i,"drive48"); $drive49=mysql_result($result,$i,"drive49"); $drive50=mysql_result($result,$i,"drive50"); $drive51=mysql_result($result,$i,"drive51"); $drive52=mysql_result($result,$i,"drive52"); $drive53=mysql_result($result,$i,"drive53"); $drive54=mysql_result($result,$i,"drive54"); $drive55=mysql_result($result,$i,"drive55"); $drive56=mysql_result($result,$i,"drive56"); $drive57=mysql_result($result,$i,"drive57"); $drive58=mysql_result($result,$i,"drive58"); $drive59=mysql_result($result,$i,"drive59"); $drive60=mysql_result($result,$i,"drive60"); $drive61=mysql_result($result,$i,"drive61"); $drive62=mysql_result($result,$i,"drive62"); $drive63=mysql_result($result,$i,"drive63"); $drive64=mysql_result($result,$i,"drive64"); $drive65=mysql_result($result,$i,"drive65"); $drive66=mysql_result($result,$i,"drive66"); $drive67=mysql_result($result,$i,"drive67"); $drive68=mysql_result($result,$i,"drive68"); $drive69=mysql_result($result,$i,"drive69"); $drive70=mysql_result($result,$i,"drive70"); $drive71=mysql_result($result,$i,"drive71"); $drive72=mysql_result($result,$i,"drive72"); $drive73=mysql_result($result,$i,"drive73"); $drive74=mysql_result($result,$i,"drive74"); $drive75=mysql_result($result,$i,"drive75"); $drive76=mysql_result($result,$i,"drive76"); $drive77=mysql_result($result,$i,"drive77"); $drive78=mysql_result($result,$i,"drive78"); $drive79=mysql_result($result,$i,"drive79"); $drive80=mysql_result($result,$i,"drive80"); ?> <div align="center"> <blink>Warning:</blink> Clicking delete will delete this sechedule (no going back once clicked) <table style="width 87%" border="1" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">The Schedule as of: <? echo $date; ?></th> <th><a href="/dominos/admin/delete2.php?urn=<? echo $urn; ?>"><input name='' type='button' value='Delete'/></a></th> <th><a href="../admin/emailit.php"><input type="button" value="Email" /></a></th> <th><a href="../test.php?urn=<? echo $urn; ?>"><input type="button" value="Edit"/></a></th> </tr> </table> <br /> <br /> <input type="text" name="date0" id="date0" value="<? echo $date0; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date1" id="date1" value="<?php echo $date1; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="trans" name="date2" id="date2" value="<?php echo $date2; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date3" id="date3" value="<?php echo $date3; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date4" id="date4" value="<?php echo $date4; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date5" id="date5" value="<?php echo $date5; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date6" id="date6" value="<?php echo $date6; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date7" id="date7" value="<?php echo $date7; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $day; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date1" id="date1" value="<?php echo $day1; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="trans" name="date2" id="date2" value="<?php echo $day2; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date3" id="date3" value="<?php echo $day3; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date4" id="date4" value="<?php echo $day4; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date5" id="date5" value="<?php echo $day5; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date6" id="date6" value="<?php echo $day6; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date7" id="date7" value="<?php echo $day7; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $row1; ?>"size="12" maxlength="12" readonly="true"style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row2; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row3; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row4; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row5; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row6; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row7; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row8; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $row9; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row10; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row11; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row12; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row13; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row14; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row15; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row16; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $row17; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row18; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row19; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row20; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row21; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row22; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row23; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row24; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $row25; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row26; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row27; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row28; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row29; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row30; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row31; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row32; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $row33; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row34; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row35; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row36; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row37; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row38; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row39; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row40; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $row41; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row42; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row43; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row44; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row45; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row46; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row47; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row48; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $row50; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row51; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row52; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row53; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row54; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row55; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row56; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row57; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $row58; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row59; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row60; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row61; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row62; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row63; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row64; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $row65; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <br /> <input type="text" name="date0" id="date0" value="<? echo $drive1; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold" /> <input type="text" name="date0" id="date0" value="<? echo $drive2; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive3; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive4; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive5; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive6; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive7; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive8; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $drive9; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive10; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive11; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive12; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive13; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive14; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive15; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive16; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $drive17; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive18; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive19; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive20; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive21; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive22; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive23; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive24; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $drive25; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive26; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive27; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive28; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive29; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive30; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive31; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive32; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $drive33; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive34; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive35; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive36; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive37; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive38; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive39; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive40; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $drive41; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive42; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive43; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive44; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive45; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive46; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive47; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive48; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $drive49; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive50; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive51; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive52; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive53; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive54; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive55; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive56; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $drive57; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive58; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive59; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive60; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive61; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive62; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive63; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive64; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $drive65; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive66; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive67; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive68; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive69; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive70; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive71; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive72; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <input type="text" name="date0" id="date0" value="<? echo $drive73; ?>"size="12" maxlength="12" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive74; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive75; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive76; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive77; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive78; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive79; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <input type="text" name="date0" id="date0" value="<? echo $drive80; ?>"size="10" maxlength="10" readonly="true" style="font-weight:bold"/> <br /> <br /> <br /> <br /> <? $i++;} ?> so i have a mysql column with a datetime and i was wondering how i could make it echo the time in "X minutes ago" or "X hours ago" and also, when its more then 24 hours old, delete the entire entry Can anyone point out what's wrong with my feedback.php? It used to work fine and I don't think I did anything but it stopped working - i.e. I had it on a site which I never looked at and when I did look at it I noticed the rubbish written to the database had inexplicably stopped being written there some months ago..... since then I've tried to clean it up and use it elsewhere ( I'm a baby at php and most else) but I can't get it to go right. In this attempt it was giving me the dreaded 'headers already written..' error and I (after googling) took out all the blank space I could and extra comments and what not and stuck in some debugging prints for me and now I get no errors but I get nothing written to the database and no email sent to me. If anyone cares to look at it to help me out, here it is, warts and all, with just the names changed to protect the innocent. <? // mail it $mailto = 'med@yahoo.com' ; $subject = "Ploverpark Feedback Form" ; $formurl = "feedback.html" ; $errorurl = "error.html" ; $thankyouurl = "thankyou.html" ; $uself = 0; $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ; $username = $_POST['username'] ; $firstname = $_POST['firstname'] ; $email = $_POST['email'] ; $comments = $_POST['comments'] ; $secondname = $_POST['secondname'] ; $country = $_POST['country'] ; $phone = $_POST['phone'] ; // do write to database now--------------------------- $link = mysql_connect("mydb.com", "my_pkguest", "password") or die("Could not connect : " . mysql_error()); print "Connected successfully<p>"; $DB = "my_pkguest"; $table = "clients"; mysql_select_db($DB) or die ("Database $DB not select.." . mysql_error()); print "Successfully select the Database: $DB "; $query = "INSERT INTO $table(username,firstname,secondname,email,country,phone,comments) values('$username','$firstname','$secondname','$email','$country','$phone','$comments')"; print "Successfully inserted to table: $table "; //------------------------------------------------------ $http_referrer = getenv( "HTTP_REFERER" ); if (!isset($_POST['email'])) { header( "Location: $formurl" ); exit ; } print "Now past the if isset "; //if (empty($name) || empty($email) || empty($comments)) { // header( "Location: $errorurl" ); // exit ; //} if ( ereg( "[\r\n]", $username ) || ereg( "[\r\n]", $email ) ) { header( "Location: $errorurl" ); exit ; } print "Now past the if ereg "; if (get_magic_quotes_gpc()) { $comments = stripslashes( $comments ); } $messageproper = "This message was sent from:\n" . "$http_referrer\n" . "------------------------------------------------------------\n" . "UserName of sender: $username\n" . "Firstname of sender: $firstname\n" . "Secondname of sender : $secondname\n" . "Country of sender : $country\n" . "Phone number of sender: $phone\n" . "Email of sender: $email\n" . "------------------------- COMMENTS -------------------------\n\n" . $comments . "\n\n------------------------------------------------------------\n" ; print "Now past the messageproper "; mail($mailto, $subject, $messageproper, "From: \"$username\" <$email>" . $headersep . "Reply-To: \"$username\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" ); print "Now past the mail"; //header( "Location: $thankyouurl" ); // exit ; ?> I've started a to-do app, and everything works fine. Every user has his own unique to-do items that he can add. The only issue is that when I log-in with a user, ALL the items of all users are displayed when I'm redirect to my main page. I want to make it as so every user has his own page where only the to-do items he has created are visible, not every item from every user. I'm a total beginner with PHP so I'm sorry if this is a stupid question. This is my todomain.php code <?php require 'db_conn.php'; require 'config.php'; session_start(); // If the session variable is empty, this // means the user is yet to login // User will be sent to 'login.php' page // to allow the user to login if (!isset($_SESSION['id'])) { $_SESSION['msg'] = "You have to log in first"; header('location: login.php'); } // Logout button will destroy the session, and // will unset the session variables // User will be headed to 'login.php' // after loggin out if (isset($_GET['logout'])) { session_destroy(); unset($_SESSION['id']); header("location: login.php"); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset= "UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <link rel="stylesheet" href="css/bootstrap-grid.min.css"> <link rel="stylesheet" href="css/bootstrap.min.css"> <link rel="stylesheet" href="style.css"> <a href="index.php?logout='1'" style="color: black;"> Click here to Logout </a> <?php if (isset($_SESSION['success'])) : ?> <div class="error success" > <h3> <?php echo $_SESSION['success']; unset($_SESSION['success']); echo $_SESSION["username"] ?> </h3> </div> <?php endif ?> <title>TODO App</title> <script src="https://kit.fontawesome.com/d72928d9b9.js" crossorigin="anonymous"></script> </head> <body> <div class="container m-5 p-2 rounded mx-auto bg-light shadow"> <!-- App title section --> <div class="row m-1 p-4"> <div class="col"> <div class="p-1 h1 text-primary text-center mx-auto display-inline-block"> <i class="fa fa-check bg-primary text-white rounded p-2"></i> <u>My Todo-s</u> </div> </div> </div> <!-- Create todo section --> <form action="app/add.php" method="POST" autocomplete="off"> <div class="row m-1 p-3"> <div class="col col-11 mx-auto"> <div class="row bg-white rounded shadow-sm p-2 add-todo-wrapper align-items-center justify-content-center"> <div class="col"> <input class="form-control form-control-lg border-0 add-todo-input bg-transparent rounded" type="text" name="title" placeholder="Add new .."> </div> <div class="col-auto m-0 px-2 d-flex align-items-center"> <label class="text-secondary my-2 p-0 px-1 view-opt-label due-date-label d-none">Due date not set</label> <i class="fa fa-calendar my-2 px-1 text-primary btn due-date-button" data-toggle="tooltip" data-placement="bottom" title="Set a Due date"></i> <i class="fa fa-calendar-times-o my-2 px-1 text-danger btn clear-due-date-button d-none" data-toggle="tooltip" data-placement="bottom" title="Clear Due date"></i> </div> <div class="col-auto px-0 mx-0 mr-2"> <button type="submit" class="btn btn-primary">Add</button> </div> </div> </div> </div> </form> <?php $todos=$conn->query("SELECT * FROM todos ORDER BY id ASC"); ?> <div class="row mx-1 px-5 pb-3 w-80"> <div class="col mx-auto"> <?php while($todo=$todos->fetch(PDO::FETCH_ASSOC)){ ?> <!-- Todo Item 1 --> <div class="row px-3 align-items-center todo-item rounded"> <?php if($todo['checked']){ ?> <input type="checkbox" class="check-box" data-todo-id="<?php echo $todo['id'];?>" checked /> <h2 class="checked"><?php echo $todo['title'] ?> </h2> <div class="col-auto m-1 p-0 todo-actions"> <div class="row d-flex align-items-center justify-content-end"> </div> </div> <?php } else{ ?> <input type="checkbox" class="check-box" data-todo-id="<?php echo $todo['id'];?>"/> <h2><?php echo $todo['title'] ?></h2> <?php } ?> <div class="col-auto m-1 p-0 d-flex align-items-center"> <h2 class="m-0 p-0"> <i class="fa fa-square-o text-primary btn m-0 p-0 d-none" data-toggle="tooltip" data-placement="bottom" title="Mark as complete"></i> </h2> </div> <div class="col-auto m-1 p-0 todo-actions"> <div class="row d-flex align-items-center justify-content-end"> <h5 class="m-0 p-0 px-2"> <i class="fa fa-pencil text-info btn m-0 p-0" data-toggle="tooltip" data-placement="bottom" title="Edit todo"></i> </h5> <h5 class="m-0 p-0 px-2"> <i class="remove-to-do fa fa-trash-o text-danger btn m-0 p-0" data-toggle="tooltip" data-placement="bottom" title="Delete todo" id="<?php echo $todo['id']; ?>"></i> </h5> </div> <div class="row todo-created-info"> <div class="col-auto d-flex align-items-center pr-2"> <i class="fa fa-info-circle my-2 px-2 text-black-50 btn" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Created date"></i> <label class="date-label my-2 text-black-50"><?php echo $todo['date_time'] ?></label> </div> </div> </div> </div> <?php } ?> </div> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script> <script src="js/bootstrap.bundle.min.js"></script> <script src="js/myjs.js" ></script> <script src="js/jquery-3.3.1.min.js"></script> <script> $(document).ready(function(){ $(".remove-to-do").click(function(e){ const id = $(this).attr('id'); $.post('app/remove.php', { id: id }, (data) => { if(data){ $(this).parent().parent().parent().parent().hide(300); } } ); }); $(".check-box").click(function(e){ const id = $(this).attr('data-todo-id'); $.post('app/checking.php', { id: id }, (data) => { if(data!='error'){ const h2= $(this).next(); if(data === '1'){ h2.removeClass('checked'); }else{ h2.addclass('checked'); } } } ); }); }); </script> </body> </html>
I have a form that passes multiple images and I wanted them to have a substring of a md5 encrypted time for generating unique codes so I don't delete or overwrite an older file. I keep the actual images in a folder and the path in mysql. The folder is working perfectly and there are no problems generating unique codes but I have been trying all night and I can't figure out why mysql won't update. I can actually get it to update but then I loose the functionallity of the code and if I don't upload a 4 images and leave one blank, the blank one deletes the previously uploaded field in the table row. Here is the md5 encrypted time for generating unique codes: Code: [Select] $unique = strtolower(substr(md5(time()), 0, 4)); This is how it works with the folder: Code: [Select] $filePath = $uploadDir . $unique . $fileName; This is how I get it to update mysql but then loose functionality: Code: [Select] $values[$i] = $unique . mysql_real_escape_string(basename(trim($_FILES[$fields[$i]]['name']))); Here is the entire code: Code: [Select] <?php require_once('storescripts/connect.php'); mysql_select_db($database_phpimage,$phpimage); $unique = strtolower(substr(md5(time()), 0, 4)); $uploadDir = 'upload/'; if(isset($_POST['upload' . $config])) { foreach ($_FILES as $file) { $fileName = $file['name']; $tmpName = $file['tmp_name']; $fileSize = $file['size']; $fileType = $file['type']; if($fileName==""){ $filePath = 'upload/'; } else{ $filePath = $uploadDir . $unique . $fileName; } $filePath = str_replace(" ", "_", $filePath); $result = move_uploaded_file($tmpName, $filePath); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } $fileinsert[]=$filePath; } } $mid = mysql_real_escape_string(trim($_POST['mid'])); $cat = mysql_real_escape_string(trim($_POST['cat'])); $item = mysql_real_escape_string(trim($_POST['item'])); $price = mysql_real_escape_string(trim($_POST['price'])); $about = mysql_real_escape_string(trim($_POST['about'])); $fields = array(); $values = array(); $updateVals = array(); for($i=1; $i<=4; $i++) { $fields[$i] = 'name'.$i; $values[$i] = mysql_real_escape_string(basename(trim($_FILES[$fields[$i]]['name']))); if($values[$i] != '') { $updateVals[] = "{$fields[$i]} = '{$values[$i]}'"; } } $updateNames = ''; if(count($updateVals)) { $updateNames = ", " . implode(', ', $updateVals); } $update = "INSERT INTO image (mid, cid, item, price, about, name1, name2, name3, name4) VALUES ('$mid', '$cat', '$item', '$price', '$about', '$values[1]', '$values[2]', '$values[3]', '$values[4]') ON DUPLICATE KEY UPDATE cid = '$cat', item = '$item', price = '$price', about = '$about' $updateNames"; $result = mysql_query($update) or die (mysql_error()); $id = mysql_insert_id(); ?> <p style="font-size:35px; font-family:Arial, Helvetica, sans-serif; color:#255E67; margin-left:25px;">Your Item Has Been Uploaded!</p> <script type="text/javascript"> setTimeout('ourRedirect()', 2000) function ourRedirect() { location.href='protator_php.php?mid=<?php echo $id ?>' } </script> Hello coders, I'm using this code to grab random results from a table and it works well but I need it to be a non-repeating event. Code: [Select] $offset_result = mysql_query( " SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM `jobs_board` "); $offset_row = mysql_fetch_object( $offset_result ); $offset = $offset_row->offset; I'm using this query followed by the html which is a set of divs with inline echo statements for the various variables I've localised from the table. Then I'm repeating that process a number of times to create a small list (I wanted to use a single while loop but cant figure it out at the moment). Anways, how can I make it so each query is random but also not repeated? At the moment they are indeed random but sometimes one same entry will appear a number of times consecutively... Nice one guys, L-plate Hi Friends, I am suffering with very serious problem, We have a deal selling website--Problem is that when someone buy a deal , they are getting 2 vouchers on bahalf of one while they are getting charged ones only [I am using authorized.net payment gateway]. for some reason Entry is inserting TWICE in MYSQL but it is not happening on every purchase, it happens once in 20 purchase (for example).... I have tried every possible effort but it still happens, anybody can show me helping hand please ? this is my partial code where I am inserting the voucher info : for($i=0; $i<$_SESSION['quHidden']; $i++): if($_SESSION['RecName'][$i]!=''):$IsGist="t";$GRName=$_SESSION['RecName'][$i];else:$IsGist="f";$GRName="";endif; $coupon_code=str_makerand("12", "12", "false", "false", "false"); $NCCod="#".$coupon_code; $download_path="dealcoupon.php?id=".$sql_coupon['deal_id']."&CRANCode=".$coupon_code; $DLContent[]="<a href=\"".$download_path."\" target=\"_blank\" style=\"font-family: Helvetica,Arial,sans-serif; color: rgb(9, 129, 190);font-size: 14px;\">Download Voucher: ".$NCCod."</a>"; mysql_query("INSERT INTO `tbl_purchase` ( `fld_buyerid` , `fld_dealid` , `fld_amount` , `fld_purchaseid`, `fld_subdate`, `fld_expdate`, `fld_quantity`, `fld_cardno`, `isGift`, `fld_RecName`) VALUES ( '".$_SESSION['usr_id']."', '".$sql_coupon['deal_id']."', '".$sql_coupon['deal_price']."', '$NCCod', '".time()."', '".$sql_coupon[deal_edate]."', '1', '".$_SESSION['x_card_num']."','".$IsGist."','".$GRName."')"); $CoupanArr[]=$NCCod; endfor; //--------------------------------------------------------------------- mysql_query("insert into tbl_vouemails set fld_did='".$sql_coupon['deal_id']."', fld_uid='".$_SESSION['usr_id']."', fld_voucher='".implode(",",$CoupanArr)."', fld_etime='".getPATime($sql_coupon[deal_edate])."', fld_subdate='".time()."', fld_VReceiver='".implode(",",$_SESSION['RecName'])."'"); This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=312600.0 What im trying to achieve is a user contact system, when the user types input in the textarea its saved in a database along with his userid on the site and the date, I have an admin side coded up where it retrieves the data, but there is no order. I want to have it display the most recent results on top. I have looked into this in the mysql manual, but you know how that is its so hard to make sense of anything in that damn manual. Im using a while loop to display the data. How can I achieve this? |