PHP - Mysql Update Mutliple Fields From Array
Now, here's what I'm trying to do:
First, I have a file filled with data like such:
title
tag
1
2
Title
Description
Etc
Next, I upload that file to my site which then proceeds to make an array with said data and then inserts it into my database. But this is not the intended behavior. Right now, if I upload the same file again, it will re-insert everything and duplicate all entries.
What I want to do is check if the data in the file has already been added, do nothing. If it's been modified, I want to update the database where changes have been made and not duplicate anything.
Currently, my code does all that except one thing whre I'm really stuck: it won't update the changes from the file to the database. I've tried echoing everything and it's to be working except for the query so I take it the error is in there but I can't find it... I'm still learning PHP and MySQL so I thought maybe somebody could help indicate where or what I'm doing wrong in the query. Thanks in advance !
Here's my attempt at doing so:
$register_ep_data = array( 'show' => $name, 'season' => $srNum, 'ep' => $epNum, 'app_name' => $epName, 'tag' => $tag, 'app_about' => $desc, 'app_website' => $imdb, 'app_release' => $release, 'type' => $type, 'app_code' => $Frame ); array_walk($register_ep_data, 'array_fu'); $fields = '`' . implode('`, `', array_keys($register_ep_data)) . '`'; $data = '\'' . implode('\', \'', $register_ep_data) . '\''; $epFound = false; $id = 0; while ($ep_list_data = mysql_fetch_array($turtle)) { $id = $ep_list_data['app_id']; $currentNAME = $ep_list_data['app_name']; $SERIES = $ep_list_data['show']; if ($SERIES == $name) { if ($currentNAME == $epName) { $epFound = true; break; } } } if ($epFound) { mysql_query("UPDATE `games` SET ($fields) VALUES ($data) WHERE `app_id` = '$id'"); } else { mysql_query("INSERT INTO `games` ($fields) VALUES ($data)"); }A few explanations: $fields would equal to something like: `show`, `season`, `ep`, etc... and $data to 'example', '1', '2', 'etc' 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. In brief, I'm attempting to capture the form data from a dynamic form to a mysql database. From he
To He
The post data looks like this from the form - Array(
... ) PHP CODE:
... As a non-php or mysql developer, I'm learning on the fly. This is a section of the php file that I was using to post the form data to mySQL. This worked great up to the point I added the dynamic form widget. <?php // This function will run within each post array including multi-dimensional arrays function ExtendedAddslash(&$params) { foreach ($params as &$var) { // check if $var is an array. If yes, it will start another ExtendedAddslash() function to loop to each key inside. is_array($var) ? ExtendedAddslash($var) : $var=addslashes($var); unset($var); } } // Initialize ExtendedAddslash() function for every $_POST variable ExtendedAddslash($_POST); $submission_id = $_POST['submission_id']; $formID =$_POST['formID']; $ip =$_POST['ip']; $fname =$_POST['fname']; $lname =$_POST['lname']; $spousename =$_POST['spousename']; $address =$_POST['address'][0]." ".$_POST['address'][1]." ".$_POST['address'][2]." ".$_POST['address'][3]." ".$_POST['address'][4]." ".$_POST['address'][5]; ... $db_host = 'localhost'; $db_username = 'xxxxx'; $db_password = 'xxxxx'; $db_name = 'xxxxx'; mysql_connect( $db_host, $db_username, $db_password) or die(mysql_error()); mysql_select_db($db_name); // search submission ID $query = "SELECT * FROM `tableName` WHERE `submission_id` = '$submission_id'"; $sqlsearch = mysql_query($query); $resultcount = mysql_numrows($sqlsearch); if ($resultcount > 0) { mysql_query("UPDATE `tableName` SET `fname` = '$fname', `lname` = '$lname', `spousename` = '$spousename', `address` = '$address', WHERE `submission_id` = '$submission_id'") or die(mysql_error()); } else { mysql_query("INSERT INTO `tableName` (submission_id, formID, IP, fname, lname, spousename, address) VALUES ('$submission_id', '$formID', '$ip', '$fname', '$lname', '$spousename', '$address') ") or die(mysql_error()); } ?> It has been suggested that I explore using the PHP Explode() function. It's possible that may work, but can't get my head around how to apply the function to the PETLIST Array. Looking for suggestions or direction to find a solution for this challenge. Looking forward to any replies. I am pulling 5 addresses and I am wanting to store these 5 addresses in columns in a separate table. On the query string I put LIMIT 5. How can I store the results of each of the 5 loops into columns in a separate table? The columns are A1(for name), A2(for address), A3 (for city), A4 (for state), A5 (for zip), A6 (for phone), A7 (for miles), .... then I also have B1-B7, C1-C7, D1-D7, and E1-E7. I am basically wanting to store up to 5 addresses in an array and then update them into a mysql table. Code: [Select] foreach ($zips as $key => $value) { $result = mysql_query("SELECT State FROM extreme WHERE Zip = '$key' AND Type='store' AND `InStore` <> 'NO' LIMIT 5", $db); $num_rows = mysql_num_rows($result); while($myrow = mysql_fetch_array ($result)) { $Dealer=$myrow['Dealer']; $Address=$myrow['Address']; $City=$myrow['City']; $State=$myrow['State']; $Zip=$myrow['Zip']; $Phone=$myrow['Phone']; $Miles = $value; } } Hi all, I have the following MySQL insert query: Code: [Select] $insert= mysql_query ("INSERT INTO tablename (column1,`".$EXPfields."`) VALUES ('$something','".$EXPvalues."')"); where $EXPfields is an array of table-field-names and $EXPvalues is an array of table-field-values. Now I want to write an equivalent query, but using UPDATE instead of INSERT INTO, but I don't want to write out all the field names/values separately, but again want to use $EXPfields and $EXPvalues. So something like this: Code: [Select] $update = mysql_query ("UPDATE tablename SET (column1,`".$EXPfields."`) = ('$something','".$EXPvalues."') WHERE .... "); Is this possible? If so, what is the proper syntax? Thanks! I have this code: Code: [Select] if (isset($_POST['update'])){ $ids = implode(",", array_map('intval', $_POST['m'])); $ranks = implode(",", array_map('intval', $_POST['ranks'])); if ($ids < 1) message("Incorrect Data"); if ($ranks < 0) message("Incorrect Data"); echo $ids; echo "<br>"; echo $ranks; exit; $db->query('UPDATE friends set RANKS WHERE friend_id IN ('.$db->escape($ids).') AND user_id = '.$pun_user['id'].'') or error('Unable to remove users from online list', __FILE__, __LINE__, $db->error()); redirect("s.php?section=Friends","Thanks, Ranks Updated"); } I grab the id's from the rank This will spit out 3,4 for $ids and for $ranks, 1,2 as you can see, set for 1 and 2 respectivaly. My problem is how can I use MYSQL to update the data correspond to each id using a IN clause? Code: [Select] $db->query('UPDATE friends set RANKS = "LOST $RANKS? HERE" WHERE friend_id IN ('.$db->escape($ids).') AND user_id = '.$pun_user['id'].'') or error('Unable to remove users from online list', __FILE__, __LINE__, $db->error()); Can anyone post a generic update function to update mysql table. The manual approach: update $tablename set $column1='a', $column2='b' where $id=$value; HI All, I am writing a prepared statement to update some user information. Included in this table are the username and password fields. In this particular form, i dont want the user to have access to this information and have built a form that only shows what i want them to be able to change. The bit that i am not sure about is the prepared statement that i am writing. I am getting a boolean error suggesting that my prepare failed and i think this may be because i have not named every field in the table. To give an idea of the table fields i have pulled this from php my_admin (this is not the sql i am running) UPDATE `ssm_user` SET `user_id`=[value-1],`user_email`=[value-2],`user_password`=[value-3], `user_firstname`=[value-4],`user_lastname`=[value-5],`user_accountlevel`=[value-6], `user_mobile`=[value-7],`user_role`=[value-8],`user_lastlogondate`=[value-9] WHERE 1 my prepared statement is $stmt = $conn->prepare(" UPDATE ssm_user SET user_email=?, user_firstname=?, user_lastname=?, user_accountlevel=?, user_mobile=?, WHERE user_id = ? "); $stmt->bind_param('sssssi', $email, $fname, $lname, $accountlevel, $mobile, $uid); $stmt->execute(); return $stmt->affected_rows; Do i have to declare every field in the table or is there something that i am missing here. HI, I have a user form on a modal. The user can be updated from this modal but on the second tab is where the users password can be updated. The update button commits all changes including the password update. If the New Password field is blank i do not want it to be updated. I am using a prepared statement and am not sure how to ommit a field if it is blank. In actual fact there is a new password and a confirm password field which must be the same before the password field is updated. if ($_SERVER['REQUEST_METHOD']=='POST'){ $uid = $_POST['UM-uid']; $fname = $_POST['UM-firstName']; $lname = $_POST['UM-lastName']; $email = $_POST['UM-emailAddress']; $accountlevel = $_POST['UM-accountLevelId']; $mobile = $_POST['UM-mobileNumber']; $roleid = $_POST['UM-roleId']; $newpass = password_hash($_POST['UM-pass'], PASSWORD_DEFAULT); if(!empty($_POST['UM-firstName'])){ // prepare stmt $stmt = $conn->prepare(" UPDATE ssm_user SET user_password=?, user_email=?, user_firstname=?, user_lastname=?, user_account_level_id=?, user_mobile=?, user_role_id=? WHERE user_id = ? "); $stmt->bind_param('sssssssi', $newpass, $email, $fname, $lname, $accountlevel, $mobile, $roleid, $uid); $stmt->execute(); $_SESSION['user']=$fname." ".$lname; $_SESSION['updateUser']="has been successfully updated"; $_SESSION['actionstatus']="success"; I am sure i will be able to work out the password confirmation part, its just the omitting password from being part of the update if blank. Hi I have an update page with multipule drop down menus, I am looking for a way to allow only the drop down menus that have been altered to be sent to the database. One way was to add the following code, where the $type_id equals 0 then add nothing to the database. Code: [Select] if ($type_id == 0) { $type_id = ""; } However I am getting a syntex error with this, if I enter a value into the $type_id it selects that fine. eg. Code: [Select] if ($type_id == 0) { $type_id = "2"; } What is the right way to send nothing to the database? Fuller code of the page is here <?php require_once("includes/sessions.php"); ?> <?php require_once("includes/connections.php"); ?> <?php require_once("includes/functions.php"); ?> <?php confirm_logged_in();?> <?php usersid(); ?> <?php find_selected_event(); find_selected_region(); ?> <?php $selected_event = getevent_byid ($url_eventid); $orgdescrip = orgdescription($url_eventid); $leveldescrip = leveldescription($url_eventid); $typedescrip = typedescription($url_eventid); $champdescrip = champdescription($url_eventid); $disdescrip = disdescription($url_eventid); $venuedescrip = venuedescription($url_eventid); $statusdescrip = statusdescription($url_eventid); ?> <?php if (!isset($new_event)) {$new_event = false;} ?> <?php // make sure the subject id sent is an integer if (intval($_GET['url_eventid']) == 0) { redirect_to('controlpanel.php'); } include_once("includes/form_functions.inc.php"); // START FORM PROCESSING // only execute the form processing if the form has been submitted if (isset($_POST['submit'])) { // initialize an array to hold our errors $errors = array(); // perform validations on the form data $required_fields = array('title'); $errors = array_merge($errors, check_required_fields($required_fields, $_POST)); $required_numberfields = array(); $errors = array_merge($errors, check_number_fields($required_numberfields, $_POST)); $fields_with_lengths = array(); $errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST)); // clean up the form data before putting it in the database $url_eventid = mysql_prep($_GET['url_eventid']); $user_id = mysql_prep($_POST['user_id']); $title = trim(mysql_prep($_POST['title'])); $event_details = mysql_prep($_POST['event_details']); $type_id = mysql_prep($_POST['type_id']); $champ_id = mysql_prep($_POST['champ_id']); $dis_id = mysql_prep($_POST['dis_id']); $org_id = mysql_prep($_POST['org_id']); $venue_id = mysql_prep($_POST['ven_id']); $level_id = mysql_prep($_POST['level_id']); $status_id = mysql_prep($_POST['status_id']); if ($type_id == 0) { $type_id = ""; } // Database submission only proceeds if there were NO errors. if (empty($errors)) { $sql = "UPDATE events SET \n" . "title = '{$title}',\n" . "event_details = '{$event_details}',\n" . "type_id = {$type_id},\n" . "champ_id = {$champ_id},\n" . "dis_id = {$dis_id},\n" . "org_id = {$org_id},\n" . "ven_id = {$venue_id},\n" . "user_id = {$url_userid},\n" . "level_id = {$level_id},\n" . "status_id = {$status_id}\n" . "WHERE event_id = {$url_eventid} \n" . "LIMIT 1"; if ($result = mysql_query($sql, $connection)) { // as is, $message will still be discarded on the redirect $message = "The event was successfully updated."; // get the last id inserted over the current db connection $new_event_id = mysql_insert_id(); redirect_to("newevent.php"); } else { $message = "I am sorry but the event could not be updated."; $message .= "<br />" . mysql_error(); } } else { if (count($errors) == 1) { $message = "There was 1 error in the form."; } else { $message = "There were " . count($errors) . " errors in the form."; } } // END FORM PROCESSING } ?> <?php /*THIS CODE WITH RETURN IN THE BROWSER THE URLS THAT ARE BEING PULLED DOWN*/ if(empty($_GET)) echo "No GET variables"; else print_r($_GET); ?> <?php include("includes/header.inc.php"); ?> <title>Horse Events</title> <?php include_once("includes/meta.inc.php");?> <?php include_once("includes/cssfavgoogle.inc.php");?> <link href="css/adminpanel.css" rel="stylesheet" type="text/css" /> <style> input[type="number"] { width:40px; } </style> </head> <body> <div id="wrapper"> <div id="header"> <img src="images/horseevents_wheretogo.png" align="right" /> <?php require_once ("includes/adminmenu.inc.php"); ?> </div> <div id="adminleft"> <h2>YOUR UPCOMING EVENTS <?php echo "<a href=\"newevent.php?url_userid={$url_userid}\"><img src=\"images/pink/add_event.png\" align=\"right\" width=\"131\" height=\"19\" /></a>" ?></h2> <table id="datetable" width="300" border="0" > <?php $event_users_set = get_upcomingeventsforuser ($url_userid); while ($eventid = mysql_fetch_array ($event_users_set)){ echo"<tr class=\'date\'>"; echo"<td>" . $eventid["stdate"] ."</td>"; echo"<td><a href=\"editevent.php?url_userid={$url_userid}&url_eventid=". urlencode ($eventid['event_id']) . "\">". $eventid ['title'] . "</td>"; echo"</tr></a>"; } ?> </table> <br /> <h2>YOUR PAST EVENTS</h2> <table id="datetable" width="300" border="0" > <?php $event_users_set = get_pasteventsforuser ($url_userid); while ($eventid = mysql_fetch_array ($event_users_set)){ echo"<tr class=\'date\'>"; echo"<td>" . $eventid["stdate"] ."</td>"; echo"<td><a href=\"editevent.php?url_userid={$url_userid}&url_eventid=". urlencode ($eventid['event_id']) . "\">". $eventid ['title'] . "</td>"; echo"</tr></a>"; } ?> </table> </div> <div id="admincontent"> <span class="h1pln">Edit Your Event</span><a class="delete" href="deleteevent.php?url_eventid=<?php echo $url_eventid; ?>" onClick="return confirm('Are you sure you want to delete?')">Delete</a><br /> <span class="h3pln">Please make sure you complete all the compulary fields<span class="compuls">*</span>.<br /> The more accurately you enter your event the more people will be able to then find it. <br /> <br /> If there are any selections we do not currently have available please click here and I will add them to your drop down menus.</span> <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?> <?php if (!empty($errors)) { display_errors($errors); } ?> <form id="newevent" action="editevent.php?url_eventid=<?php echo urlencode ($selected_event ['event_id']); ?>" method="post"> <table id="neweventdisplay" cellpadding="5" width="400" border="0"> <tr> <td><input type="text" name="event_id" value="<?php echo $url_eventid; ?>" /></td> <td><input type="text" name="user_id" value="<?php echo $url_userid; ?>" /></td> </tr> <tr> <td class="heading">Event Title</td> <td><input id="titleinput" name="title" type="text" value="<?php echo $selected_event ['title']; ?>" /><span class="compuls">*</span><span class="smalltext">Enter up to 36 characters</span></td> </tr> <tr> <td class="heading">Current Status</td> <td><?php echo $statusdescrip ['status_description']; ?> <select name="status_id" > <?php $status_set = findstatus(); $statuslist = mysql_fetch_assoc ($status_set); ?> <?php do { ?> <option value="<?php echo $statuslist ['status_id']; ?>" ><?php echo $statuslist ['status_description']; ?></option> <?php } while ($statuslist = mysql_fetch_assoc ($status_set)); ?></select> <span class="compuls">*</span></td> </tr> <tr> <td class="heading">Organiser</td> <td><?php echo $orgdescrip ['org_name']; ?> <select name="org_id"> <?php $organisers_set = findorganisers(); $orglist = mysql_fetch_assoc ($organisers_set); ?> <?php do { ?> <option value="<?php echo $orglist ['org_id']; ?>" ><?php echo $orglist ['org_name']; ?></option> <?php } while ($orglist = mysql_fetch_assoc ($organisers_set)); ?></select></td> </tr> <tr> <td class="heading">Start Date</td> <td id="dateinput"><?php echo $selected_event ['stdate']; ?></td> </tr> <tr> <td class="heading">Type Of Event</td> <td><?php echo $typedescrip ['type_description']; ?> <select name="type_id"> <?php $type_set = findtype(); $typelist = mysql_fetch_assoc ($type_set); ?> <?php do { ?> <option value="<?php echo $typelist ['type_id']; ?>" ><?php echo $typelist ['type_description'], $typelist ['type_id']; ?></option> <?php } while ($typelist = mysql_fetch_assoc ($type_set)); ?></select><span class="compuls">*</span></td> </tr> <tr> <td class="heading">Venue</td> <td><?php echo $venuedescrip ['ven_name']; ?><select name="ven_id"> <?php $venues_set = findvenues(); $venuelist = mysql_fetch_assoc ($venues_set); ?> <?php do { ?> <option value="<?php echo $venuelist ['ven_id']; ?>" ><?php echo $venuelist ['ven_name'], $venuelist ['ven_id']; ?></option> <?php } while ($venuelist = mysql_fetch_assoc ($venues_set)); ?></select></td> </tr> <tr> <td class="heading">Discipline</td> <td><?php echo $disdescrip ['dis_description']; ?><select name="dis_id"> <?php $discipline_set = finddisciplines(); $dislist = mysql_fetch_assoc ($discipline_set); ?> <?php do { ?> <option value="<?php echo $dislist ['dis_id']; ?>" ><?php echo $dislist ['dis_description'], $dislist ['dis_id']; ?></option> <?php } while ($dislist = mysql_fetch_assoc ($discipline_set)); ?></select><span class="compuls">*</span></td> </tr> <tr> <td class="heading">Level</td> <td><?php echo $leveldescrip ['level_description']; ?> <select name="level_id"> <?php $level_set = findlevels(); $levellist = mysql_fetch_assoc ($level_set); ?> <?php do { ?> <option value="<?php echo $levellist ['level_id']; ?>" ><?php echo $levellist ['level_description'], $levellist ['level_id']; ?></option> <?php } while ($levellist = mysql_fetch_assoc ($level_set)); ?></select></td> </tr> <tr> <td class="heading">Is This A Championship</td> <td><?php echo $champdescrip ['champ_description']; ?><select name="champ_id"> <?php $championship_set = findchampionships(); $champlist = mysql_fetch_assoc ($championship_set); ?> <?php do { ?> <option value="<?php echo $champlist ['champ_id']; ?>" ><?php echo $champlist ['champ_description'], $champlist ['champ_id']; ?></option> <?php } while ($champlist = mysql_fetch_assoc ($championship_set)); ?></select></td> </tr> <tr> <td class="heading">Event Details</td> <td><textarea name="event_details" cols="45" rows="15" ><?php echo $selected_event ['event_details']; ?> </textarea></td> </tr> <tr> <td class="heading">Upload Schedule</td> <td></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" id="convert" value="Update Your Event"></td> </tr> </table> <a class="delete" href="controlpanel.php">Cancel</a> </form> </div> <div id="adminright"> </div> <br clear="all" /> <?php require("includes/lowerlistings.inc.php"); ?> <?php require("includes/footer.inc.php"); ?> </div><!--End of Wrapper--> </body> </html> hi i am trying to make a payroll calculator script that takes employee info, calculates pay, displays submitted info in a table, stores info in an array, and updates the array when new info is submitted. i have most of these accomplished, i am having trouble with the "store into an array, and update the array when new info is submitted" parts of the project. i am still not very fluent in php so there may be easier ways to achieve what i have so far. any pointers would be a great help, this part has got me stumped. I've used a lot of solutions from this site, however, this is my first post, so go easy on me :-) I've created a product form the successfully INSERTS data to a mysql table. I can successfully query the data so that product information can be updated. When I click submit to UPDATE the rows, everything updates except for 2 fields that are arrays. Here is my product form that populates data to be edited. Code: [Select] <?php session_start(); require("config.php"); require("db.php"); require("functions.php"); if(isset($_SESSION['SESS_ADMINLOGGEDIN']) == FALSE) { header("Location: " . $config_basedir); } if(isset($_GET['func']) == TRUE) { if($_GET['func'] != "conf") { header("Location: " . $config_basedir); } $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir); header("Location: " . $config_basedir . "adminedit.php"); } else { require("header.php"); $sql = "SELECT * FROM products WHERE id = " . $_GET['id'] . ";"; $query = mysql_query($sql); while ($prodrow = mysql_fetch_array($query)){ $id = $prodrow['id']; $active=$prodrow['active']; $cat_id=$prodrow['cat_id']; $name=$prodrow['name']; $description=$prodrow['description']; $details=$prodrow['details']; $price=$prodrow['price']; $price2=$prodrow['price2']; $price3=$prodrow['price3']; $price4=$prodrow['price4']; $price5=$prodrow['price5']; $price6=$prodrow['price6']; $minimum=$prodrow['minimum']; $price7=$prodrow['price7']; $price8=$prodrow['price8']; $price9=$prodrow['price9']; $image=$prodrow['image']; } ?> <form action="adminprodupdate.php" method="post"> <table width="500" border="1" cellpadding="10"> <tr> <td>ID:</td> <td><input type="hidden" value="<? echo $id; ?>" name="id" /></td> </tr> <tr> <td>Active:</td> <td><input name="active" type="radio" value="0" <?php echo ($active=='0')? 'checked':'';?> />Yes<br /> <input name="active" type="radio" value="1" <?php echo ($active=='1')? 'checked':'';?> />No</td> </tr> <tr> <td>Category:</td> <td><input name="cat_id" type="radio" value="1" <?php echo ($cat_id=='1')? 'checked':'';?> />Hats<br /> <input name="cat_id" type="radio" value="2" <?php echo ($cat_id=='2')? 'checked':'';?> />Shirts<br /> <input name="cat_id" type="radio" value="3" <?php echo ($cat_id=='3')? 'checked':'';?> />Promotional Items</td> </tr> <tr> <td>Product ID: </td> <td><input type="text" name="name" value="<? echo $name; ?>"></td> </tr> <tr> <td>Short Description: </td> <td><input type="text" name="description" value="<? echo $description; ?>"></td> </tr> <tr> <td>Details:</td> <td><textarea name="details" cols="50" rows="10" ><? echo $details; ?></textarea></td> </tr> <tr> <td>Price for S-XL:<br /> <br /><strong><div id="redfont">**Shirts**<br />&<br />**Hats**</div></strong></td> <td>1-23: <input type="text" name="price" value="<? echo $price; ?>"><br><br> 24-47: <input type="text" name="price2" value="<? echo $price2; ?>"><br><br> 48+: <input type="text" name="price3" value="<? echo $price3; ?>"><br><br> </td> </tr> <tr> <td>Price for 2XL - 5XL:<br /> <br /><strong><div id="redfont">**Shirts ONLY!**</div></strong></td> <td>1-23: <input type="text" name="price4" value="<? echo $price4; ?>"><br><br> 24-47: <input type="text" name="price5" value="<? echo $price5; ?>"><br><br> 48+: <input type="text" name="price6" value="<? echo $price6; ?>"><br><br> </td> </tr> <tr> <td>Minimum QTY: </td> <td><input type="text" name="minimum" value="<? echo $minimum; ?>"></td> </tr> <tr> <td>Sizes:</td> <td><? echo ''; $result = mysql_query("SELECT * FROM sizes"); while ($row = mysql_fetch_assoc($result)) { $selected = ''; $result2 = mysql_query("SELECT * FROM productoptions WHERE productid = '" . $_GET['id'] . "' AND sizeid = '" . $row['id'] . "'"); if ($row2 = mysql_fetch_assoc($result2)) { $selected = 'checked '; } echo '<input type="checkbox" name="size[]" value="' . $row['id'] . '" ' . $selected . '/> ' . $row['size'] . '<br />'; } ?> </td> </tr> <tr> <td>Colors:</td> <td><? $result = mysql_query("SELECT * FROM colors"); while ($row = mysql_fetch_assoc($result)) { $selected = ''; $result2 = mysql_query("SELECT * FROM productoptions WHERE productid = '" . $_GET['id'] . "' AND colorid = '" . $row['id'] . "'"); if ($row2 = mysql_fetch_assoc($result2)) { $selected = 'checked '; } echo '<input type="checkbox" name="color[]" value="' . $row['id'] . '" ' . $selected . '/> ' . $row['color'] . '<br />'; } ?> </td> </tr> <tr> <td> </td> <td><input type="Submit" value="Update this product"></td> </tr> </form> </table> <?php } require("footer.php"); ?> Here is my script: Code: [Select] <?php include("config.php"); include("db.php"); $id=$_POST['id']; $active=$_POST['active']; $cat_id=$_POST['cat_id']; $name=$_POST['name']; $description=$_POST['description']; $details=$_POST['details']; $price=$_POST['price']; $price2=$_POST['price2']; $price3=$_POST['price3']; $price4=$_POST['price4']; $price5=$_POST['price5']; $price6=$_POST['price6']; $minimum=$_POST['minimum']; $arrsizes = $_POST['size']; $arrcolors = $_POST['color']; $image=$_POST['image']; $sql="UPDATE products SET active = '$active', cat_id = '$cat_id', name = '$name', description = '$description', details = '$details', price = '$price', price2 = '$price2', price3 = '$price3', price4 = '$price4', price5 = '$price5', price6 = '$price6', minimum = '$minimum', image = '$image' WHERE id = '$id'"; $result = mysql_query("SELECT id FROM products ORDER BY id DESC LIMIT 0,1"); if ($row = mysql_fetch_assoc($result)) { $productid = $row['id']; } foreach ($arrsizes as $sizevalue) { foreach ($arrcolors as $colorvalue) { $sql2="UPDATE productoptions SET sizeid = '$sizevalue', colorid = '$colorvalue' WHERE productid='$id' "; } } mysql_query($sql) or die ("Error: ".mysql_error()); mysql_query($sql2) or die ("Error: ".mysql_error()); echo $sql; echo $sql2; header("Location: " . $config_basedir . "adminhome.php"); ?> And here is what is echo'd after submit: Code: [Select] UPDATE products SET active = '0', cat_id = '2', name = 'Test Edit Prod', description = 'just a simple test', details = 'just a simple testjust a simple testjust a simple testjust a simple testjust a simple testjust a simple test', price = '1', price2 = '2', price3 = '3', price4 = '4', price5 = '5', price6 = '6', minimum = '127', image = '' WHERE id = '41'UPDATE productoptions SET sizeid = '6', colorid = '5' WHERE productid='41' This part of the code: UPDATE productoptions SET sizeid = '6', colorid = '5' WHERE productid='41' , is supposed to be updating sizes and colors, however, it is only updating the last size/color selected in the check box. Thanks in advance for any support! Below is my php file from my website srcfresno.com/inquiry2.htm When I go to the website and enter information in the form fields, it submits to my email fine but the email I receive has no information filled in. Please help. Not sure why !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>Statistics & Research Consulting</title> </head> <?php $to = 'inquiry@srcfresno.com'; $subject = 'Contact Inquiry form'; $firstname = $_REQUEST['First Name'] ; $lastname = $_REQUEST['Last Name'] ; $from = $_REQUEST['Email'] ; $phone = $_REQUEST['Phone'] ; $company = $_REQUEST['Company Website (if applicable)'] ; $messege = $_REQUEST['Please describe your interest in Statistics & Research Consulting'] ; $fields = array( 'firstname' => 'First Name', 'lastname' => 'Last Name', 'from' => 'Email', 'phone' => 'Phone', 'company' => 'Company Website (if applicable)', 'message' => 'Please describe your interest in Statistics & Research Consulting' ); $body = "We have received the following information from $_SESSION[username]:\n\n"; foreach($_REQUEST as $a => $b){ if(array_key_exists($a, $fields) && !empty($b)){ $part1 .= sprintf("%20s: %s\n", $fields[$a], $b); } $send = mail($to, $subject, $body); if($send) {print "Thank you for contacting us. We have received your information and a SRC Consultant will respond shortly."; } else {print "We encountered an error sending your mail, please notify webmaster@srcfresno.com"; } ?> <body> </body> </html> If my SQL statement returns a result I want to change the background color of a cell. If the user is logged in I want to then show one of two buttons. either book, or cancel, depending on whether the cell is available or not. So far I have this: $sql = "SELECT * FROM diary WHERE day = '$mon' AND studio_id ='mon11'"; $query = mysql_query($sql) or die (mysql_error()); if (mysql_num_rows($query) < 1) { $bgcolour= '#5DFC0A'; if(isSet($_SESSION['logged'])) { $book = '<form action="../book.php" method="POST"><input type="hidden" name="day" value='.$mon.' type="text"/><input type="hidden" name="month" value='.$month.' type="text"/><input type="hidden" name="year" value='.$year.' type="text"/><input type="hidden" name="book_id" value="mon11" type="text"/><input type="submit" name="submit" value="Book!"></form>'; }} else { $bgcolour= '#FF0000'; } if(isSet($_SESSION['logged'])) { $book = '<form action="../cancel.php" method="POST"><input type="hidden" name="day" value='.$mon.' type="text"/><input type="hidden" name="month" value='.$month.' type="text"/><input type="hidden" name="year" value='.$year.' type="text"/><input type="hidden" name="book_id" value="mon11" type="text"/><input type="submit" name="submit" value="Cancel!"></form>'; } echo "<td rowspan='3' bgcolor=".$bgcolour.">"; if (isset($book)) { echo $book; } I want to use the $session(logged) variable to show the appropriate button, but I can't get it to work in the other if statement, Any ideas? I have the following query "select distinct article_author, article_author2 from articles" When I run this it returns two columns. However is there a way in which I can group these two columns into 1 column? Thanks for any help. Hello, Ive got a mysql database but i used a script to add a bunch of file names but it entered with a few errors and theres quite a few that got entered 4-5 times. I can get all the names fine using "SELECT DISTINCT name FROM games" but how can i export all the other fields not just the names. I want to select everything but only DISTINCT on the names Hi everyone, I am working on a website that involves MySQL. Here is the example to my table. field1 | field2 George Fritz | www.fritz.org Linda Gomez | www.gomez.org I need a code, that will fetch field2 of the given field1. For example, if $field1 is George Fritz, the code should return www.fritz.org Any help? Thanks... Funstein Hello. How can I have a single form which has a number of standard fields in it, say date and name.... but for that same date and name I want to add multiple additional entries for say phone calls recieved... (silly example I know) How can I enter the standard data once and an undefined amount of phone calls received ? without having to put a maximum number of possible entry fields on the page.... ? So, say my Form is : <form action="myform.php" method="post"> <p>Date: <input type="text" date="date" /><br /> Name: <input type="text" name="name" /></br> Call From: <input type="text" call_from="call_from" /></br> <p><input type="submit" value="Send it!"></p> </form> If I have 50 calls for that person I only want to enter their name and the date once and then add as many calls as needed... How can I do it? Thanks So im trying to make a sign up forum to where you have to put in your zip code.. and im wanting to make a page to where it shows all the individual zip codes that have register but i dont want mutliples.. for example say i have 5 people register from '90210' and if you go to look at the page where it shows the list of zip codes how could i make it only display '90210' once and not 5 times? im wanting to make this so someone can look at the zip code page and see if anyone near them has registerd on the site as well Thanks Please help me with this: been doing this for 2 days and still cannot solve it. it won't update... I have attached my file: <?php include('connect-database.php'); if (isset($_POST['submit']) AND $_POST['submit'] == 'update') { $error = false; extract($_POST); if (empty($full_name)) $error = true; if (!$error) { $update = "UPDATE users SET full_name = '$full_name', WHERE id=$id "; mysql_query($update) or die(mysql_error() . "<br><br>" . $update); $full_name = ''; $message = "Record successfully updated."; } else { $message = "There is an error in your entry"; } } else { $id = intval(isset($_GET['id']) ? $_GET['id'] : 0); } if ($id == 0) { echo "<div style='margin-bottom:10px'>Invalid ID.</div>"; exit; } $query = "SELECT * FROM users WHERE id=$id"; $result = mysql_query($query) or die(mysql_error() . "<br><br>" . $query); if (mysql_num_rows($result) == 0) { echo "<div style='margin-bottom:10px'>Record Not Found in Database!</div>"; exit; } $row = mysql_fetch_array($result); extract($row); ?> <div id="mainContent" class="tab_container"> <div id="tab1" class="tab_content"> <h1>Edit Personal Data</h1> <div style="color:red;font-weight:bold"><? echo $message; ?></div> <form name="submit" action="" method="post"> <ul> <li><b>ID # :</b> <?php echo $id?></li> <li><b>Name :</b> <input type="text" name="full_name" id="" size="30" value="<?php echo $full_name ?>" /></li> <li><b>Address :</b> <input type="text" name="address" id="" size="55" maxlength="100" value="<?php echo $address ?>" /></li> <li><b>Contact Number :</b> <input type="text" name="contact_number" id="" size="11" value="<?php echo $contact_number ?>" /></li> <li><b>Email Address :</b> <input type="text" name="user_email" id="" size="30" value="<?php echo $user_email ?>" /></li> <li><b>Status :</b> <input type="text" name="status" id="" size="10" value="<?php echo $status ?>" /></li> <li><b>Nationality :</b> <input type="text" name="nationality" id="" size="20" value="<?php echo $nationality ?>" /></li> <li><b>Religion :</b> <input type="text" name="religion" id="" size="20" value="<?php echo $religion ?>" /></li> </ul> <h2>Self Description</h2> <p><textarea rows="9" cols="40" name="self_description" ><?php echo $self_description ?></textarea></p> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <input type="submit" name="submit" value="update" /> </form> </div> Hello everyone I need your assitance a great deal, so I have a form which i submitted to a php file throug ajax and jquery. It is working A ok but I want to be able to submit it with javascript instead, so i don't load any lib. And it is now a problem. The method I use to get the form field names and values in jquery is so simple and dynamic hence if changes are made on the html form i don't have to edit my jquery file to effect the change ie in respect to changing the name of the fields or adding more fields. But I don't know to archieve this using javascript. So i want to post my jquery script, for you all my mighty programmers to assist me get a javascript Clone for me, thank you very much for Helping Jquery file $("form.ajax").on("submit", function(){ var that= $(this); that.find('[name]').each(function(index,value){ var that = $(this), name =that.attr('name'), value =that.val(); data[name]=value; }); return false;}); Now the above code is just my major focus of the script. What it does is that select the form with an ajax class attribute and run a function after the user submits the form. The var that get reference to the above form throug the (this) reference. Next i use find fuction to look through out the open and close of our form.ajax form for any element that has the name attribute and set it into array using the .each(function (index,value){}) this is my main focus how to ilterate through the form looking for name attribute and set my finding into array using javascript. The next that var reference to the find statement and then we steal the name attribute and value from our findings and set an array called data with the stolen name variable as its index n value attribute as its value. Thank you once more my aim again is with the find and array setting statement. |