PHP - Updating Records
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 Similar TutorialsI have got myself a bit confused whilst trying to create an 'update selected records' page. In memberlist.php, a set of records is shown, each with a checkbox. When the user clicks on 'Update Selected' it opens up membermultiupdate.php. I cannot get this page to recognise which id's have been passed and put them in an array so only the checked records are shown. The page in question is at http://www.margate-fc.com/memberlist.php. When it opens membermultiupdate.php, there are currently 2 errors.... Code: [Select] Warning: implode() [function.implode]: Invalid arguments passed in /homepages/46/d98455693/htdocs/membermultiupdate.php on line 11 which refers to $update = implode ("','", mysql_real_escape_string ($_POST['checkbox'])) Code: [Select] Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /homepages/46/d98455693/htdocs/membermultiupdate.php on line 44which is while ($rowmembers = mysql_fetch_array($members)) I have also tried mysql_fetch_assoc there too. I may be miles out or I may be missing something simple but I have tried for hours now to get my head around this and have not even got to the point where I can see if the actual update side works! Any suggestions would be greatly received and I have put the relevant code from both pages below. Thanks in advance for any help or suggestions Steve memberlist.php The query to get all rows $members = mysql_query(" SELECT * FROM users"); The submit form with checkboxes <form name="form1" method="post" action="membermultiupdate.php"> <?php while ($rowmembers = mysql_fetch_assoc($members)) {echo ' <tr> <td><input type="hidden" name="id[]" value="'.$rowmembers['id'].'" />'.$rowmembers['id'].'</td> <td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="'.$rowmembers['id'].'"></td></td> <td>'.$rowmembers['id'].'</td> <td>'.$rowmembers['username'].'</td> <td>'.$rowmembers['first_name'].'</td> <td>'.$rowmembers['last_name'].'</td> <td>'.$rowmembers['email'].'</td> '; if ($rowmembers['active'] == 1) {echo '<td> YES </td>';} else {echo ' <td>NO </td>';} echo ' <td><a href="memberedit.php?member='.$rowmembers['id'].'"><img src="http://icons.iconarchive.com/icons/custom-icon-design/office/256/edit-icon.png" width="15" height="15" /></a> <img src="http://icons.iconarchive.com/icons/custom-icon-design/office/256/delete-icon.png" width="15" height="15" /></td> </tr>';} ?> <tr> <td colspan="4" align="center"><input type="submit" name="submit" value="Update Selected"></td> </tr> </form> membmultiupdate.php The code bit to try to show all checked rows if (isset ($_POST['submit'])) { if (is_array ($_POST['checkbox'])) { $update = implode ("','", mysql_real_escape_string ($_POST['id'])); $members = mysql_query("SELECT * FROM users WHERE id IN (".$update.") "); } } The form to show all of the checked rows <form name="form1" method="post" action=""> <?php while ($rowmembers = mysql_fetch_array($members)) {echo ' <tr> <td width="200px" align="right" style="font-weight:bold"> <label for="name">Username:</label> </td> <td width="200px" > <input type="text" name="name" value="'.$rowmembers['username'].'" /><br> </td> </tr> <tr> <td width="200px" align="right" style="font-weight:bold"> <label for="name">First Name:</label> </td> <td width="200px" > <input type="text" name="first_name" value="'.$rowmembers['first_name'].'" /><br> </td> </tr> <tr> <td width="200px" align="right" style="font-weight:bold"> <label for="name">Last Name:</label> </td> <td width="200px" > <input type="text" name="last_name" value="'.$rowmembers['last_name'].'" /><br> </td> </tr> <tr> <td width="200px" align="right" style="font-weight:bold"> <label for="name">Email:</label> </td> <td width="200px" > <input type="text" name="email" value="'.$rowmembers['email'].'" /><br> </td> </tr>' ;} ?> <tr> <td colspan="4" align="center"><input type="submit" name="update" value="update"></td> </tr> </form> The code to update the rows from the above form and the return to memberlist.php if($update) { foreach($_POST['id'] as $id) { $sql1=" UPDATE users SET username='".$_POST["name".$id]."' , first_name='".$_POST["first_name".$id]."' , last_name='".$_POST["last_name".$id]."' , email='".$_POST["email".$id]."' , ONOFF='".$_POST["ONOFF".$id]."' WHERE id='".$id."'"; $result1=mysql_query($sql1); } } if($result1){ header("location:memberlist.php"); } Hi,
I am trying to create an admin page for a local Gym Club to allow an Administrator to be able to update club prices which then show on different screens on the site.
I have been able to display the "Prices Admin" page which basically reads a MySQL database table (pricelist), display the description, member price and non-member price and allows the user to update any of these fields.
My problem is that when I try writing the data back to the database with the "UPDATE" statement it fails, what I mean is that nothing updates. I have at the moment commented out the actual update statement and put in a "file_put_contents" command" to try and work out what is in the various fields before the UPDATE is run. I find that the display/INPUT works perfectly well but when I do a foreach on the $record array variable I am getting strange results.
I may not have explained this very well but here are the relevant sections of my code;
// Display and Input section
<div id="admin-area">
Hi Guys, <?php $host="xxx"; // Host name $username="xxx"; // Mysql username $password="xxx"; // Mysql password $db_name="xxx"; // Database name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM attendance"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <html> <head> <title>Registers</title> </head> <body> <?php include 'Navigation.php';?> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <table border="0" cellspacing="1" cellpadding="0" style="width: 1461px; height: 105px"> <tr> <td align="center"><strong>Id</strong></td> <td align="center"><strong>Last Name</strong></td> <td align="center"><strong>First Name</strong></td> <td align="center"><strong>Form</strong></td> <td align="center"><strong>Year Group </strong></td> <td align="center"><strong>Date</strong></td> <td align="center"><strong>Attendance</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"><? $Student_id[]=$rows['Student_id']; ?><? echo $rows['Student_id']; ?></td> <td align="center"><? $firstname[]=$rows['firstname']; ?><? echo $rows['firstname']; ?></td> <td align="center"><? $lastname[]=$rows['lastname']; ?><? echo $rows['lastname']; ?></td> <td align="center"><? $Form_Group[]=$rows['Form_Group']; ?><? echo $rows['Form_Group']; ?></td> <td align="center"><? $Year_Group[]=$rows['Year_Group']; ?><? echo $rows['Year_Group']; ?></td> <td align="center"><? $Att_Date[]=$rows['Att_Date']; ?><? echo $rows['Att_Date']; ?></td> <td align="center"><input name="Presence[]" type="text" id="Presence" value="<? echo $rows['Presence']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="7" align="center"><input type="submit" name="Submit" value="Submit Register"></td> </tr> </table> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE attendance SET Presence='$Presence[$i]' WHERE Student_id='$Student_id[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:Registers.php"); } mysql_close(); ?>
I have a problem with an amend to an admin system I am trying to change. The shop stocks different colours of each product and the client wants to be able to update the stock levels of all colours of one product (which all share the same title) on one form. I have tried following some instructions on some sites and tried making my own and I can get it to display the form and the values correctly, but on submission it does nothing but direct me to a page without a title value in the address (e.g. www.example.com/example/stock_level_2.php?title=). I think it may be to do with the arrays I am using, has anyone got any ideas? Here is the code. Form: Code: [Select] <?php $pd_title = str_replace("_"," ",$_REQUEST["title"]); $pd_title = str_replace("%","&#37;",$pd_title); $pd_title = str_replace("/","&#47;",$pd_title); $lookupqueryc = mysql_query("SELECT * FROM product WHERE pd_title = '".$pd_title."' ORDER BY pd_id DESC"); echo '<table><tr><th align="center" class="bodytext">Product<br />ID</th><th align="center" class="bodytext">Product Name</th><th align="center" class="bodytext">Stock Level</th></tr>'; $form = '<form name="frmAmendStock" method="post" action="stock_level_2.php?title="'; $form .= $_GET["title"]; $form .= '" enctype="multipart/form-data">'; echo $form; echo '<input name="submitted" type="hidden" value="true">'; $count=mysql_num_rows($lookupqueryc); echo '<input name="count" type="hidden" value="'; echo $count; echo '">'; while($lookupresultc = mysql_fetch_array($lookupqueryc)){ echo '<tr><td align="center" class="bodytext">'; $id[]=$lookupresultc["pd_id"]; echo $lookupresultc["pd_id"]; echo '</td><td class="bodytext">'; echo $lookupresultc["pd_title"]; if (isset($lookupresultc["pd_colour"]) && $lookupresultc["pd_colour"] !="") { echo " ("; echo $lookupresultc["pd_colour"]; echo ')'; } if ($lookupresultc["pd_stock"] <= 5) { echo '</td><td align="center" class="bodytext" style="border: 2px solid red;">'; echo '<input name="stock[]" type="text" id="stock" value="'; echo $lookupresultc["pd_stock"]; echo '"style="width: 50px;" />'; echo "</td></tr>"; }else{ echo '</td><td align="center" class="bodytext">'; echo '<input name="stock[]" type="text" id="stock" value="'; echo $lookupresultc["pd_stock"]; echo '"style="width: 50px;" />'; echo "</td></tr>"; } } ?> <tr> <td> </td> <td height="35"><a href="javascript: " onClick="javascript:document.forms.frmAmendStock.submit()" class="bodytext"><strong>click here to amend your stock </strong></a></td> </tr> </form> </table> And here is the code it should run on submission: Code: [Select] <?php if (isset($_POST["submitted"])) { for($i=0;$i<$_POST["count"];$i++){ mysql_query("UPDATE product SET pd_stock='$stock[$i]' WHERE pd_id='$id[$i]'"); } } ?> This is the form that I'm using and it populates just fine but when you make the changes I can't figure out how to get it to update each record in my database. Code: [Select] <table width="100%" cellspacing="1" cellpadding="2" border="0"> <form action="<?php echo $_SERVER["PHP_SELF"] . "?update=1"; ?>" method="post"> <tr> <td><b>Category Name</b></td> <td><b>Category Description</b></td> <td><b>Order</b></td> <td align="right"><input type="submit" value="Update"></td> </tr> <?php read_cat_list($cat); for ($i = 0; $i < $cat["count"]; $i++) { echo "<tr>\n"; echo "<td width=\"30%\" valign=\"top\"><input type=\"text\" name=\"cat_name_" . safe_string($cat[$i]["cat_id"]) . "\" size=\"30\" maxlength=\"250\" value=\"" . safe_string($cat[$i]["cat_name"]) . "\"></td>\n"; echo "<td width=\"36%\" valign=\"top\"><textarea name=\"cat_desc_" . safe_string($cat[$i]["cat_id"]) . "\" rows=\"2\" cols=\"30\">" . safe_string($cat[$i]["cat_desc"]) . "</textarea></td>\n"; echo "<td width=\"10%\" valign=\"top\"><input type=\"text\" name=\"cat_order_" . safe_string($cat[$i]["cat_id"]) . "\" size=\"3\" maxlength=\"3\" value=\"" . safe_string($cat[$i]["cat_order"]) . "\"></td>\n"; echo "<td width=\"24%\" valign=\"top\">[ <a href=\"#\" onmouseover=\"window.status = 'Delete " . safe_string($cat[$i]["cat_name"]) . "'; return true;\" onmouseout=\"window.status = ''; return true;\" onclick=\"javascript:del_cat(" . $cat[$i]["cat_id"] . ", '" . safe_string($cat[$i]["cat_name"]) . "'); return false;\">Delete</a> ]</td>\n"; echo "</tr>\n"; } ?> <tr> <td colspan="4" align="right"><input type="submit" value="Update"></td> </tr> </form> </table> the safe_string function just cleans up the output/input from the database, This next block is my form processor for this form. Code: [Select] <?php function update_cats($vars) { $err = ""; #if ($SESSION["level"] != ADMIN) { # $err = ERR_NOT_ENOUGH_ACCESS; #} else { $temp = array_keys($vars); for ($i = 0; $i < count($temp); $i++) { if (substr($temp[$i], 0, 9) == "cat_name_") { if ($vars[$temp[$i]] == "") { $err = "Category names cannot be blank."; break; } else { $name_query["cat_name"] .= substr($temp[$i], 9) . ", "; } } } for ($i = 0; $i < count($temp); $i++) { if (substr($temp[$i], 0, 9) == "cat_desc_") { $desc_query["cat_desc"] .= substr($temp[$i], 9) . ", "; } } for ($i = 0; $i < count($temp); $i++) { if (substr($temp[$i], 0, 10) == "cat_order_") { if ($vars[$temp[$i]] == "") { $err = "Category orders cannot be blank."; break; } else { $order_query["cat_order"] .= substr($temp[$i], 10) . ", "; } } } #} if (!$err) { if ($name_query["cat_name"]) { $update_name_query = "update category"; $update_name_query .= " set cat_name = '" . $name_query["cat_name"] . "'"; $update_name_query .= " where cat_id in (" . substr($name_query["cat_name"], 0, -2) . ")"; update_db($update_name_query); } if ($desc_query["cat_desc"]) { $update_desc_query = "update category"; $update_desc_query .= " set cat_desc = '" . $name_query["cat_desc"] . "'"; $update_desc_query .= " where cat_id in (" . substr($desc_query["cat_desc"], 0, -2) . ")"; update_db($update_desc_query); } if ($order_query["cat_order"]) { $update_order_query = "update category"; $update_order_query .= " set cat_order = '" . $name_query["cat_order"] . "'"; $update_order_query .= " where cat_id in (" . substr($order_query["cat_order"], 0, -2) . ")"; update_db($update_order_query); } } return $err; } ?> update_db is my database caller, if you need any of the functions that I use that are not here please post back and tell me. now when I process the form all my fields change to this: cat_name: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, cat_desc: cat_id: 0 for all the records in the database table, I'm just trying to update each record with the values it needs Here is my database table with the data. Code: [Select] CREATE TABLE `category` ( `cat_id` int(11) NOT NULL AUTO_INCREMENT, `cat_name` varchar(255) NOT NULL, `cat_desc` text NOT NULL, `cat_order` int(11) NOT NULL, PRIMARY KEY (`cat_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ; -- -- Dumping data for table `category` -- INSERT INTO `category` (`cat_id`, `cat_name`, `cat_desc`, `cat_order`) VALUES(1, 'Hand Tossed Pizza', '', 1); INSERT INTO `category` (`cat_id`, `cat_name`, `cat_desc`, `cat_order`) VALUES(2, 'Hand Tossed Specialty Pizzas', '', 2); INSERT INTO `category` (`cat_id`, `cat_name`, `cat_desc`, `cat_order`) VALUES(3, 'Chicago Style Deep Dish', '', 3); INSERT INTO `category` (`cat_id`, `cat_name`, `cat_desc`, `cat_order`) VALUES(4, 'Specialty Chicago Style Deep Dish', '', 4); INSERT INTO `category` (`cat_id`, `cat_name`, `cat_desc`, `cat_order`) VALUES(5, 'Chicken Wings & Tenderloins', '', 5); INSERT INTO `category` (`cat_id`, `cat_name`, `cat_desc`, `cat_order`) VALUES(6, 'Hot Sides', '', 6); INSERT INTO `category` (`cat_id`, `cat_name`, `cat_desc`, `cat_order`) VALUES(7, 'Hot Sandwiches', '', 7); INSERT INTO `category` (`cat_id`, `cat_name`, `cat_desc`, `cat_order`) VALUES(8, 'Cold Sandwiches', '', 8); INSERT INTO `category` (`cat_id`, `cat_name`, `cat_desc`, `cat_order`) VALUES(9, 'Pastas', '', 9); INSERT INTO `category` (`cat_id`, `cat_name`, `cat_desc`, `cat_order`) VALUES(10, 'Fresh Salads', '', 10); INSERT INTO `category` (`cat_id`, `cat_name`, `cat_desc`, `cat_order`) VALUES(11, 'Fresh Breads', '', 11); INSERT INTO `category` (`cat_id`, `cat_name`, `cat_desc`, `cat_order`) VALUES(12, 'Soups', '', 12); INSERT INTO `category` (`cat_id`, `cat_name`, `cat_desc`, `cat_order`) VALUES(13, 'Kids Menu', '', 13); INSERT INTO `category` (`cat_id`, `cat_name`, `cat_desc`, `cat_order`) VALUES(14, 'Drinks', '', 14); INSERT INTO `category` (`cat_id`, `cat_name`, `cat_desc`, `cat_order`) VALUES(15, 'Desserts', '', 15); Hope I have provided plenty of info on what I got and what I need for it todo Thanks I know how to pull data from sql table and limit down the results, what i wanted to do is pull data from a sql table 'finished' and list data that has paid='0' this is then limited to show the amount of rows set by variable 'maxPay' here is my list what im pulling atm; <h2>Payment </h2> <?php if($userType[user_type]==28){ $queryPay = mysql_query("SELECT * FROM finished WHERE paid='0'&&method!='FALSE'&&method!='credit';") or die(mysql_error()); $queryAdmin = mysql_query("SELECT maxPay FROM `admin`;") or die(mysql_error()); $row = mysql_num_rows($queryPay); //echo $row."row<br />"; $rowsArray = mysql_fetch_assoc($queryAdmin); $rows = $rowsArray[maxPay]; //echo $rows."rows<br />"; if($rows>$row){ $r=$row; } else{ $r=$rows; } $s=0; while($s<$r){ if($_POST[complete]==TRUE){ mysql_query("UPDATE `finished` SET `paid`='$_POST[paid]' WHERE `auctionID`='$_POST[aid]';"); $_POST[complete] = FALSE; } $s++; } $t=0; while($t<$r){ $queryuser = mysql_query("SELECT * FROM finished WHERE paid='0'&&method!='FALSE'&&method!='credit';") or die(mysql_error()); $user = mysql_result($queryuser, $t, "username"); //echo $user; $item = mysql_result($queryuser, $t, "itemName"); //echo $item; $value = mysql_result($queryuser, $t, "marketPrice"); //echo $value; $method = mysql_result($queryuser, $t, "method"); //echo $method; $id = mysql_result($queryuser, $t, "auctionID"); //echo $id; //echo $method; if($method=='isk'){ ?> <FORM method="post" action="pay.php"> <input type="hidden" name=complete value="TRUE" /> <input type="hidden" name=paid value="YES" /> <input type="hidden" name=username value="<? echo $user; ?>" /> <input type="hidden" name=aid value="<? echo $id; ?>" /> <input type="submit" value="Paid" /><? echo $user." won a ".$item." he selected to receive ".$value."ISK."; echo "<br />"; ?></FORM><? } elseif($method=='ship'){ ?> <FORM method="post" action="pay.php"> <input type="hidden" name=complete value="TRUE" /> <input type="hidden" name=paid value="YES" /> <input type="hidden" name=username value="<? echo $user; ?>" /> <input type="hidden" name=aid value="<? echo $id; ?>" /> <input type="submit" value="Paid" /><? echo $user." won a ".$item." he selected to receive the ship."; echo "<br />"; ?></FORM><? } else{ } $t++; } } else{ echo "You are not an Admin."; } ?> and pay.php: <?php header('Location: /admin.php'); include "connect.php"; echo $_POST[aid]; if($_POST[complete]==TRUE){ $tempID = (($_POST[aid])+1); mysql_query("UPDATE `finished` SET `paid`='$_POST[paid]' WHERE `auctionID`='$tempID';") or die(mysql_error()); $_POST[complete] = FALSE; } ?> at the moment i am listing all my data, and processing it using pay.php, each dataset has a "paid" button, i want to change this to using a checkbox at end of each data row, and a submit button at the bottom. this way i can select which rows to update and tick the checkbox, then click submit and those rows will then be updated the value '0' in db to a value of 'YES'. hope i explained myself clearly enough for some help. im a relative php noob still in training. Hello all. Please I need help to update customer table. I get the texboxes populated with select query no problem. I have html page with a search box and when the user enter their first name or last name and click search it will call up the search.php file here is the file: This code below populate the textboxes to be updated: Code: [Select] <?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("^/[A-Za-z]+/", $_POST['name'])){ $name=$_POST['name']; } } else{ echo "<p>Please enter a search query</p>"; } } //connect to the database $con = mysql_connect("localhost","dbusrn","dbpwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); $name = $_POST['name']; $result = mysql_query ("select * from Customer_Registration where Firstname like '%$name%' or lastname like '%$name%' "); $row = mysql_fetch_row($result); $cf_uid = $row[0]; $Firstname = $row[6]; $lastname = $row[7]; $Address = $row[8]; $Postcode = $row[9]; $Phone = $row[10]; $Email = $row[11]; $Customer_Type = $row[12]; $Computer_type = $row[13]; $Computer_maker = $row[14]; $Model = $row[15]; $OS = $row[16]; $Appointment_date = $row[17]; $Problem = $row[18]; $Solution = $row[19]; $Comment = $row[20]; ?> <form action="updatecus1.php" method="post"> <table width="100%" border="2" cellspacing="0" cellpadding="8"> <tr><td width="45%" class="FormText">Customer ID:</td> <td width="55%"><?php echo $cf_uid;?></td></tr> <tr><td width="45%" class="FormText">First name:</td> <td width="55%"><input name="Firstname" type="text" value="<?php echo $Firstname;?>"?> </td></tr> <tr><td width="45%" class="FormText">Last name:</td> <td width="55%"><input name="lastname" type="text" value="<?php echo $lastname;?>"?> </td></tr> <tr><td width="45%" class="FormText">Address:</td> <td width="55%"><input name="Address" type="text" value="<?php echo $Address; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Postcode:</td> <td width="55%"><input name="Postcode" type="text" value="<?php echo $Postcode; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Phone:</td> <td width="55%"><input name="Phone" type="text" value="<?php echo $Phone; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Email:</td> <td width="55%"><input name="Email" type="text" value="<?php echo $Email; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Customer:</td> <td width="55%"><input name="Customer_type" type="text" value="<?php echo $Customer_Type; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Computer :</td> <td width="55%"><input name="Computer_type" type="text" value="<?php echo $Computer_type; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Manufactural:</td> <td width="55%"><input name="Computer_maker" type="text" value="<?php echo $Computer_maker; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Model:</td> <td width="55%"><input name="Model" type="text" value="<?php echo $Model; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Operating System:</td> <td width="55%"><input name="First name" type="text" value="<?php echo $OS; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Appointment:</td> <td width="55%"><input name="Operating System" type="text" value="<?php echo $Appointment_date; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Problem:</td> <td width="55%"><textarea name="Problem" rows="10" cols="20" ><?php echo $Problem; ?></textarea></td></tr> <tr><td width="45%" class="FormText">Solution:</td> <td width="55%"><textarea name="Solution" rows="10" cols="20" ><?php echo $Solution; ?></textarea></td></tr> <tr><td width="45%" class="FormText">Comment:</td> <td width="55%"><textarea name="Comment" rows="10" cols="20" ><?php echo $Comment; ?></textarea></td></tr> <td width="55%"><input name="submit" value="submit" type="submit" <br> <input type="Submit" value="Cancel"</br></td> </form> <?php -------------------------------------------------------------------------------------- The update.php file have the following code: Code: [Select] <?php //connect to the database $con = mysql_connect("localhost","dbusrn","dbpwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); if (isset($_POST['submit'])) { $cf_uid = $_POST['cf_uid']; $Firstname = $_POST['Firstname']; $lastname = $_POST['lastname']; $Address = $_POST['Address']; $Postcode = $_POST['Postcode']; $Phone = $_POST['Phone']; $Email = $_POST['Email']; $Customer_Type = $_POST['Customer_Type']; $Computer_type = $_POST['Computer_type']; $Computer_maker = $_POST['Computer_maker']; $Model = $_POST['Model']; $OS = $_POST['OS']; $Appointment_date = $_POST['Appointment_date']; $Problem = $_POST['Problem']; $Solution = $_POST['Solution']; $Comment = $_POST['Comment']; $query = "UPDATE Customer SET Firstname='$Firstname',lastname='$lastname',Address='$Address',Postcode='$Postcode',Phone='$Phone',Email='$Email',Customer_Type='$Customer_Type',Computer_type='$Computer_type',Computer_maker='$Computer_maker',Model='$Model',OS='$OS', Appointment_date='$Appointment_date',Problem='$Problem',Solution='$Solution',Comment='$Comment' WHERE cf_uid='$cf_uid '"; mysql_query($query) or die(mysql_error()); mysql_close($con); echo "<p>Congrats Record Updated</p>"; } ?> I got congrats record updated but in actual fact no record are updated. Please help MOD EDIT: code tags added. hello guys moving on from inserting multiple records im now stuck with updating multiple records. i can get most of the details nailed but i need it to match the id's for the table the code i have in the sql part are Code: [Select] if (isset($_POST['submit'])) { //Assign each array to a variable $StaffMember = $_POST['StaffMember']; $referrer = $_POST['referrer']; $referred = $_POST['referred']; $SentOut = $_POST['SentOut']; $today = date("y.m.d H:i:s"); $user_id = $_SESSION['user_id']; $IssueNum = $_POST['Referrerid']; $limit = count($StaffMember); $values = array(); // initialize an empty array to hold the values for($k=0;$k<$limit;$k++){ $msg[] = "$limit New KPI's Added"; $values[$k] = "( '{$StaffMember[$k]}', '{$referrer[$k]}', '{$referred[$k]}', '{$SentOut[$k]}', '{$today}', '{$user_id}' )"; // build the array of values for the query string } $query = "UPDATE `Referrer` (StaffMember, referer, referred, SentOut, SentOutDate, SentOutBy) VALUES " . implode( ', ', $values ) . " WHERE IssueNum= '{$IssueNum[$k]}'"; echo $query; } i obviously want the records updating where the issuenumber is the same and if the check box in the form is ticked help with this one? I making an web app for teachers to assess their students online. The problems I am currently having are on select only one record is displayed and after update no records are displayed in the form even though it was successfully updated.. The program has two files, index.php and process.php. The problems started when got the class name into the query to search and display the class. $result = $mysqli->query("SELECT * FROM data WHERE classroom = '".$classroom."' ORDER BY '.name';") or die($mysqli->error); The query works but doesn't order by name I would like. I would be grateful if anyone could cast an eye over it and give me some tips. Thanks guys. The beers are on me if anyone can sort it, but you'll have to come to Phnom Penh, Cambodia as that is where I live. Anyway here's the code. process.php <html> <?php session_start(); $mysqli = new mysqli("localhost","ray","password","reports") or die(mysqli_error($mysqli)); $id = 0; $update = false; $name = ''; $classroom = ''; if (isset($_GET['edit'])){ $id = $_GET['edit']; $update = true; $result = $mysqli->query("SELECT * FROM data WHERE id=$id") or die($mysqli->error()); if(isset($result->num_rows) && $result->num_rows > 0) { $row = $result->fetch_array(); $name = $row['name']; $classroom = $row['classroom']; $pacomment = $row['pacomment']; } } if (isset($_POST['update'])){ $id = $_POST['id']; $pacomment = $_POST['pacomment']; $mysqli->query("UPDATE data SET pacomment= '$pacomment' WHERE id=$id") or die($mysqli->error); $_SESSION['message'] = "Record has been updated!"; $_SESSION['msg_type'] = "warning"; header('location: index.php'); } index,php <?php require_once 'process.php'; ?> <!--************************************** Setup Messages **************************************** --> <?php if (isset($_SESSION['message'])): ?> <div class="alert alert-<?=$_SESSION['msg_type']?>"> <?php echo $_SESSION['message']; unset($_SESSION['message']); ?> </div> <?php endif ?> <!--**************************************End Setup Messages *********************************************** --> <?php ?> <!DOCTYPE html> <html> <head> <title>Home of English Reports</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> <style>= body { margin: 0; font-family: Arial, Helvetica, sans-serif; } .topnav { overflow: hidden; background-color: #008080; } .topnav a { float: left; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; } .topnav a:hover { background-color: #ddd; color: black; } .topnav a.active { background-color: #4CAF50; color: white; } </style> </head> <body style="background-color:linen;"> <!--************************************** End Setup Page Styles ************************************* --> <div class="container"> <form action="index.php" method = get> <label for="classroom">Class name:</label><br> <input type="text" id="classroom" name="classroom" value="107i am"><br> <input type="submit" value="Submit"> </form> </div> <?php $resultcomment = $mysqli->query("SELECT EnglishComment FROM comments"); ?> <!-- ************************************** Begin Connect DB ************************************************ --> <div class="container" align-content-center> <?php $classroom = (isset($_GET['classroom']) ? $_GET['classroom'] : null); $result = $mysqli->query("SELECT * FROM data WHERE classroom = '".$classroom."' ORDER BY '.name';") or die($mysqli->error); ?> <!-- ************************************** End Connect DB **************************************************** --> <div class="row justify-content-center"> <form action="process.php" method="POST"> <input type="hidden" name="id" value="<?php echo $id; ?>"> <div class="form-group"> <h1><label><?php echo $name?></label></h1> </div> <form action="process.php" method="POST"> <input type="hidden" name="id" value="<?php echo $id; ?>"> <div class="form-group"> <h3><label>PA Teacher's Comment</label></h3> <select name = "pacomment"> <?php while($rows = $resultcomment-> fetch_assoc()) { $EnglishComment = $rows['EnglishComment']; echo "<option value='$EnglishComment'>$name.$EnglishComment</option>"; } ?></h2> </select><br> <p> <div class="form-group"> <?php if ($update == true): ?> <button type="submit" class="btn btn-info" name="update">Update</button> <?php else: ?> <!-- <button type="submit" class="btn btn-primary" name="save">Save</button> --> <?php endif; ?> </div> </form> <!-- ************************************** Begin Setup Table Headers ****************************************** --> <div class="row justify-content-center"> <table class="table" width = "20%" border = "5" cellpadding = "1";> <thead> <tr> <th><center>Action</center></th> <th><center>ID</center></th> <th>Name and Comment</th> </tr> </thead> <!-- ************************************** End Setup Classlist Table Headers ****************************************** --> <!-- ****** Loop thru Every Record From $result Query Variable and get variables and echo each variable into the table rows ********** --> <?php while ($row = $result->fetch_assoc()): ?> <tr> <td> <center><a href="index.php?edit=<?php echo $row['id']; ?>" class="btn btn-info">Assess</a></center> </td> <!-- ************************************** Put data into Classlist table rows ****************************************** --> <td><center><?php echo $row['studentid']; ?></center></td> <td><?php echo $row['name']." ".$row['pacomment'] ?></td> </tr> <?php endwhile; ?> <!-- ****************** End While() Loop **************************** --> </table> <!-- *************** End of Classlist Table ****************************************** --> </div> </div> </div> </body> </html>
Edited July 25, 2020 by raymon Hey, Im needing some help with an update form that I have created using PHP/MySQL. Basically the form is working great (updating records, retrieving records and showing errors) but there is a problem with the errors. If there are no errors and I edit the existing text input values, the database updates fine. However if I edit the existing text input values and there is an error, the edited input values dont save, they revert back to the values of the database. I understand why this is happening, its because the text inputs are set to show the values of the database so if i edit the existing values and an error occurs or the page is refreshed, the values revert back to the database values. However id like it so that if any text in the text field have been edited and an error occurs, the text stays to how it is until the user by passes any errors and then the database is updated. Hopefully this makes sense. I have attached the php page just incase anybody wants to look into it but any help would be much appreciated! Also, im not looking for someone to just to fix this for me but if someone knows my problem and can guide me in the right direction, that would be great. 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).... 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> I am trying to make automated scoresheets for a soccer league. The problem i am having is it is only displaying the first record and repeating. Could someone please help me out with this? Thanks in advance. Code: [Select] <?php /* connection and protection */ include 'dbc.php'; // MATCH DATA $details = mysql_query("SELECT * FROM thirdsched_south WHERE id = '1'") or die(mysql_error()); // matchs data $match = mysql_fetch_array( $details ); // HOME TEAM $hometeam = mysql_query("SELECT * FROM players WHERE teamid = 'cloverda' AND approved ='1'") or die(mysql_error()); // store home data $home = mysql_fetch_array( $hometeam ); // AWAY TEAM $awayteam = mysql_query("SELECT * FROM players WHERE teamid = 'lefcb' AND approved ='1'") or die(mysql_error()); // Store AWAY DATA $away = mysql_fetch_array( $awayteam ); ?> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" src="public_smo_scripts.js"></script> <link href="styles.css" rel="stylesheet" type="text/css"> <style type="text/css"> <!-- .style1 { font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 13px; } .style2 {font-size: 14px} .style3 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 14px; } --> </style> </head> <body onload="window.print()"> <table width="930" border="1"> <tr> <td colspan="2" class="style1 style1"><div align="center"><img src="bccsl-gmsh-hd.jpg"/></div></td> </tr> </table> <table width="930" border="1"> <tr> <td width="455" class="style1 style1"><div align="center" class="style2">Division: Third- South</div></td> <td width="459" height="32" class="style1 style1"><div align="center" class="style2">Date: <? echo $match['date']; ?> </div></td> </tr> <tr> <td class="style1 style1"><div align="center" class="style2">Time: <? echo $match['time']; ?> </div></td> <td height="36" class="style1 style1"><div align="center" class="style2">Field: <? echo $match['field']; ?> </div></td> </tr> <tr> <td class="style1 style1"><div align="center" class="style2">Home Team: <? echo $match['hometeam']; ?> </div></td> <td class="style1 style1"><div align="center" class="style2">Away Team: <? echo $match['awayteam']; ?></div></td> </tr> </table> <table width="930" border="1" cellspacing="0" cellpadding="0"> <tr> <th width="230" class="style1 style1" scope="col"><div align="center">Name</div></th> <th width="41" class="style1 style1" scope="col">#</th> <th width="41" class="style1 style1" scope="col">G</th> <th width="41" class="style1 style1" scope="col">A</th> <th width="71" class="style1 style1" scope="col">Cards</th> <th width="47" rowspan="38" class="style1 style1" scope="col"><img src="bccsl-gmsh-MD.jpg" width="47" height="657" /></th> <th width="227" class="style1 style1" scope="col"><div align="center">Name</div></th> <th width="46" class="style1 style1" scope="col">#</th> <th width="46" class="style1 style1" scope="col">G</th> <th width="43" class="style1 style1" scope="col">A</th> <th width="73" class="style1 style1" scope="col">C</th> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first'];?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td bgcolor="#666666" class="style1 style1"><div align="center"></div></td> <td bgcolor="#666666" class="style1 style1"> </td> <td bgcolor="#666666" class="style1 style1"> </td> <td bgcolor="#666666" class="style1 style1"> </td> <td bgcolor="#666666" class="style1 style1"> </td> <td bgcolor="#666666" class="style1 style1"><div align="center"></div></td> <td bgcolor="#666666" class="style1 style1"> </td> <td bgcolor="#666666" class="style1 style1"> </td> <td bgcolor="#666666" class="style1 style1"> </td> <td bgcolor="#666666" class="style1 style1"> </td> </tr> <tr> <td height="43" class="style1 style1"><div align="center" class="style2">TOTALS</div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center" class="style2">TOTALS</div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> </table> <table width="930" border="1"> <tr> <td width="447" class="style3">MANAGERS<br /> SIGNATU _______________________________</td> <td width="467" class="style1"><p class="style2">MANAGERS<br /> SIGNATU ________________________________</p></td> </tr> <tr> <td height="48" class="style1"><p class="style2">REFEREE<br /> SIGNATU _______________________________</p> </td> <td class="style1 style2">REFFEREE<br /> COMMENTS:</td> </tr> <tr> <td colspan="3" class="style1 style1"><div align="center" class="style2">Game Report is due within 24hrs. Email Report to scores@bccsl.org or fax to 604-677-5846</div></td> </tr> </table> </body> </html> 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. 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 am really not sure if this is a problem with me (probably is), php or mysql. I have a calendar that I am adding events to. If I want to edit only the date I can but only once after I make this update I am out. If I attempt to update the time or event title the database is never updated and I am no longer able to update the date. here is the controller for the save. Code: [Select] <?php function eventsave() { $details = $_POST; $this->load->model('eventsmodel'); $this->eventsmodel->eventsave($details,'', TRUE); redirect('/admin/events', 'location'); } ?> I have turned off the redirect to see if I was getting any errors and they seem to be non existent. Here is the model that is used to create a new entry and update a record. Code: [Select] <?php function eventsave($event) { $startdate = explode('-', $event['startdate']); $start = mktime($event['starthour'], $event['startmin'], 0, $startdate['0'], $startdate['1'], $startdate['2']); $end = mktime($event['endhour'], $event['endmin'], 0, $startdate['0'], $startdate['1'], $startdate['2']); $name = $event['name']; if (isset($event['id'])) { // if is true then this is an update not a new event $data = array( 'name' => $name, 'start' => $start, 'end' => $end ); $this->db->where('id', $id); $this->db->update('events', $data); }else{ $this->db->set('name', $name); $this->db->set('start', $start); $this->db->set('end', $end); $this->db->insert('events'); } } ?> I am using code igniter if that helps and the information being submitted by the form looks good. This is the submitted update array and the new event array is just missing the "id" Code: [Select] Array ( [name] => test [startdate] => 05-14-2011 [starthour] => 1 [startmin] => 0 [endhour] => 1 [endmin] => 0 [id] => 54 [saveevent] => save ) Any suggestions would be appreciated. Thank you. |