PHP - Update Single Column In A Single Record?
Hi, I've been scratching my head for a while now about how to do this, I'm relatively new to php and mysql and perhaps foolishly taking on creating a user area for a website. I have everything else working, all of my register account functions and confirmations and all of the login scripts etc.
I have created a profile page which returns various information to the user (this bit works fine) and I've got some nice show/hide toggles running with some javascript/css but my intention is to allow the user to change thier information (e-mail address, contact phone number and also whether they are subscribed to the e-mail list), it also displays any support tickets or messages. So after the long intro, here's what I'm struggling with... I have a form in a visibility toggled <div> which submits a 'change_email' script, so a user wants to change their e-mail, clicks on change, the <div> appears, they bang in the new e-mail and hit submit. My php script appears to work (because it doesn't throw up any errors), until you realise that actually it's not updated the record in the db... I'm using mysql_query("UPDATE users SET email='$new_email' WHERE username='$user'"); Do I need to setup variables for all of the information in the db (name, username, password, email, contno etc etc) and include them in the command to get it to work or should that just pick the correct record and then update it? If that is the case is there a way I can include 'blank' variables so I don't have to set them all up... e.g. mysql_query("UPDATE users SET user='',password='',email='$new_email', etc WHERE username='$user'"); Many thanks in anticipation Similar TutorialsPHP script return 20Â UL LISTÂ values like, < ul >
A < /ul > How to display UL LIST into row wise 5 columns like
A B C D How to pull just I record of a column out of the 20 columns? This is not showing the results. $SomeVar = 'pets'; $query = "SELECT field1 FROM db1 WHERE id1 = '".$SomeVar."'"; $results=mysql_query($link); echo $link; I am having a problem applying pagination to my page when I only have one record displayed. I would like to have it set up to where one record is followed by the next one in the list. I have tried several ways but they are for whole tables moving to the next page. I think I am missing something small but not sure. Any help will be greatly appreciated, thanks. Hi.
I have a product database w/ tables each for product series, model, sub-model and optionals. One item in each of these makes up one product. So Series K, Model 7, sub-model 2, optional 3 will be a product called K 7/2-3 .The permutations and combinations of these are all possible products.
In the same db, I have a quotations table. Each quotation has a unique id / record. A quotation can include any number of products : it can have K 7/2-3, KA 561/1-2 , FPN 311/2-1 or it can only have KA 561/1-2 etc.
Now I am stuck. Don't know how to
a. structure the quotations table
b. create a MySQL select so that one statement can make multiple selections . I thought of using a checkbox but that doesn't work either since the series/model/sub model/optionals must chosen sequentially.
Any ideas I can follow thru ?
Many thanks
Swati
how do I call only a single column in a MySQL? This is not working. $SomeVar = $_POST['finco']; $query = "SELECT * FROM idb WHERE name = '".$SomeVar."'"; $results = mysql_query($query); $psend = $results["fincos"]; echo($psend); I have a mysql table that looks like this: id int(11) autoincrement artist varchar(50) title varchar(50) I need to check for any rows that have the same titles. So for example, if I had the following rows: 1 - Bob - Hello World 2 - Charlie Brown - Theme Song 3 - Joe - Hello World 4 - Joe - Is Cool 5 - Bob - Magic Dude The query would display Row 1, and Row 3 as duplicates. Any idea how I can do something like this? I need to create several buttons that when clicked it updates a field in a table and then passes params to another page (action). I cant seem to figure a logical way of doing this without making things messy, any one have any ideas Hi is it possible to update multiple records of the same table using a single hidden field with a while loop??? For example: Code: [Select] <?php if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE ships SET HealthA=%s WHERE ShipID=%s", GetSQLValueString($_POST['healtha'], "int"), GetSQLValueString($_POST['shipid'], "text")); ?> <input name="healtha" type="hidden" id="healtha" value="<?php echo $row_Ships['HealthA'] + 1; ?>" /> <input name="shipid" type="hidden" id="shipid" value="<?php while($row = mysql_fetch_assoc($Ships)){ echo $row_Ships['ShipID']; }?>" /> If its not possible what else could i do to achieve this please? Thank you Hi, I'm trying to delete a string that's single quoted. From: Cyto's to Cyto, but doesn't work. It works when I add 's to the string with stripslashes, but I can't seem to delete a quote from a string. Does someone know how? My $_post code: Code: [Select] $name=mysql_real_escape_string(stripslashes($_POST["ename"])); Cheers So I'm rebuilding an existing joomla component in laravel and this time I want to get it right. Hopefully my explanation is not too complicated.
I have this situation:
I have an order. The order has many products. The product has many parameters in the form of input fields such as radio, select list and text (think of color, size, engraving, logo select). An order also has some parameters such as address etc.
My question is how I should structure this considering the following:
1. The parameters of either an order itself or a product can change from time to time. Sometimes I need to add several fields for a certain amount of time.
2. Each product has 1 or more production pages (production steps) where some of the parameters set by the order need to be visible. Each production step has its own set of parameters (3d model, logo file). This means that the step1 page should show its own parameters INCLUDING a predetermined set of product parameters. So the columns could look like this: color - engraving - logo select - 3d model - logo file.
3. Each production page lists all the products belonging to that step.
4. Each product can belong to 1 or more production steps.
5. A product is only visible at 1 step at a time. The steps have a specific ordering.
A little note: it's not a usual webshop, but rather we sell custom sports products. Currently we have 3 products where 1 product has 2 production steps and another has 3 production steps.
Don't get me wrong, I have a working application for this, but currently it's just a database mess. The application kept growing as per bosses request so thinking it through was not possible at the time.
At present, all my queries return multiple records. Now I want to do a record count, and only return the one record. Current Code Code: [Select] $query = "SELECT * FROM tblListField WHERE ListID = '" . $_SESSION['listid'] . "'"; $result = mysqli_query($dbc, $query) or die('Error executing SELECT * statement for tblListField - ' . $query); if(mysqli_num_rows($result)) { // at least one row, process the data from the query while ($row = mysqli_fetch_array($result)) { So the above runs through each record; what do I use to get the one record from the following SQL? (Note; I'm using mysqli_) Code: [Select] $query = "SELECT COUNT(ItemField_1) WHERE ListID='" . $listid . "'"; I want to use all five results separately in order to use in a Jquery slider. Code: [Select] <?php $a = "SELECT * FROM blog_posts ORDER BY id DESC LIMIT 5"; $query = mysql_query($a) or die (mysql_error()); $query_results = mysql_fetch_array($query); ?> I know if i was going to grab vars from an normal array i would just use... Code: [Select] <?php echo $array_reults['0'] ?> Can any one help me with this problem? Greetings, I'm trying to execute a shell command with a user-supplied password as input. The password may contain apostrophes and and virtually any other character. Unfortunately, when using escapeshellarg(), the password argument is interpreted as two separate arguments, as escapeshellarg() will handle apostrophes (single quotes) by breaking out of the already quoted text and using a backslash escape. $password = escapeshellarg("ex'ample!%"); // The password will actually be supplied by an HTML form. $command = ('echo '.$password); echo "$command"; // Returns 'ex'\''ample!%' Does anyone have any input on how to accomplish what I'm trying to do? I'd like to allow obscure passwords without disallowing specific characters, while still being "safe" in passing the information to a shell command. Double quotes would work for passing single quotes, but I'm afraid I might break other characters there. Thanks. Hi, learning as I go here, and I appreciate the help in advance .. I have some working php code that retrieves sql results using php. I assign the resutls to an array by doing this $bobreport = array(); while ($row=db2_fetch_array($querystmt)) { array_push($bobreport, $row); } i can then write the rows of returned data after some column headers using this... foreach ($bobreport as $value) { echo "<tr><td>$value[0]</td><td>$value[1] ..... } The particular report I'm working on now has a redundant date and time in every row that I omit in the foreach loop because I just want to show it once above the table somewhere. This doesn't seem to work in accomplishing that... echo "This data was updated ".$bobreport[0][9]." at ".$bobreport[0][10] ; All I seem to get in the report is "This data was updated at". Please help. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358810.0 Hello, I have a simple multiple-step form and I use sessions to save the data. Now i have 1 single checkbox and i would like to know how i can save that data (if one checked it or not). I am not very advanced with sessions, nor PHP, thus i tried the following: Code: [Select] if (isset($_POST['newsletter'])) { $_SESSION['newsletter']=$_POST['newsletter']; } $newsletter = $_SESSION['newsletter']; // do not really know what if statement to use if($newsletter == 'yes') { $newsl = '1'; } //checkbox html here <input type="checkbox" class="styled" name="newsletter" value="yes" /> Obviously the above won't work. Can explain to me how to save checkbox data in a session? Thanks a lot in advance. hey everyone will you please assist. I'm getting data from a mysql database. And I want to assign the data to a single value, if possible For example, in my database I have 2 columns, name and group Lets say John, Peter and Cathy belongs to group 555, where Sally and Marcus belongs to group 777. So my sql query outputs all users in group 555 Is there a way to assign the search result to a vlue, for example $result = ??? and If I said echo $result, it should show the users who belongs to group 555 as an example. I tried to use row[Name][1]; but it doesnt work. The thing is, I can display the data the way I am familiar with, but I'm sending an automated email to myself, containing the users. So if I would used a for each statement, the mail will trigger and send a copy for every count, in this case, 3 times. And thats my huge problem. The mail must trigger only once, containing the users in my search query, in this case, group 555. Any help will be appreciated Thank you Could somebody please point me in the right direction.... I want to block the US, AUS, NZ, CAN, IRE from the index.php of my site. But not the rest of the site. The following site (like many others) provides a pretty neat list for the htaccess http://www.ipinfodb.com/ip_country_block.php I did a test. I got the list for blocking the UK. After copying the UK list to my htaccess i couldn't view my site. The thing i don't get is... my ip address was not in the list but i was still blocked, The 1st 2 sets from my ip are '2.100' The only ip's in the list starting with 2 a deny from 2.24.0.0/13 deny from 2.96.0.0/13 deny from 2.120.0.0/12 deny from 2.136.0.0/13 How exactly is this all working? And what's the best way of blocking the above countries from just my index.php? Any links to manuals or anything here would be great... Thank You. John Hi All Sorry my first post is a help one... I'm developing a small fault logging application I need a little help with. This is my code at the moment Client Table Columns contractid, company, branch, addressline1, addressline2, addressline3, addressline4, postcode, contactname, telephone, email Addressbook2 Table Columns nameid, namecompany, namecontactname, nameaddressline1, nameaddressline2, nameaddressline3, nameaddressline4, namepostcode, nametelephone1, nametelephone2, nameemail, <?php $NodeTitles = mysql_query("SELECT * FROM faults, users, clients, addressbook2 WHERE faults.client = clients.contractid AND faults.referredby = addressbook2.nameid AND faults.openedby = users.userid ORDER by dateopened DESC, timeopened DESC") or die (mysql_error()); while ($row = mysql_fetch_assoc($NodeTitles)) { ?> <tr id="entryRow2358" onMouseOver="this.style.cursor='pointer'" onclick="window.location.href='job.php?faultid=<?php echo $row['faultid'];?>';"> <td class="n" colspan="1"><div title=""><?php echo $row['faultid'];?></div></td> <td class="" colspan="1"><div title="Company"><?php echo $row['clientcompany'];?></div></td> <td class="" colspan="1"><div title="Referrer"><?php echo $row['referrercompany'];?></div></td> <td class="" colspan="1"><div title="Branch"><?php echo $row['clientbranch'];?></div></td> <td class="" colspan="1"><div title="Fault"><?php echo $row['fault'];?></div></td> <td class="" colspan="1"><div title="Opened By"><?php echo $row['fullname'];?></div></td> <td class="" colspan="1"><div title="Date Created"><b><?php $date = date_create($row['dateopened']); echo date_format($date, 'j F Y');?></b> <span><?php echo $row['timeopened'];?></span></div></td> </tr> <?php } ?> QUESTION TIME I want to make this much cleaner and tidier (and also more future proof) by removing the clients table so that I only have one 'addressbook' (this will contain clients, referrers, engineers ... and any other correspondents) Naturally I will have a column in the address book to tell me what type of correspondent the name is. ie. 1 = Client, 2 = Referrer, 3 = Engineer. So.......will I have to do many MYSQL queries within a while statement or will I be complicating the entire process by doing this? Can I write a single SQL statement to do this? Any advise or help with my code would be great! Thanks Andrew Hi all, Just to check if it is possible to have 2 while loops in a single code? Below are my codes. SQL code $tutor_id = mysqli_real_escape_string($dbc, $_GET['tutor_id']); $query = "SELECT tl.level_id, tl.level_name, ts.subject_id, ts.subject_name, tsl.subject_level_id, IF(tosl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl INNER JOIN tutor_subject_level AS tsl USING (level_id) INNER JOIN tutor_subject AS ts USING (subject_id) LEFT JOIN tutor_overall_level_subject AS tosl ON tosl.subject_level_id = tsl.subject_level_id AND tosl.tutor_id = '{$tutor_id}' ORDER BY tl.level_id, ts.subject_name"; $sql = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); $query1 = "SELECT tl.level_id, tl.level_name, IF(tslvl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl LEFT JOIN tutor_selected_level AS tslvl ON tslvl.level_id = tl.level_id AND tslvl.tutor_id='{$tutor_id}' ORDER BY tl.level_id, tl.level_name"; $sql1 = mysqli_query($dbc, $query1) or die(mysqli_error($dbc)); PHP code (2 while loops) //Process the results $checkboxes = ''; //Create variable for output $current_level_id = false; //Flag to check when records change level while($data = mysqli_fetch_array($sql)) //Iterate throug the DB results { if($current_level_id != $data1['level_id']) //Determine if this level is different from the last { print_r ($data); $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $current_level_id = $data['level_id']; $subject_data = array(); } //Add the current record to the $level_data array $subject_data[] = $data; } //$checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); while($data1 = mysqli_fetch_array($sql1)) { print_r ($data1); $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $level_data = array(); $level_data[] = $data1; } //Call the createLevelCheckboxes() function to generate the HTML for the LAST level records $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); |