PHP - Updating Value Of Multiple Text Fields To Mysql
I have problem that only last text field is updated, how should I fix this?
Here's the code <?php if(isset($_POST["update"])){ mysql_query("UPDATE categories SET name_category = '".$_POST['category']."' WHERE ID= ".$_POST['currentCat']." ") or die(mysql_error()); mysql_query("UPDATE podkategorije SET name_subcategory = '".$_POST['subcategory']."' WHERE id_subCat= ".$_POST['currentSubCat']." ") or die(mysql_error()); } ?> <form action="" method="post" > <?php //creating texfields from db $query = "SELECT k.ID, k.name_category, pk.name_subcategory, pk.id_subCat FROM `categories` AS k JOIN `subcategories` AS pk ON pk.id_mainCat = k.ID"; $result = mysql_query($query) or die(mysql_error()); $currentCat = false; while($row = mysql_fetch_array($result)) { //so it doesn't repeat itself if($currentCat != $row['ID']) { //display of main Categories ?> <ul> <li> <br/><input name="categories" type="text" value="<?php echo $row['name_category']; ?>" /> </li> </ul> <? $currentCat = $row['ID']; } //display subcategories ?> <input name="subcategories" type="text" value="<?php echo $row['name_category']; ?>" /><br/> <input type="hidden" name="currentCat" value="<?php echo $row['ID']; ?>" /> <input type="hidden" name="currentSubCat" value="<?php echo $row['id_subCat']; ?>" /> <? } ?> <br /> <input type="button" value="Back" onClick="history.go(-1);return true;"> <input type="submit" value="Update" name="update"/> </form> Similar TutorialsI have the following PHP script to update two time/date fields in the database. When i run this the fields are not updated. Can anyone see where i m going wrong. <?php $con = mysql_connect("localhost","dbname","dbpassword"); if (!$con) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_select_db("my_db", $con); mysql_query("UPDATE msm_content SET created = '2011-01-02 00:00:00', modified = '2011-01-01 00:00:00'"); echo 'Query Updated successfully'; mysql_close($con); ?> Your guidance is much appreciated. Here goes.
I am trying to retrieve info. from mySql database and update 3 textfields.
I also have 4 selects on the form that need populating during the running of the program. My problem is using console I can see the info - Customer name - but it does not appear in the text field. The onchange request in the DIV container seems to be where it fails. Here are the files I am using:
1. add_an_order.php
<html> <head> <title>Add an Order</title> <link href = "css/style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="include/jquery-1.11.1.min.js"></script> </head> <body> <div id="header"><img src="images/logo.png" /></div> <div id="nav"> <div id="nav_wrapper"> <ul> <li><a href="index.php">Orders</a></li><li> <a href="customers.php">Customers</a></li><li> <a href="contacts.php">Contacts</a></li><li> <a href="batteries.php">Batteries</a></li><li> <a href="#">Queries</a> </li> </ul> </div> </div> <div id="main"> <?php echo '<h3 id="menOpt">Add an Order</h3><hr>'; // Check for a form submission. /* if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); $required_fields = array('customer_name', 'customer_address', 'city', 'telephone'); foreach ($required_fields as $fieldname) { if (!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) { $errors[] = strtoupper($fieldname); } } if (empty($errors)) { include ('include/dbconnect.php'); $name = mysqli_real_escape_string($con, trim(strip_tags($_POST['customer_name']))); $contact = mysqli_real_escape_string($con, trim(strip_tags($_POST['contact']))); $address = mysqli_real_escape_string($con, trim(strip_tags($_POST['customer_address']))); $city = mysqli_real_escape_string($con, trim(strip_tags($_POST['city']))); $telephone = mysqli_real_escape_string($con, trim(strip_tags($_POST['telephone']))); $telephone = preg_replace('/[^0-9]/', '', $telephone); if (isset($_POST['deepc'])) { $deepc = 1; } else { $deepc = 0; } if (isset($_POST['problemc'])) { $problemc = 1; } else { $problemc = 0; } $problem = mysqli_real_escape_string($con, trim(strip_tags($_POST['problem']))); if (isset($_POST['blacklist'])) { $blacklist = 1; } else { $blacklist = 0; } if (isset($_POST['pickup'])) { $pickup = 1; } else { $pickup = 0; } $query = "INSERT INTO customers ( customer_name, contact, customer_address, city, telephone, deep_cycle, problem_customer, problem, blacklist, pickup) VALUES ('$name', '$contact', '$address', '$city', '$telephone', $deepc, $problemc, '$problem', $blacklist, $pickup)"; $r = mysqli_query($con, $query); if (mysqli_affected_rows($con) == 1) { echo '<p class="success">Customer has been successfully added.</p>'; } else { $message = "Could not add customer."; $message .= "<br />" . mysqli_error($con); } mysqli_close($con); } else { // We have errors. $message = count($errors) . " error(s) on the form."; } } // End: if ($_SERVER['REQUEST_METHOD'] == 'POST'). */ // Leave PHP and display the form. ?> <?php if (!empty($message)) { echo '<p class="error">' . $message . '</p>'; } ?> <?php // Output list of fields that have errors. if (!empty($errors)) { echo '<p class="error">'; foreach ($errors as $error) { echo $error . '<br />'; } echo '</p>'; } ?> <div class="container"> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset> <label>Business: <span class="important"> *</span><select name="customer_name" id="customer_name" onchange="request_fill(this.value)" value="<?php if (isset($_POST['customer_name'])) echo $_POST['customer_name']; ?>" ></select></label> <label>Address: <input type="text" name="address" id="add_a" value="<?php if (isset($_POST['customer_address'])) echo $_POST['customer_address']; ?>" /></label> <label>City: <input type="text" name="city" id="city" value="<?php if (isset($_POST['city'])) echo $_POST['city']; ?>" /></label> <label>Phone: <input type="text" name="telephone" value="<?php if (isset($_POST['telephone'])) echo $_POST['telephone']; ?>" /></label> <label>Manufacturer: <span class="important"> *</span><select name="manufacturer" id="manufacturer" onchange="request_mod(this.value)" value="<?php if (isset($_POST['manufacturer'])) echo $_POST['manufacturer']; ?>" ></select></label> <label>Model: <span class="important"> *</span><select name="model" id="model" onchange="form_yr(this.value)" value="<?php if (isset($_POST['model'])) echo $_POST['model']; ?>" ></select></label> <label>Year: <span class="important"> *</span><select name="battery" id="bat_disp" value="<?php if (isset($_POST['battery'])) echo $_POST['year'] ?>" ></select></label> <label>Quantity: <span class="important"> *</span><input type="text" name="quantity" id="quantity" value="<?php if (isset($_POST['quantity'])) echo $_POST['quantity']; ?>" /></label> <label>Warranty ? <input type="checkbox" name="warranty" <?php if ($_POST['warranty']) echo " checked"; ?> /></label> <label>Exchange ? <input type="checkbox" name="exchange" <?php if ($_POST['exchange']) echo " checked"; ?> /></label> <input type="submit" name="submit" value="Add Order" /> or <a href="index.php">Cancel</a> </fieldset> </form> </div> <script type="text/javascript" src="include/functions.js"></script> <script> $(document).ready(function() { $('.container').hide(); $('.container').fadeIn(1000); request_cust(); request_man(); }); </script> <?php include ('include/footer.php'); 2. request_fill function request_fill() { var cust2 = 'customer'; var ad = document.getElementById("add_a"); var hr = new XMLHttpRequest(); hr.open("POST", "battery_parser.php", true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function() { if(hr.readyState == 4 && hr.status == 200) { var dataArray = hr.responseText; ad.innerHTML = dataArray[1]; } } hr.send("&cust2="+cust2); } 3. battery_parser.php <?php include_once("include/dbconnect.php"); if (isset($_POST['cust2'])) { $cust2 = $_POST['cust2']; $sql = "SELECT customer_address FROM customers WHERE customer_id = 2"; $query = mysqli_query($con, $sql); $dataString = ''; while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ $add = $row["customer_address"]; $dataString = $add; } mysqli_close($con); echo $dataString; exit(); } else { exit(); } ?> I am trying to update multiple rows in a mysql db through php but I am getting an error message in this line: $size = count($_POST['uid']); My db field names are uid (which autoincrements and does not need to be updated), fname, lname and email fields. Here is a link for the project I need to develophttp://users.cis.fiu.edu/~vagelis/classes/COP5725/project.htm Here is the content for the first page: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <style type="text/css"> body { margin:50px 0px; padding:0px; text-align:center; font:13px Tahoma,Geneva,sans-serif } #content { width:1000px; margin:0px auto; text-align:left; padding:15px; border:1px dashed #333; background-color:#eee; } </style> <link rel="icon" href="http://www.mysite.com/favicon.ico" type="image/vnd.microsoft.icon" /> </head> <body> <div id='content'><h3><center>Update Information</center></h3> <?php //create a connection $connection = mysql_connect("localhost","root","r2d2c3po"); //test the connection if (!$connection) { die("Database connection failed: " . mysql_error()); } //select database to use mysql_select_db("music_social_network", $connection); //setup query $sql = "SELECT * FROM `user` ORDER BY uid"; //get results from query or die $result = mysql_query($sql, $connection) or die(mysql_error()); //fetch rows from query $rows = mysql_fetch_assoc($result); ?> <?php // find out how many records there are to update $size = count($_POST['uid']); // start a counter in order to number the input fields for each record $i = 0; print "<table width='100%' border='0' cellspacing='1' cellpadding='0'><tr><td>"; // open a form print "<form name='namestoupdate' method='post' action='update.php'> <table width='100%' border='0' cellspacing='1' cellpadding='1'><tr> <td align='center'><strong>User ID</strong></td> <td align='center'><strong>First Name</strong></td> <td align='center'><strong>Last Name</strong></td> <td align='center'><strong>Email</strong></td> </tr>\n"; // start a loop to print all of the users with their information // the mysql_fetch_array function puts each record into an array. each time it is called, it moves the array counter up until there are no more records left while ($Update = mysql_fetch_array($result)) { print "</tr>\n"; // assuming you have three important columns (the index (id), the course name (course), and the book info (bookinfo)) // start displaying the info; the most important part is to make the name an array (notice bookinfo[$i]) print "<td align='center'><p>{$Update['uid']}</p></td>\n"; print "<td align='center'><input type='text' fname='fname[$i]' value='{$Update['fname']}' /></td>"; print "<td align='center'><input type='text' size='40' lname='lname[$i]' value='{$Update['lname']}' /></td>\n"; print "<td align='center'><input type='text' size='40' email='email[$i]' value='{$Update['email']}' /></td>\n"; print "</tr>\n"; // add 1 to the count, close the loop, close the form, and the mysql connection ++$i; } print "<tr> <td colspan='4' align='center'><input type='submit' value='submit' />"; print "</td> </tr> </table> </td> </tr> </form> </table>"; mysql_close($connection); ?><br /><br /><div></body> </html> here is the content for the update.php page: <!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> <style type="text/css"> body { margin:50px 0px; padding:0px; text-align:center; font:13px Tahoma,Geneva,sans-serif } #content { width:1000px; margin:0px auto; text-align:left; padding:15px; border:1px dashed #333; background-color:#eee; } </style> <link rel="icon" href="http://www.mysite.com/favicon.ico" type="image/vnd.microsoft.icon" /> </head> <body> <div id='content'><h3><center>Success! </center></h3> <table width='100%' border='0' cellspacing='1' cellpadding='0'><tr><td> <table width='100%' border='0' cellspacing='1' cellpadding='1'> <tr> <td align='center'><strong>User ID</strong></td> <td align='center'><strong>First Name</strong></td> <td align='center'><strong>Last Name</strong></td> <td align='center'><strong>Email</strong></td> </tr> <?php //create a connection $connection = mysql_connect("localhost","root","r2d2c3po"); //test the connection if (!$connection) { die("Database connection failed: " . mysql_error()); } //select database to use mysql_select_db("music_social_network", $connection); //setup query $sql = "SELECT * FROM `user` ORDER BY uid"; //get results from query or die $result = mysql_query($sql, $connection) or die(mysql_error()); //fetch rows from query $rows = mysql_fetch_assoc($result); // find out how many records there are to update $size = count($_POST['uid']); // start a loop in order to update each record $i = 0; while ($i < $size) { // define each variable $uid = $_POST['uid'][$i]; $fname = $_POST['fname'][$i]; $lname = $_POST['lname'][$i]; $email = $_POST['email'][$i]; // do the update and print out some info just to provide some visual feedback $query = "UPDATE `user` SET `fname` = '$fname', `lname` = '$lname', `email` = '$email' WHERE `uid` = '$uid' "; mysql_query($sql) or die ("Error in query: $query"); print " </tr> <td align='left'><p>$uid</p></td> <td align='left'>$fname</td> <td align='left'>$fname</td> <td align='left'>$lname</td> </tr> "; ++$i; } mysql_close($connection); ?> <tr> <td colspan='4' align='center'> </td> </tr> </table> </td> </tr> </table></div></body></html> Mod edit: [code] . . . [/code] tags added. Apologies... I'm a noob trying to reverse engineer code. I have a script that can retrieve values from a MySQL database (based on a session login that recognizes which user you are) and places those values into the text fields of a form, pre-populating the form. Code: [Select] <?php mysql_connect('localhost', 'db', 'password'); mysql_select_db('users'); $id = mysql_real_escape_string($_SESSION['userid']); $select = "SELECT * FROM user_info WHERE md5(Member_No) = '$id';"; $query = mysql_query($select); if ($row = mysql_fetch_array($query)) { ?> <form> FIRST name: <input type="text" name="First" value="<?php echo stripslashes($row['First']); ?>" LAST name: <input type="text" name="Last" value="<?php echo stripslashes($row['Last']); ?>" > Birthday: <input type="text" name="Birthday" value="<?php echo stripslashes($row['Birthday']); ?>" <input type="submit" value="Submit"> </form> <?php } ?> I want to be able to connect to that same database and update ALL the values (3 in the example above) with the single click of the form button. I think I was told some time ago that it's not possible to update all the values at once? Thanks, ~Wayne hello friend, I use these code for update my database with radio button checked or unchecked through array but my code could not update the server data please help me ::: my code is ::: <?php //include configuration file for connection include_once('config.php'); $sql = "select * from ATTENDANCE"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <form name="form1" method="post" action="<? echo $_SERVER['REQUEST_URI']; ?>"> <table style="text-align: left; padding: 5px;" cellpadding="0px" cellspacing="0px"> <tbody> <tr> <th style="text-align: center; padding: 5px; border: 1px #000000 solid;">Student ID</th> <th style="text-align: center; padding: 5px; border: 1px #000000 solid;">Student Name</th> <th style="text-align: center; padding: 5px; border: 1px #000000 solid;">Student Present</th> <th style="text-align: center; padding: 5px; border: 1px #000000 solid;">Student Absent</th> <th style="text-align: center; padding: 5px; border: 1px #000000 solid;">Comment</th> </tr> <?php while($rows=mysql_fetch_array($result)) { ?> <tr> <td class="table1"> <? $id[] = $rows['STUDENT_ID']; ?><? echo $rows['STUDENT_ID']; ?> </td> <td class="table1"> <? echo $rows['STUDENT_NAME']; ?> </td> <td id="present"> <input type="radio" name="present<? echo $rows['STUDENT_ID']; ?>" checked="checked" value="PRESENT">Present </td> <td id="absent"> <input type="radio" name="present<? echo $rows['STUDENT_ID']; ?>" value="ABSENT">Absent </td> <td style="text-align: left; padding: 5px; border: 1px #000000 solid; height: 33px;"> <? echo $rows['COMMENT']; ?> </td> </tr> <?php }?> <tr> <td colspan="5" style="vertical-align:middle; text-align: center;"><br><br> <input id="Submit" type="submit" name="Submit" value="Submit" style="text-align: center; background-color: #000000; color: #ffffff; border: 1px #000000 solid;"> </td> </tr> </tbody> </table> </form> <?php if($_POST['$Submit']) { foreach($_POST['STUDENT_ID'] as $id) { $sql = "UPDATE ATTENDANCE SET STUDENT_PRESENT = '".$_POST["present".$id]."' WHERE STUDENT_ID = '".$id."' "; $result = mysql_query($sql); } } if($result) { print_r ($_POST); header("location:report.php"); } else { echo "Your entry is not completed at this time............."; } ?> hi, i'm new to php. i've got a problem. I've 3 tables and table has following content table 1 id name email address phone execution_date executor_name web_address table 2 id name email address phone execution_date executor_name project_title table 3 id name email address phone execution_date executor_name reviewer I want to export these table to and spreadsheet (.xls) with some criteria a form will assign which data will published at the spreadsheet with these criteria #all data can be exported from three tables #some column can be selected from three tables #some or all data can be selected from individual table i've implement a script for this but it didn't meet my requirements. Can anyone help? here is my script <?php $DB_Server = "localhost"; //your MySQL Server $DB_Username = "root"; //your MySQL User Name $DB_Password = "pass"; //your MySQL Password $DB_DBName = "mydb"; //your MySQL Database Name $search_from_date = $_POST['start_date']; $search_to_date = $_POST['end_date']; $Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno()); $Db = @mysql_select_db($DB_DBName, $Connect) or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno()); $now_date = date('m-d-Y H:i'); if(($_POST['typer_of_report'] == 'rrc_report') || ($_POST['typer_of_report'] == 'all_report')) { $DB_TBLName = 'rrc_record'; } if(($_POST['typer_of_report'] == 'erc_report') || ($_POST['typer_of_report'] == 'all_report')) { $DB_TBLName2 = 'erc_record'; } if(($_POST['typer_of_report'] == 'aeec_report') || ($_POST['typer_of_report'] == 'all_report')) { $DB_TBLName3 = 'aeec_record'; } $file_type = "vnd.ms-excel"; $file_ending = "xls"; //} header("Content-Type: application/$file_type"); header("Content-Disposition: attachment; filename=protocol_report.$file_ending"); header("Pragma: no-cache"); header("Expires: 0"); if($DB_TBLName) { $sql = "Select * from ".$DB_TBLName." where execution_date >= '".$search_from_date."' and execution_date <= '".$search_to_date."' order by execution_date desc"; $Use_Title = 1; $title = "Report for $DB_TBLName on $now_date"; $result = @mysql_query($sql,$Connect) or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno()); if ($Use_Title == 1) { echo("$title\n"); } $sep = "\t"; //tabbed character for ($i = 0; $i < mysql_num_fields($result); $i++) { echo mysql_field_name($result,$i) . "\t"; } print("\n"); while($row = mysql_fetch_row($result)) { $schema_insert = ""; for($j=0; $j<mysql_num_fields($result);$j++) { if(!isset($row[$j])) $schema_insert .= "NULL".$sep; elseif ($row[$j] != "") $schema_insert .= "$row[$j]".$sep; else $schema_insert .= "".$sep; } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; } //} echo "\n...\n"; } if($DB_TBLName2) { $sql = "Select * from ".$DB_TBLName2." where execution_date >= '".$search_from_date."' and execution_date <= '".$search_to_date."' order by execution_date desc"; $result = @mysql_query($sql,$Connect) or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno()); $Use_Title = 1; $title = "Report for $DB_TBLName2 on $now_date"; if ($Use_Title == 1) { echo("$title\n"); } $sep = "\t"; //tabbed character for ($i = 0; $i < mysql_num_fields($result); $i++) { echo mysql_field_name($result,$i) . "\t"; } print("\n"); while($row = mysql_fetch_row($result)) { $schema_insert = ""; for($j=0; $j<mysql_num_fields($result);$j++) { if(!isset($row[$j])) $schema_insert .= "NULL".$sep; elseif ($row[$j] != "") $schema_insert .= "$row[$j]".$sep; else $schema_insert .= "".$sep; } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; } echo "\n...\n"; } if($DB_TBLName3) { $sql = "Select * from ".$DB_TBLName3." where execution_date >= '".$search_from_date."' and execution_date <= '".$search_to_date."' order by execution_date desc"; $result = @mysql_query($sql,$Connect) or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno()); $Use_Title = 1; $title = "Report for $DB_TBLName3 on $now_date"; if ($Use_Title == 1) { echo("$title\n"); } $sep = "\t"; //tabbed character for ($i = 0; $i < mysql_num_fields($result); $i++) { echo mysql_field_name($result,$i) . "\t"; } print("\n"); while($row = mysql_fetch_row($result)) { $schema_insert = ""; for($j=0; $j<mysql_num_fields($result);$j++) { if(!isset($row[$j])) $schema_insert .= "NULL".$sep; elseif ($row[$j] != "") $schema_insert .= "$row[$j]".$sep; else $schema_insert .= "".$sep; } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; } } ?> have anyone any idea? I want to have a search product feature, but I would like members to be able to search multiple fields in one go i.e. product_code, Product_name in one MySQL query. The thing is, members have to be logged on, so the query must also only show results relating to that specific member, via the session[member_ID], my current query for listing products for that specific member is : Code: [Select] $sql = "SELECT productId, productCode, image, name, price, stock_level FROM product_inventory WHERE memberr_ID = '" . $_SESSION['SESS_mem_ID'] . "; How would I change the above into a search query to search for productcode, productname and still only show results beloging to this member using the session data ? all help appreciated I have a page where "Events" which may be of interest to site visitors can be recorded. Among other info, an "Event" has a "from" date and a "to" date (to show that an event will run from October 29th to October 31st, for example). All event info is being written to the db, but the "from" and "to" dates are not. (In the db, "0000-00-00 00:00:00" is being entered in the "from" and "to" columns.) In the Events table, both event_date and event_end_date are of type datetime. Dates are entered into the form fields via a javascript datepicker and are in the format "24/09/2011". I'm using this code: Code: [Select] // Check for a Start Date: if (empty($_POST['from'])) { $errors[] = 'You forgot to enter a Start Date for the event.'; } else { $from = $_POST['from']; } // Check for an End Date: if (empty($_POST['to'])) { $errors[] = 'You forgot to enter an End Date for the event.'; } else { $to = $_POST['to']; } The db query is this: Code: [Select] if (empty($errors)) { // If everything's OK. // Insert the Event info in the database... // Make the query: $q = "INSERT INTO events (title, event_date, event_end_date, venue, ext_link, blurb) VALUES ('$title', '$from', '$to', '$venue', '$ext_link', '$blurb') "; $r = @mysqli_query ($dbc, $q); // Run the query. if ($r) { // If it ran OK. // Print a message: echo "<h2>Event info added!</h2> <h3>Your entry is now visible on the <a href='index.php'>Home Page</a>.</h3> <p><a href='logout.php'><strong>Log out</strong></a></p> " ; mysqli_close($dbc); include('inc/footer.php'); exit(); And the form is this: Code: [Select] <form id="form1" name="form1" method="post" action="add_event.php"> <label for="title">Title</label> <input type="text" name="title" id="title" value="<?php if (isset($_POST['title'])) echo $_POST['title']; ?>" /> <script> $(function() { var dates = $( "#from, #to" ).datepicker({ defaultDate: "", changeMonth: true, numberOfMonths: 1, onSelect: function( selectedDate ) { var option = this.id == "from" ? "minDate" : "maxDate", instance = $( this ).data( "datepicker" ), date = $.datepicker.parseDate( instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings ); dates.not( this ).datepicker( "option", option, date ); } }); }); </script> <label for="from" >*From</label> <input type="text" name="from" id="from" value="<?php if (isset($_POST['from'])) echo $_POST['from']; ?>" /> <label for="to" ">*To</label> <input type="text" name="to" id="to" value="<?php if (isset($_POST['to'])) echo $_POST['to']; ?>" /> <label for="venue">*Venue</label> <input type="text" name="venue" id="venue" value="<?php if (isset($_POST['venue'])) echo $_POST['venue']; ?>" /> <label for="blurb">*Description</label> <textarea name="blurb" id="blurb" value="<?php if (isset($_POST['blurb'])) echo $_POST['blurb']; ?>" rows="5" ></textarea> <label for="ext_link">External link (optional, entered like "www.example.com")</label> <input type="text" name="ext_link" id="ext_link" value="<?php if (isset($_POST['ext_link'])) echo $_POST['ext_link']; ?>" /> <input type="submit" name="submit" value="Insert Event Info" class="submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> Can anyone tell me why the dates aren't being recorded? Any help will be greatly appreciated. when i submit it, the only field that updates is the email field. UserEdit.php file <? /** * UserEdit.php * * This page is for users to edit their account information * such as their password, email address, etc. Their * usernames can not be edited. When changing their * password, they must first confirm their current password. * */ include("include/session.php"); ?> <html> <title>Edit Your Details</title> <link rel="stylesheet" type="text/css" href="../assets/css/styles.css" /> <link rel="stylesheet" type="text/css" href="../assets/css/forms.css" /> <link rel="stylesheet" type="text/css" href="../assets/css/layout.css" /> <link rel="stylesheet" type="text/css" href="../assets/css/style.css" /> <style> #form6 input{ margin:0; width:250px; border:1px solid #ddd; padding:3px 5px 3px 25px; } input{ font:100% Trebuchet MS, Arial, Helvetica, Sans-Serif; line-height:160%; color:#FFF; } #form6 input{background:#000; } </style> <body> <? /** * User has submitted form without errors and user's * account has been edited successfully. */ if(isset($_SESSION['useredit'])){ unset($_SESSION['useredit']); echo "<h1>User Account Edit Success!</h1>"; echo "<p><b>$session->username</b>, your account has been successfully updated. " ."<a href=\"index.php\">Main</a>.</p>"; } else{ ?> <? /** * If user is not logged in, then do not display anything. * If user is logged in, then display the form to edit * account information, with the current email address * already in the field. */ if($session->logged_in){ ?> <h2>User Account Edit : <? echo $session->firstname; ?></h2> <? if($form->num_errors > 0){ echo "<td><font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font></td>"; } ?> <form id="form6" action="process.php" method="POST"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr> <td>Email:</td> <td><input type="text" name="email" maxlength="50" value=" <? if($form->value("email") == ""){ echo $session->userinfo['email']; }else{ echo $form->value("email"); } ?>"> </td> <td><? echo $form->error("email"); ?></td> </tr> <tr> <td>Phone:</td> <td><input type="text" name="tel" maxlength="50" value=" <? if($form->value("tel") == ""){ echo $session->userinfo['tel']; }else{ echo $form->value("tel"); } ?>"> </td> <td><? echo $form->error("tel"); ?></td> </tr> <tr> <td>Address:</td> <td> <input type="text" name="address" maxlength="50" value=" <? if($form->value("address") == ""){ echo $session->userinfo['address']; }else{ echo $form->value("address"); } ?>" style="height: 138px"> </td> <td><? echo $form->error("address"); ?></td> </tr> <tr> <td>Company:</td> <td><input type="text" name="company" maxlength="50" value=" <? if($form->value("company") == ""){ echo $session->userinfo['company']; }else{ echo $form->value("company"); } ?>"> </td> <td><? echo $form->error("company"); ?></td> </tr> <tr><td colspan="2" align="right"> <input type="hidden" name="subedit" value="1"> <input type="submit" value="Edit Account"></td></tr> <tr><td colspan="2" align="left"></td></tr> </table> </form> <? } } ?> </body> </html> sends to session.php /** * editAccount - Attempts to edit the user's account information * including the password, which it first makes sure is correct * if entered, if so and the new password is in the right * format, the change is made. All other fields are changed * automatically. */ function editAccount($subcurpass, $subnewpass, $subemail, $subtel, $subaddress, $subcompany){ global $database, $form; //The database and form object /* New password entered */ if($subnewpass){ /* Current Password error checking */ $field = "curpass"; //Use field name for current password if(!$subcurpass){ $form->setError($field, "* Current Password not entered"); } else{ /* Check if password too short or is not alphanumeric */ $subcurpass = stripslashes($subcurpass); if(strlen($subcurpass) < 4 || !eregi("^([0-9a-z])+$", ($subcurpass = trim($subcurpass)))){ $form->setError($field, "* Current Password incorrect"); } /* Password entered is incorrect */ if($database->confirmUserPass($this->username,md5($subcurpass)) != 0){ $form->setError($field, "* Current Password incorrect"); } } /* New Password error checking */ $field = "newpass"; //Use field name for new password /* Spruce up password and check length*/ $subpass = stripslashes($subnewpass); if(strlen($subnewpass) < 4){ $form->setError($field, "* New Password too short"); } /* Check if password is not alphanumeric */ else if(!eregi("^([0-9a-z])+$", ($subnewpass = trim($subnewpass)))){ $form->setError($field, "* New Password not alphanumeric"); } } /* Change password attempted */ else if($subcurpass){ /* New Password error reporting */ $field = "newpass"; //Use field name for new password $form->setError($field, "* New Password not entered"); } /* Email error checking */ $field = "email"; //Use field name for email if($subemail && strlen($subemail = trim($subemail)) > 0){ /* Check if valid email address */ $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*" ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*" ."\.([a-z]{2,}){1}$"; if(!eregi($regex,$subemail)){ $form->setError($field, "* Email invalid"); } $subemail = stripslashes($subemail); } /* Errors exist, have user correct them */ if($form->num_errors > 0){ return false; //Errors with form } /* Update password since there were no errors */ if($subcurpass && $subnewpass){ $database->updateUserField($this->username,"password",md5($subnewpass)); } /* Change Email */ if($subemail){ $database->updateUserField($this->username,"email",$subemail); } /* Change Email */ if($subtel){ $database->updateUserField($this->username,"tel",$subtel); } /* Change Email */ if($subaddress){ $database->updateUserField($this->username,"address",$subaddress); } /* Change Email */ if($subcompany){ $database->updateUserField($this->username,"company",$subcompany); } /* Success! */ return true; } sends to database.php /** * updateUserField - Updates a field, specified by the field * parameter, in the user's row of the database. */ function updateUserField($username, $field, $value){ $q = "UPDATE ".TBL_USERS." SET ".$field." = '$value' WHERE username = '$username'"; return mysql_query($q, $this->connection); } think thats all you should need? First, Happy X-Mas to all! I want to do a form for entering dog-show results. On first site of form the user is able to enter how many dogs for each class (there are youth and open class for example) he want to insert. So on second site there will be formfields for every dog in every class, created with php. User should be able to take dogname from jquery autocomplete - this works for multiple fields. But i need the according id to the dogname - and actual only one id is given - the first one is changing by choosing from autocomplete in next fields... Data came from a json array like 0: {dogidindatabase: "9892", value: "Excalibur Khali des Gardiens de la Cour ",…} dogidindatabase: "9892" label: "<img src='../main/img/female.png' height='20'>Excalibur Khali des Gardiens de la Cour " value: "Excalibur Khali des Gardiens de la Cour " 1: {dogidindatabase: "15942", value: "Excalibur from Bandit's World Kalli",…} dogidindatabase: "15942" label: "<img src='../main/img/male.png' height='20'>Excalibur from Bandit's World Kalli" value: "Excalibur from Bandit's World Kalli"all i need is inside ... the script in form is <script type='text/javascript'> //<![CDATA[ $(function() { $(".dog").autocomplete({ source: "xxx.php", minLength: 3, select: function(event, ui) { $('#dogidindatabase').val(ui.item.dogidindatabase); } }); $["ui"]["autocomplete"].prototype["_renderItem"] = function( ul, item) { return $( "<li></li>" ) .data( "item.autocomplete", item ) .append( $( "<a></a>" ).html( item.label ) ) .appendTo( ul ); }; }); //]]> </script>and the form looked like <input type='text' name='dog' class='dog' value='".strip_tags(${'dogname' .($countbabymale+1)})."' size='35' data-required='true' /><br> <input class='readonly' readonly='readonly' type='text' id='dogidindatabase' name='dogidindatabase' size='5' />I changed in script and form id='dogidindatabase' to class, but it doesn´t work. Testsite is under http://www.wolfdog-d...how.php?lang=de (only german at first) - Insert a number (higher than 1) under baby 3-6 (first box, the others are not working for testing); submit to get to page 2; you see all post-variables (for testing). Try to insert a dogname in first input-field (choose "exc") and insert first one - the id is under dogname. In second dogname inputfield you can choose second dog - the id for the first one changes to id of seond one .... How can i get both for every dog? 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"> 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]'"); } } ?> Hi All, Can't get this code working. the statement works fine directly on the table, just not when executed from the PHP file: Code: [Select] <strong>Multi Update</strong><br> <?php $host="localhost"; // Host name $username="user_name"; // Mysql username $password="Password"; // Mysql password $db_name="dbname"; // Database name $tbl_name="tablename"; // Table 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 mik1vm_product.product_id, mik1vm_product.product_sku, mik1vm_product.product_name, mik1vm_product.product_in_stock, mik1vm_product.product_in_stock_cardiff FROM $tbl_name"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Product Id</strong></td> <td align="center"><strong>SKU</strong></td> <td align="center"><strong>Name</strong></td> <td align="center"><strong>In Stock</strong></td> <td align="center"><strong>In Stock Cardiff</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"><? $product_id[]=$rows['product_id']; ?><? echo $rows['product_id']; ?></td> <td align="center"><input name="product_sku[]" type="text" id="product_sku" value="<? echo $rows['product_sku']; ?>"></td> <td align="center"><input name="product_name[]" type="text" id="product_name" value="<? echo $rows['product_name']; ?>"></td> <td align="center"><input name="product_in_stock[]" type="text" id="product_in_stock" value="<? echo $rows['product_in_stock']; ?>"></td> <td align="center"><input name="product_in_stock_cardiff[]" type="text" id="product_in_stock_cardiff" value="<? echo $rows['product_in_stock_cardiff']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE $tbl_name SET product_sku='$product_sku[$i]', product_name='$product_name[$i]', product_in_stock='$product_in_stock[$i]' , product_in_stock_cardiff='$product_in_stock_cardiff[$i]' WHERE product_id='$product_id[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:test.php"); } mysql_close(); ?> The page loads fine, but just doesn't update the DB. Thanks in advance for any help.
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(); ?>
Hi, I have a row called code in mysql data base now what I want to do is something like this $rand=rand(1111,9999); $code=mysql_query("UPDATE member SET code='$rand' WHERE clan_id='1'"); At the moment its updating the code row with the same random number. What I want to achieve is a unique number for each member. For instance Currently if the $rand=1289 lets suppose Every code row will become 1289 I want the code rows to be different to each other. I tried a few things up my sleeve but no luck. How can i do this? thanks any help much appreciated. 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? 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 Hi, I've created an admin page that lists all piano sheet music that has been uploaded to my server. It displays the ID (autoincrement), Userid (user that uploaded sheet), Artist (name of the band) and Title (name of the song). On this page, I can either delete the row completely, or click on "Uploaded", which just sets it's uploaded column to 'yes'. Now I'm working on a button called "Uploaded All". This will set the uploaded column on all of the rows on the page to 'yes'. This way I don't have to click Uploaded for every single row. (view attached image if you are unsure what I am talking about) I'm not getting any errors when clicking "Uploaded All". When clicking it, it doesn't update the table rows in the database as it should. Take a look at my code: Tip: The area of the code that I'm currently having troubles with is here $usersids[$i] = $row['id']; $i++; } echo " <tr> <td align='center' width='10' colspan='6'><a href='uploadedsheets.php?confirm=all'>Uploaded All</a></td> </tr>"; if ($confirm=="all") { $i = 0; while($row = mysql_fetch_array($result)) { mysql_query('UPDATE `upload` SET `uploaded`="yes" WHERE id = ' . $usersids[$i]); $i++; } echo "<SCRIPT language='JavaScript'><!-- window.location='uploadedsheets.php';//--> </SCRIPT>"; } Inside the above code after the if statement, I tried echoing out $usersids, and it showed correctly. So the problem must be in the update query or the array. Full Code: <?php session_start(); include_once('../inc/connect.php'); include_once('../inc/admin.php'); if(!isset($_SESSION['sort_counter'])) {$_SESSION['sort_counter'] = 1;} if(($_SESSION['sort_counter']%2) == 0){ //test even value $sortcount = "DESC"; }else{ //odd value $sortcount = ""; } $result = mysql_query("SELECT * FROM upload WHERE uploaded='no' ORDER BY id"); $unconfirmedquery = mysql_query("SELECT uploaded FROM upload WHERE uploaded='no'"); $unconfirmedcount = mysql_num_rows($unconfirmedquery); $confirmedquery = mysql_query("SELECT uploaded FROM upload WHERE uploaded='yes'"); $confirmedcount = mysql_num_rows($confirmedquery); $sort = $_GET['sort']; $delete = $_GET['delete']; $confirm = $_GET['confirm']; ///////////////////////////////// if ($sort=='id'){ // $result = mysql_query("SELECT * FROM users ORDER BY id"); $result = mysql_query("SELECT * FROM upload WHERE uploaded='no' ORDER BY id $sortcount"); $_SESSION['sort_counter'] = $_SESSION['sort_counter'] + 1; //increment after every run } if ($sort=='userid'){ // $result = mysql_query("SELECT * FROM users ORDER BY username"); $result = mysql_query("SELECT * FROM upload WHERE uploaded='no' ORDER BY userid $sortcount"); $_SESSION['sort_counter'] = $_SESSION['sort_counter'] + 1; //increment after every run } if ($sort=='artist'){ // $result = mysql_query("SELECT * FROM users ORDER BY email"); $result = mysql_query("SELECT * FROM upload WHERE uploaded='no' ORDER BY artist $sortcount"); $_SESSION['sort_counter'] = $_SESSION['sort_counter'] + 1; //increment after every run } if ($sort=='title'){ // $result = mysql_query("SELECT * FROM users ORDER BY email"); $result = mysql_query("SELECT * FROM upload WHERE uploaded='no' ORDER BY title $sortcount"); $_SESSION['sort_counter'] = $_SESSION['sort_counter'] + 1; //increment after every run } if ($sort=='file'){ // $result = mysql_query("SELECT * FROM users ORDER BY email"); $result = mysql_query("SELECT * FROM upload WHERE uploaded='no' ORDER BY file $sortcount"); $_SESSION['sort_counter'] = $_SESSION['sort_counter'] + 1; //increment after every run } /// FIX THIS AREA if ($confirm=="true" && isset($_GET['id'])) { mysql_query('UPDATE `upload` SET `uploaded`="yes" WHERE id = ' . (int)$_GET['id']); echo "<SCRIPT language='JavaScript'><!-- window.location='uploadedsheets.php';//--> </SCRIPT>"; } if ($delete=="true" && isset($_GET['id'])) { mysql_query('DELETE FROM `upload` WHERE id = ' . (int)$_GET['id']); echo "<SCRIPT language='JavaScript'><!-- window.location='uploadedsheets.php';//--> </SCRIPT>"; } if ($delete=="false" && isset($_GET['id'])) { echo "<SCRIPT language='JavaScript'><!-- window.location='uploadedsheets.php';//--> </SCRIPT>"; } ///////////////////////////////// echo " <html> <head> <title>Uploaded Sheets</title> <style> a:link{ text-decoration: none; color: #519904; } a:visited{ text-decoration: none; color: #519904; } a:hover{ text-decoration: none; color: #4296ce; } #headcont{ width: 900px; height: 20px; margin-left: auto; margin-right: auto; } #unconfirmed{ width: 450px; text-align: center; float: left; background-color: #cccccc; } #confirmed{ width: 450px; text-align: center; float: left; background-color: #72A4D2; } </style> </head> <body> "; include_once('../inc/navadmin.php'); echo "<div style='font-size: 28px; text-align: center;'>Uploaded Sheets</div> <div id='headcont'> <div id='unconfirmed'>Not Uploaded Sheets: ".$unconfirmedcount."</div> <div id='confirmed'>Uploaded Sheets: ".$confirmedcount."</div> </div><br /> <table border='1' align='center'> <tr> <th bgcolor='#cccccc'><a href='uploadedsheets.php?sort=id'>ID</a></th> <th bgcolor='#cccccc'><a href='uploadedsheets.php?sort=userid'>UserID</a></th> <th bgcolor='#cccccc'><a href='uploadedsheets.php?sort=artist'>Artist</a></th> <th bgcolor='#cccccc'><a href='uploadedsheets.php?sort=title'>Title</a></th> <th bgcolor='#cccccc'><a href='uploadedsheets.php'>Uploaded</a></th> <th bgcolor='#cccccc'><a href='uploadedsheets.php'>Delete</a></th> </tr>"; echo "<script type='text/javascript'> function show_delete() { var r=confirm('Delete?'); if (r==true) { // Delete return true; } else { // Don't Delete return false; } } "; echo " function show_undelete() { var r=confirm('Undelete?'); if (r==true) { // Undelete return true; } else { // Don't Undelete return false; } } </script>"; $usersids = ""; $i = 0; while($row = mysql_fetch_array($result)) { // $active = $row['active']; $color = "#ffffff"; $deleted = "Delete"; if ($active=='no'){ $color = "#f43636"; $deleted = "Undelete"; $active = "false"; $alert = "show_undelete"; } else{ $active = "true"; $alert = "show_delete"; } // echo "<tr>"; echo "<td align='center' width='40' bgcolor='$color'>" .$row['id']. "</td>"; echo "<td align='center' width='40'>" .$row['userid']. "</td>"; echo "<td align='center' width='230'>".ucwords($row['artist'])."</td>"; echo "<td align='center' width='230'>".ucwords($row['title'])."</td>"; echo "<td align='center' width='10'><a href='uploadedsheets.php?confirm=true&id=" .$row['id'] . "'>Uploaded</a></td>"; echo "<td align='center' width='10'><a href='uploadedsheets.php?delete=$active&id=" .$row['id']. "' onclick='return $alert()'>$deleted</a></td>"; echo "</tr>"; $usersids[$i] = $row['id']; $i++; } echo " $usersids[0] <tr> <td align='center' width='10' colspan='6'><a href='uploadedsheets.php?confirm=all'>Uploaded All</a></td> </tr>"; if ($confirm=="all") { $i = 0; while($row = mysql_fetch_array($result)) { mysql_query('UPDATE `upload` SET `uploaded`="yes" WHERE id = ' . $usersids[$i]); $i++; } echo "<SCRIPT language='JavaScript'><!-- window.location='uploadedsheets.php';//--> </SCRIPT>"; } echo "</table>"; // Footer echo " </body> </html> "; ?> As I am new to all this php, I need some help and/or ideas on how to code this little idea of mine: I have a database with a members table, I would like to create some Teams, and so I want too create a new table with the info for these teams. My problem is to set what team a member belongs too. My idea short Add a new column in the members area to hold the Id of the team this member belongs too. So if member 1000 sends a "join team link" too member 2000 the script needs to get the team id from member 1000 and add this id to member 2000. select teamid from members where id=1000 update teamid='same id as member 1000' where id='membersid' I hope this all makes sense, cause I am having a hard time trying to explain it. 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. |