Comparing PHP Array From Checkbox To MySQL Table
My problem involves updating a MySQL table using checkbox input. I'm relatively new to both PHP and MySQL so I'm looking for a little direction on the smartest way to accomplish my goal.
When a user goes to a project page, they are able to categorize their project by area. The user checks a series of checkboxes and the results are stored in an arrays called $category_ids. I'll called the project id $project_id.
What I want to do is compare the array $category_ids to entries in a MySQL table for $project_id. Then I want to add the links that aren't already in the table and delete the ones that need to be deleted. The table has these fields:
projects_cat_link (table)
----------------------
category_id ¦ project_id (fields)
Does anyone have any tips on how to do this? I've gathered that maybe there's a way to get the MySQL data into a similarly formed array and then use functions like array_diff to compare. But then I'm not sure how to use the comparison in a MySQL query to add/edit/delete the links.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Remove A Row In Mysql Table With A Checkbox ?
I'm having trouble writing the code for deleting a row with a checkbox. My page allready contains an update and a insert form, which works great, but removing rows with a checkbox.This is my php code. <?php require_once('../../Connections/fisherintranet.php'); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $HTTP_SERVER_VARS['PHP_SELF']; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING']; } if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO licenties (company, license) VALUES (%s, %s)", GetSQLValueString($HTTP_POST_VARS['company'], "text"), GetSQLValueString($HTTP_POST_VARS['license'], "text")); mysql_select_db($database_fisherintranet, $fisherintranet); $Result1 = mysql_query($insertSQL, $fisherintranet) or die(mysql_error()); } if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "form3")) { $updateSQL = sprintf("UPDATE licenties SET company=%s, license=%s WHERE license=%s", GetSQLValueString($HTTP_POST_VARS['company'], "text"), GetSQLValueString($HTTP_POST_VARS['licupdate'], "text"), GetSQLValueString($HTTP_POST_VARS['license'], "text")); mysql_select_db($database_fisherintranet, $fisherintranet); $Result1 = mysql_query($updateSQL, $fisherintranet) or die(mysql_error()); $updateGoTo = "licenties.php"; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } if ((isset($HTTP_POST_VARS["MM_remove"])) && ($HTTP_POST_VARS["MM_remove"] == "form2")) { $removeSQL = sprintf("Delete from licenties WHERE 'ID'==???????????"); mysql_select_db($database_fisherintranet, $fisherintranet); $Result1 = mysql_query($removeSQL, $fisherintranet) or die(mysql_error()); $removeGoTo = "licenties.php"; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $removeGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $removeGoTo .= $HTTP_SERVER_VARS['QUERY_STRING']; } header(sprintf("Location: %s", $removeGoTo)); } session_start(); if ($HTTP_SESSION_VARS["statusCheck"] != "Admin") header("Location: menu.php"); $colname_licenties = "1"; if (isset($HTTP_SESSION_VARS['companyCheck'])) { $colname_licenties = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['companyCheck'] : addslashes($HTTP_SESSION_VARS['companyCheck']); } mysql_select_db($database_fisherintranet, $fisherintranet); $query_licenties = sprintf("SELECT license FROM licenties WHERE company = '%s' ORDER BY license ASC", $colname_licenties); $licenties = mysql_query($query_licenties, $fisherintranet) or die(mysql_error()); $row_licenties = mysql_fetch_assoc($licenties); $totalRows_licenties = mysql_num_rows($licenties); $colname_alles = "1"; if (isset($HTTP_SESSION_VARS['companyCheck'])) { $colname_alles = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['companyCheck'] : addslashes($HTTP_SESSION_VARS['companyCheck']); } mysql_select_db($database_fisherintranet, $fisherintranet); $query_alles = sprintf("SELECT * FROM licenties WHERE company = '%s' ORDER BY license ASC", $colname_alles); $alles = mysql_query($query_alles, $fisherintranet) or die(mysql_error()); $row_alles = mysql_fetch_assoc($alles); $totalRows_alles = mysql_num_rows($alles); ?> This is my code of my form : <form name="form2" method="post" action="<?php echo $editFormAction; ?>"> <table width="30%" border="1" align="center" cellpadding="0" cellspacing="0" bgcolor="#999966"> <tr> <td colspan="2" bgcolor="#999900"><div align="center"> <font color="#FFFFFF" face="Times New Roman, Times, serif"><strong>licenses</strong></font></div></td> </tr> <?php do { ?> <tr> <td><div align="center"> <p> <input name="<?php echo $row_alles['ID']; ?>" type="checkbox" id="<?php echo $row_alles['ID']; ?>" value="<?php echo $row_alles['ID']; ?>"> <font color="#FFFFFF"> </font></p> </div></td> <td><div align="center"> <p><font color="#FFFFFF"><?php echo $row_licenties['license']; ?></font></p> </div></td> </tr> <?php } while ($row_licenties = mysql_fetch_assoc($licenties)); ?> </table> <p align="center"> <input name="MM_remove" type="hidden" id="MM_remove" value="form1"> <input type="submit" name="Submit" value="Remove selected license"> </p> </form>
Sending Extracted Array Data From MySQL To Checkbox
I have a list of checkboxes set up as a form that stores the data to a database cell in a comma separated string: For example: "12,13,18,110,118,21,28,31" Each checkbox has a name of "categories" with different values. What I'd like to do is the following: 1) Extract the data from the database 2) Separate each number it into an individual array value 3) Make the checkboxes in categories.php reflect the selected or non-selected state, based upon the results from the database (selected being the numbers in the database) Step 1 - I know how to do. Step 2 - I assume I need to use the explode function, no? Step 3 - Not a clue.... Code:
Fetching Array From MySQL Table
Some told me to better learn some basics of php and mysql, but i encountered a problem that i couldn't solve with all the tutorials out there. I tried the following code to fetch an array from a MySQL table named Gallery: PHP Code:
Inserting Array Into Mysql Table
Anyone know the best way to insert an array from a form into a mysql table. My array is validated from the form and then inserted into the db, only when I SELECT it, it merely saya 'array' in the field.
Multidimensional Array In To A MySQL Table
Trying to load an multidimensional array into a MySQL table with columns as follows, level1,level2,level3,illust,item,description,partN o,qua,price,remarks,weight ,size,mass the array first line is $input[0][level1]Engine the array secondline is $input[0][level2]Cylinder Head etc.. A 'foreach' inside a 'foreach' echo of the array gives the following, which is correct. 0, level1, Engine 0, level2, Cylinder Head 0, level3, 0, illust, 001.pdf 0, item, 1 0, description, Casting 0, partNo, 238356 0, qua, 1 0, price, 1,245.00 0, remarks, This is for the Z350 series 0, weight, 5 0, size, 5x5x5 0, mass, 37 1, level1, Engine 1, level2, Cylinder Head 1, level3, 1, illust, 001.pdf 1, item, 2 1, description, Valve, inlet 1, partNo, 452790 1, qua, 4 1, price, 5.46 1, remarks, This is for the Z350 series 1, weight, 5 1, size, 5x5x5 1, mass, 37 2, level1, Engine 2, level2, Cylinder Head 2, level3, 2, illust, 001.pdf 2, item, 3 2, description, Valve, exhaust 2, partNo, 345436 2, qua, 4 2, price, 5.99 2, remarks, This is for the Z350 series 2, weight, 5 2, size, 5x5x5 2, mass, 37
Sorting A Table Into An Array In Mysql
Can someone tell me how to sort a table using a while function. This is what i want to do. I have table that has 17 fields, the first two are id and date and the rest of date..but what i want to do is take the data and sort it by the date and put the rest of the data under that date. example: date Data date Data I asume the array will look like this result[0][0] result[0][1] result[1][0] result[1][1] and so on .....
Checkbox And Relational Table
I've a formular with a list of clients per work experience. I can have several clients for a experience. So I have a table for "experience", one for "client" and a relational table "rel_experience-client". To retrieve the list of clients per work experience I use the query : SELECT * FROM experience, client, rel_experience_client WHERE experience_ref=experience.id AND client_ref=client.id AND experience_ref=12345 ORDER BY libelle How can I retrive this information and add a checkbox on each client if they are on the experience? With the solution below, I can't find the ... solution! <?php require_once('../../../Connections/metadeco_connect.php'); ?> <?php mysql_select_db($database_metadeco_connect, $metadeco_connect); $query_rs1experience = "SELECT * FROM experience"; $rs1experience = mysql_query($query_rs1experience, $metadeco_connect) or die(mysql_error()); $row_rs1experience = mysql_fetch_assoc($rs1experience); $totalRows_rs1experience = mysql_num_rows($rs1experience); mysql_select_db($database_metadeco_connect, $metadeco_connect); $query_rs4_rel_experience_client = "SELECT * FROM experience, client, rel_experience_client WHERE experience_ref=experience.id AND client_ref=client.id AND experience_ref=12345 ORDER BY libelle"; $rs4_rel_experience_client = mysql_query($query_rs4_rel_experience_client, $metadeco_connect) or die(mysql_error()); $row_rs4_rel_experience_client = mysql_fetch_assoc($rs4_rel_experience_client); $totalRows_rs4_rel_experience_client = mysql_num_rows($rs4_rel_experience_client); mysql_select_db($database_metadeco_connect, $metadeco_connect); $query_rs7client = "SELECT * FROM client ORDER BY libelle ASC"; $rs7client = mysql_query($query_rs7client, $metadeco_connect) or die(mysql_error()); $row_rs7client = mysql_fetch_assoc($rs7client); $totalRows_rs7client = mysql_num_rows($rs7client); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body><form name="form1" method="post" action=""> <?php if ($totalRows_rs7client>0) { $nested_query_rs7client = str_replace("12345", $row_rs7client['id'], $query_rs7client); mysql_select_db($database_metadeco_connect); $rs7client = mysql_query($nested_query_rs7client, $metadeco_connect) or die(mysql_error()); $row_rs7client = mysql_fetch_assoc($rs7client); $totalRows_rs7client = mysql_num_rows($rs7client); $nested_sw = false; if (isset($row_rs7client) && is_array($row_rs7client)) { do { //Nested repeat ?> <input <?php if (!(strcmp($row_rs1experience['id'],$row_rs7client['id']))) {echo "checked";} ?> name="checkbox_client" type="checkbox" id="checkbox_client" value="<?php echo $row_rs7client['id']; ?>"> <?php echo $row_rs7client['libelle']; ?><br> <?php } while ($row_rs7client = mysql_fetch_assoc($rs7client)); //Nested move next } } ?> <br> <input type="submit" name="Submit" value="Submit"> </form> </body> </html> <?php mysql_free_result($rs1experience); mysql_free_result($rs4_rel_experience_client); mysql_free_result($rs7client); ?>
Check If Any Items In An Array (php) Is In A Table (mysql).
I want to check if any of the items in a PHP array exist in a MySQL table. What is the best way to do this with making repeated calls to the database for each item? Actual application is: I have an array (in PHP) of serial numbers of units about to be shipped.I want to check the ship record (a table in a MySQL database) to check if that serial number has been used before. According to our quality policy we never reuse serial numbers, serial numbers are unique. So prior to printing the packing slip I want to warn the shipping guy/gal a serial number may be incorrect. I could brute force it and increment through the "to be shipped array" and check each item against the table. But that is, as I said brute force, and I am having to be concerned with system speed lately.
Putting An Array In A Mysql Database Table Field
I want to insert an array into my database but i've got a problem with it. Before i insert the array into the dbase i check if everything is in the array with print_r($array). Everything that should be in the array is in there so i insert it into the dbase. When i check my dbase with phpmyadmin the field that should contain my array has the word array in it so i assume the array is in the dbase. But when i retrieve the data from my dbase and check my array with print_r i get the following error: Warning: Argument to array_values() should be an array in.
Explode Text Area Into Array For MySQL Table
On my site, I have a textarea where users enter their sites' information in the following format (tab-delimited): Site Name <tab> Site Description <tab> URL <newline> Site Name <tab> Site Description <tab> URL <newline> (and so on...) I know I have to use the "Explode function and a loop to get the data into an array and enter it into a MySQL table. Would anyone have a snippet of code off-hand that could show me how to do this?
Comparing Array Values
I'm developing a database that holds information about crew members. There are 7 categories of service types. Crew members can be associated with any number of categories. I'm working on an update form to add or delete categories for a crew member. I first issued a query to find the member's categories. I issued a second query to list all possible categories. I want to show a checkbox for any possible categories that aren't in the member's individual category list. If the member is in categories 1 and 2, but not in 3 or 4, I want to show a checkbox for categories 3 and 4. I can get the two category lists to print, but I can't figure out how to compare them. Here is the code I have for the select statements: Generates the list of member categories: $cat_query = "SELECT crew_category.crew_id, crew_category.category_id, category.category_desc FROM crew_category, category WHERE crew_category.crew_id = "$crew_id" and crew_category.category_id = category.category_id"; $cat_result = mysql_query($cat_query); Generates the list of all possible categories: $all_cat_query = "SELECT category_id FROM category"; $all_cat_result = mysql_query($all_cat_query); I'm just developing my programming skills (as I'm sure you can tell), so I apologize for my ignorance! Thanks in advance to anyone who can help!
Comparing Array Contents
i'm having a small problem with getting information into a database. Basically, i've got a form with some elements in it, such as: name phone address for example. I pass these values to a function which finds out whether the action is associateds with the form is to insert, update or delete info from/to the database (using an HTML "hidden" field.) The field names in my database are the same as in my form. (name, phone etc...). Using mysql_fetch-field, I have an array with the field names in it. I read the values passed from the form into an array called $values with the form fields as keys ? I would like to set the entry as 'NULL' for each field in which there is no data to enter. I thought the best way to do this was by comparing the contents of both arrays, and where there was a key in $values corresponding to the fieldname, somehow assign the contents of $values to that fieldname in the query.
Checkbox Array
checkbox arrays do not hold their respective positions as do other field arrays that are established to store the contents of selected records. The problem is that when you "uncheck" one of the elements and then repost, that array element disappears and the whole array collapses and renumbers itself with only the remaining "checked" ones -- simply useless when dealing with records in a table where all the field array elements should be in sync. I consider it a bug -- why does the array have to collapse? Why can't it just hold a null value and keep its position? The only fix is to never hold checkbox values in an array. Store them in individual variables numbered like an array, then do an "eval" to retrieve the contents. Here's the whole thing in action: Code:
Checkbox Array
I have a list of checkboxes. The name for each is being pulled up from a database. Each (minus irrelevent or implicit code) looks like this ... <input type=checkbox name=assnid$assnarray[assnid] value=1> or...peaking at the HTML, the list looks like this: <input type=checkbox name=assnid1 value=1> <input type=checkbox name=assnid2 value=1> <input type=checkbox name=assnid3 value=1> and so on... Anybody know how to post the selected checkboxes into $assnidarray? For example, assuming all are chosen, $assnidarray would be (1,2,3,...).
Checkbox Array
I have a checkbox array containing the id of a record in a MySQL database. The checkboxes are created dynamically depending on what is stored in the database. I want to send the checkbox array to my stop_subscriptions.php file, running the code on all checked boxes, however I dont seem to be able to actually send the array, I was hoping that someone could steer me in the right direction. <?php $sql = "SELECT i.type, i.title , s.inj_id FROM inj_subscription s, injustices i WHERE s.member_id = '$user' AND i.inj_id = s.inj_id AND s.inj_id IS NOT null" ; $result = mysql_query($sql); $row = mysql_fetch_assoc($result) ; if ($row) { echo "<div><span>Specific Subsriptions:</span><br/>" ; $table_start ='<table width="90%" table name="table2" align="center" cellspacing="0" border="0"> <tr> <form method="post" action="stop_subscription.php"> <th width="20%">Type</th> <th width="70%">Title</th> <th width="10%"></th> <input type="submit" name="Submit" value="Submit" style="font-size:10px"/><p> <input type="hidden" name="stop_subscription" value="1"/> </form> </tr>' echo $table_start; $rownum = 0; while($row) { $rownum++; $style = rowcolor($rownum); $table_rows .= '<td id="td" align="center" style="'.$style.'padding:5px;" >'." ".'<form><input type="checkbox" name="deletethis[]" value="'.$row['inj_id'] . '"></form></td>'." "; echo "<tr>" . $table_rows . "</tr>"; $row = mysql_fetch_assoc($result) ; } echo '</table><Br/></div><br/>' } ?>
Checkbox Without Array
I have a question regarding implementing a checkbox that DOESN'T use arrays -- everything i find when i google has arrays in it! So, I'm hoping someone here can help me come up with a solution to my problem. I have a checkbox that a user can check (default will be to have it NOT checked) - and once it's checked, to keep it checked until the user unselects it again. Here's my checkbox code: <input type ="submit" name="cv_permission" type="checkbox"> What do I have to do to keep it turned 'ON' once it's checked?
Checking For Checkbox Array
I'm working on a page for an e-commerce site that has a form than lists items in an order placed by a customer. The form serves two purposes: to edit and save the details of the items (i.e. number of items, price, etc.) and to split the order (i.e. select certain items to remove from the order and use to create a new separate order). Each item has a checkbox next to it, and the name for the checkbox is "name[]" so an array of the checked items is created and passed to the processing script. The logic I want to use to determine if the items are being saved or being split out is by looking at the $name array. However, if I try something like "if ($_POST['name'])" and none of the checkboxes are checked, I get an Undefined Index error (it works fine if there are items checked). What is a valid way to check to see if the $name array exists so I know which action to take?
Checkbox Array Problem
I have a form which contains several fields. One of which is a group of checkboxes that can all be selected, and if they are - all values should be passed as an array. Each checkbox is Named as follows. myCheckBoxName[] myCheckBoxName[] I have the following code on the following page to pick up the results from the querystring. while(list($key, $value) = each($HTTP_POST_VARS)) { $keys = $keys . "$key, "; $values= $values . "'$value', "; echo("$key = $value <br>" ); } But the field which contains multiple checkboxes only displays the value "array" - and nothing else.
Foreach On Checkbox Array
I am having a bit of an issue getting a foreach statement i have made to work , essentially what this for each statement is suposed to do is write a row to a database for each one of the check boxes selected here is the code:
Sticky Checkbox Array
I have a group of checkboxes that I would like to be sticky. I want the checkboxes that the user has checked to remain checked upon returning to the page from a validation error. Code:
HELP! Passing Checkbox Values To Array
I have a form with a repeating table display data from MySQL, ie, invoice numbers and invoice pricing. I need to be able to select which invoices someone wants to pay via checkboxes. From here, I need to be able to display the corresponding records on another page where I can SUM() the invoice totals to give a price to be paid. I've never used array's before but believe this is how it should be done. My brain is currently fried and I'm struggling...
How To Store Checkbox Values To An Array?
I need to allow the user to select multiple mysql records via an html form checkbox. On submission of the form I would like to store these values in an array for either multiple record deletion or creating a list of records. Code:
Form Processor And Checkbox Array
I have been able to create simple forms on my html pages using a .php processor. For one I am working on now, I need to have two checkbox sections where the user can click multiple choices in each. It goes through my .php file and get's emailed. I need help with the code in the .php file on how to process two checkbox arrays and email the result. Code:
Problems With Dynamic Checkbox - Need To Create Array
The problem I have concerns a dynamically created table/form which pulls in results from a user search of a mysql database. This works fine and pulls in results (title/author/isbn/price) and dynamically creates the table dependent upon how many results are found. For each result there is a dynamically created checkbox, which is bound to a unique field from the database(in this case isbn). My problem then is: the dynamically created checkbox submits an isbn value to the next page - an order form. However I need that a user can select a number of checkboxes from the table. At the moment, each selection overwrites the other. It may be vary obvious - but I need to work out some way of storing the checkbox info in an array that gets submitted to my order form page. at the moment the code for my checkbox within the html form is: <input name="isbn_input" type="checkbox" id="isbn_input" value="<?php echo $row_Rs_panozzo_search['isbn']; ?>" /> </font></td> This works passing one value through to my order form, but I need to set it up so it passes multiple values.
Checkbox Array From Form - Shorthand For Looping The VALUES?
I am retreiving values from checkboxes in a form to decide where thumbnails and uploaded images get placed (same image goes in multiple directories). The following code works. But I wonder if there is a shorthand way to output the values in a while statment rather than a bunch of if statements. That is, is there a way to output ALL possible values (e.g., sports, group, 2002 - I have many others) in a loop? PHP Code:
Checkbox Array Passes To Script Fine But Doesn't Mail Right
I'm starting to get a little ticked off because I've worked for hours on this and I can't seem to find the cause. I'm using PHP 5.1.6. I'm trying to get the values of some form checkboxes along with another fixed variable and pass them along in an email. For demonstration purposes, I have checked the Wed and Fri checkboxes and set the time for 9:00 am. <FORM ACTION="test.php" METHOD=POST> <TABLE border="1" width="70%" > <TR> <td><input type="checkbox" name="NewClass[]" value="Mon" size="5" maxlength="2"</td> <td><input type="checkbox" name="NewClass[]" value="Tue" size="5" maxlength="2"</td> <td><input type="checkbox" name="NewClass[]" value="Wed" size="5" maxlength="2"</td> <td><input type="checkbox" name="NewClass[]" value="Thu" size="5" maxlength="2"</td> <td><input type="checkbox" name="NewClass[]" value="Fri" size="5" maxlength="2"</td> <td><input type="checkbox" name="NewClass[]" value="Sat" size="5" maxlength="2"</td> <td><input type="checkbox" name="NewClass[]" value="Sun" size="5" maxlength="2"</td> <TD><input type="text" name="NewClass-Time" size="5" maxlength="10"></TD> </TR> </TABLE> <input type="submit" name="ClassList" value="Submit Survey Info" class="button"> </form> When I print out print_r($_POST);, I get everything passed correctly as: Array ( [NewClass] =Array ( [0] =Wed [1] =Fri ) [NewClass-Time] =9:00 am ) But when it gets emailed, the results listed on the email I get are as follows: NewClass: Array NewClass-Time: 9:00 am I stripped the processing script down to the barest of essentials. All that's on it right now is: foreach($_POST as $key => $value){if(!(!isset($value))){$set=1;}$message = $message . "$key: $value ";} if($set!==1){header("location: $_SERVER[HTTP_REFERER]");exit;} $message = stripslashes($message); $headers = "From: " . $_POST['name'] . " <" .$_POST['email'] . "> " . "Return-Path: " . $_POST['email'] . " " . "Reply-To: " . $_POST['email'] . " "; mail($my_email,$subject,$message,$headers);
Comparing Values Of 2 Arrays Combined With Mysql Field Names
I am trying to create an edithistory table that has a text column into which I will put a string that can be read using strtok later to revert changes if necessary. I want to build this function so that it's dynamic enough to be applied to every table so that I don't have to write one for each table that might be updated. When a row is added to any table (a new entry), it retrieves the next available editid # from the edithistory table and assigns it to that item in the "edits" column for its row in its own table. Every edit made is a new entry in the edithistory table (entryid auto_increment primary key), and the editid is a reference back to the object being edited. Code:
Checkbox In Mysql Fields
PHP selects and shows a list of records. Next to each record is a check box. If user checks the box the record(s) is selected and appended to another 2nd DB....when the user finally presses a button Basically I hope you get my drift, pretty normal but powerful stuff... Are there any tutorials or snips on how I'd do this?
Checkbox Forms, Php & Mysql
I'm about to add some checkboxes to a form, and then store the data in a column on a MySQL database. Just wanted to know best practice, at the moment I'm writing and thinking .. God that's ungly code ... <input type="checkbox" name="delta" <?php if ($delta==1) { echo "checked"; }?>> Delta<br> <input type="checkbox" name="mastercard" <?php if ($mastercard==1) { echo "checked"; }?>> Mastercard<br> <input type="checkbox" name="solo" <?php if ($solo==1) { echo "checked"; }?>> Solo<br> <input type="checkbox" name="switch" <?php if ($switch==1) { echo "checked"; }?>> Switch<br> <input type="checkbox" name="visa" <?php if ($visa==1) { echo "checked"; }?>> Visa<br> MySQL database fields ... delta binary(1) No 0 mastercard binary(1) No 0 solo binary(1) No 0 switch binary(1) No 0 visa binary(1) No 0 When I output the fields, I get "on" or empty, and am wondering whether I am making a good decision to do the code this way. Now I need to figure out how to update the database based on the forms output.
Declaring A Checkbox In A Mysql
I have a html form that consists of drop down menus, text boxes and two checkboxs. I can get all the data to be sent to a mysql db via php. But when i try to insert the checkboxes into the db i get an error stating the following: Could not insert data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES ('6','a1','b1','3','c1','1234','1234','1234@1234.com Code:
Adding Checkbox Input To Mysql Db
how to pass a value from a form with a checkbox on a html page to a mysql database. I've preloaded some data and can populate a box if the data is already present in the db. But I would like to be able to check the box or uncheck the box and pass that value to the db (being able to change the value depending on whether it's checked or not). Code:
Passing A Checkbox Variable To A MySQL Db
Im the webmaster for a boxers website, and rather frequently, the publicist sends me links to articles about the boxer that I need to post. So, I set up a form that allows me to pull the information as needed and post it. Basically I have it set up to post the Article Title, Article URL, and Article Date, and I call that information from the db. However, on occassion, one of these links will be a press release, and the only thing that changes is that the text Press Release: is added in front of the article title. I was thinking about creating an extra field in the table called article_pr, and referencing that on the page, and if the row is empty, it would just pull up a space, and if its marked it just pulls up whatever is in there. However, on the form, I need to have a check box that asks if it is a press release. If so, I would need it to print this in the code Press Release:<br> Is there a way to have the check box indicate whether it will put that code in the db field?
Checkbox Values Stored In Mysql
I have a series of checkboxes and need to store their values in a MySQL table. I'm wondering what data type people recommend: varchar or text, exp. "True/False", "Yes/No" tinyint, exp. "0/1" Maybe it depends on the usage or maybe it doesn't matter and/or is a choice of personal preference.
Grab Content From HTML Table And Place Into MySQL Table?
I am in the process of helping a co-worker upgrade some of his old static html pages into dynamic MySQL driven pages. He currently has a lot of pages with huge tables displaying data. Does anyone know if there is a script or class that can convert a table to a .sql file for upload?
Table Background Color Based On Results From MySQL Table
I am trying to get the "Did User Agree" field on a database query to be colored Green for "Agreed" Red for "Disagreed" and Blue for "Agreed (2nd Time)" .. I have my PHP setup to do the query just fine as of right now with alternating column colors, just can't seem to get the colors to work as I am hoping for. Can anyone help me get the Agreed? table's background color to the colors above? Code:
Mysql Fetch_field Gets Table Alias, Not Real Table Name
After a SQL 'select .... from tablename alias' the mysql_fetch_field function returns a value $result=>table which will contain the alias, not the actual table name. Is there a way to get the actual table name ? I am running mysql 4.1 and php 4.4
Using PHP To Sort Data In MySQL Table 1 By Values In Table 2
I have a MySQL database with 2 tables in it. products and prices.. Products has a field in it called 'prodno'. Prices has a field in it called 'prodid'. There is one of each item in products and each product has it's own unique 'prodno' There are multiple instances of each product's pricing in prices.. One for each price.. So if a product had multiple prices depending on quantity it would have an entry for each price.. Example: id = 1 prodid = 7001 qty = 300 price = 12.5 id = 2 prodid = 7001 qty = 400 price = 15.5 I was wondering if I could query the database getting info from the products table but sort it according to the prices in the prices table. Kinda like doing a "SELECT * FROM products" ordering it by the lowest price value from each item.. This is all very confusing to me, and I'm the one writing it. Let's try one last time.. Query the database selecting * from products (I plan on using all the info in products) and ordering them by the lowest price for each item in the prices table. I've tried sorting the results of just a basic SELECT * FROM products using Javascript and PHP but with pagination in the results it makes it a bit hard.
Pesky Checkbox Arrays And A MySQL Song Database
I'm not one who likes to ask for help, so for the last three days my brain has been turning to mush while I try to create a DJ Request Song Wish List. Anyone who can help me out will be saving me from severe insanity. :) My goal is to: 1. Display search results for song title, artist and genre. (accomplished) 2. Allow the user to add songs to their Wish List. This is done by displaying checkboxes with the corresponding value equal to the songID. (working on it) 3. Allow the user to update their wishlist by adding/deleting songs. So far I have a form that retrieves the song info from a database in a repeating region. In Dreamweaver: <input name="songID[]" type="checkbox" id="songID[]" value="<b><?php echo $row_RecordsetSearchResults['Title'];?></b> by <?php echo $row_RecordsetSearchResults['Artist'];?>"> This puts the corresponding songID number into a checkbox value, which in turn is submitted by form POST action to the following page as an array. To process this array I have: if(isset($_POST['songID'])) { $songID = $_POST['songID']; print '<p>Song IDs:</p>' // process items $n = count($songID); for($i = 0; $i <= $n; $i++) { //See if the values are being passed from POST echo $songID[$i]; echo '<br>' } $songsInsert = '*'.implode('*',$_POST['songID']).'<br>' $insertSQL = sprintf("INSERT INTO wishlist (Username, Title) VALUES (%s, %s)", GetSQLValueString($MM_Username, "text"), GetSQLValueString($songsInsert, "text")); mysql_select_db($database_ToneDeaf, $ToneDeaf); $Result1 = mysql_query($insertSQL, $ToneDeaf) or die(mysql_error()); } The problem is, I'm using implode. It does store the songs, but only as one long block of text. So if the user picks "New York by Frank Sinatra" and "Hot In Here by Nelly" it is stored as "*New York by Frank Sinatra*Hot In Here by Nelly*" Obviously this gives me no options to make this actually readable, let alone allow the user to remove one of those songs from their list (both would be have to be removed.) Also, referencing only the songID number as stored in the music database doesn't seem a good option, since the song database will be changing frequently and song data may be overwritten. Not sure if there's a viable workaround there. Originally I wanted to store Title, Artist, Genre under seperate columns so I could link them to something like "See more songs from this Artist." However the more I read about arrays and multidimensional arrays, I realize I'm not ready to go there yet. (I just started learning PHP two weeks ago.)
Comparing Form Data To Mysql Data
Im interested in building a script that would take form data, a variable like an address, and compare it with a known address in a mysql table (called addresses), then if there is a match log the address information in a separate table called (addresslog), and return the visitor to a certain page. If there is no match between the address entered in the form and known addresses then the information is still logged into the addresslog database but the visitor will be sent to a different page. I'm still new to this, and am working through the logic and the syntax, but I believe I'm close. It's still not working, I have all of the proper tables, maybe I'm way off with the coding so I thought I would seek out some expert advice. Here's the entire script with as much explanation as I could give. PHP Code:
Array To Table
is there some way i can have a script dump all the details in this array into database tables without having to type it all out manually? I'd like it in fields of gameid and gamename specified in the case clause...but short name will do if thats all i can get. All the info would be best if possible. Here is the array... PHP Code:
To Write An Array To A Table
I have a javascript array to pass to PHP: var javascript_array={{"1","Elisab eth","London"},{"2","Antony"," Paris"},{"3","Augusto","Roma"} ,{"4","Tom","Miami"}} I transform it into a string var string="1,Elisabeth,London;2,A ntony,Paris;3,Augusto,Rome;4,T om,Miami" I separated any old array with a ";" and any element of a singhe array with...
Array As A Temporary Table
I'm trying to implement an array as a mysql temporary table. Then do the join based on that array. Code:
Table Row Intervals From An Array
i want to do is to display the results from my SQL Query and render them in a HTML table but after every third bit of data i want to echo out a <tr> tag to start a new row. Code:
Insert Into Table Via Assoc Array
I am trying to populate data from an array into a table, but i cant figure out what i am doing wrong. //mysql query $sql = "SELECT charge_location.dept_code, charge_location.week, Sum(charge_location.total_hrs_paid) AS sum_of_total_hrs_paid, Sum(charge_location.hrs_non_chargeable) AS sum_of_hrs_non_chargeable FROM charge_location GROUP BY charge_location.dept_code, charge_location.week"; $result = mysql_query($sql); $num_results = mysql_num_rows($result); //populate the stats_table for($i=0; $i<$num_results; $i++){ $row = mysql_fetch_array($result); mysql_query("insert into stats_summary values( ($row[dept_code]), ($row[week]), ($row[sum_of_total_hrs_paid]), ($row[sum_of_hrs_non_chargeable])) "); } PS i get no errors when it executes, just fails to populate the table.
Displaying Array Results In Table
I'd like to display the results of an array in a table format with the Alias, Alias Destination & Username as column headings & the results underneath. PHP Code:
|