PHP - Update A Field In A Record When Value Selected From Dropdown List
Yesterday, I created a topic about how I could update records and I managed to achieve that successfully.
Now I have another dilemma. When I have a specific record I want to update, I want to change a category ID of an product (e.g. change it from 1 to 2) but how do I go about doing this? Here is my code thus far: Code: [Select] <?php require_once ('./includes/config.inc.php'); require_once (MYSQL); $id=$_GET['prodID']; $results = mysqli_query($dbc, "SELECT * FROM product WHERE prodID=".$_GET['prodID'].""); $row = mysqli_fetch_assoc($results); ?> <form action="" method='POST'> Product ID: <input type="text" value="<?php echo $row['prodID'];?>" name="prodID" /> <br /> Product: <input type="text" value="<?php echo $row['product'] ;?>" name="product" /> <br /> Product Description: <input type="text" value="<?php echo $row['prod_descr'] ;?>" name="prod_descr" /> <br /> Category: <select name="category"> <option value="<?php echo $row['catID'];?>"></option> </select> Price: <input type="text" value="<?php echo $row['price'] ;?>" name="price" /> <br /> In Stock: <input type="text" value="<?php echo $row['stock'] ;?>" name="stock" /> <br /> <br /><input type="submit" value="save" name="save"> </form> <?php if(isset($_POST['save'])) { $id = $_POST['prodID']; $product = $_POST['product']; $descr = $_POST['prod_descr']; $price = $_POST['price']; $stock = $_POST['stock']; // Update data $update = mysqli_query($dbc, "UPDATE product SET product='$product', prod_descr='$descr', price='$price', stock='$stock' WHERE prodID=".$_GET['prodID'].""); header( 'Location: update_save.php' ) ; } ?> Similar Tutorialsi have the following code: <td width='100px'>Suppliers <select name="supplier"> <?php $catcher_id = $service->getCatcherId(); $supplier_names = LpmAdnetworkPeer::getByName($catcher_id); foreach($supplier_names as $row) { ?> <option><?php echo $row->getName(); ?></option> <?php } ?> </select> </td> then on the same form i have a submit button that takes me to the next form..the problem now is how can i access the ID of the item seleted in the dropdown on the NEXT form please? i can get the name from the list by $_POST['supplier'] on the next form thanks i skipped solving this the other day with an easier way but now i am stuck with this stumble again in another area and i have no way out.... so here it goes, i have an ajax dropdown box...i need to get the value that is selected by the user when it is clicked and then pass this value to a new pop window by appending to its url....any suggestions? Hey Everyone... First off, I am only a young web developer and i'm working on a school project and am making a text-based game online... Now what i'm having trouble with... I want a drop-down list that has a list of characters classes Clubber Mixer Sauceror Tamer And I want whatever is selected to be placed into the database along with the username/password (THIS ALL WORKS FINE JUST NOT THE DROP DOWN LIST) All help appreciated So I've been attempting to create a dropdown list that will post to mySQL. The problem I'm running into is the way I populate the dropdown I can't figure out how to return the selected option to mySQL. <form name="pentry" method="post" action="" action="pentry.php"> <input name="username" type="hidden" value="<?php echo "$username"?>"> Date of Practice:<input type="text" id="dates" name="practdate" datepicker="true" datepicker_format="YYYY-MM-DD" maxlength="100"><br> <?php $query="SELECT eoptions,id FROM sm_options"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo "<select name=eoptions value=''>Event Options</option>"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value=$nt[id]>$nt[eoptions]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box mysql_close(); ?><br> Event:<input type="text" name="event" maxlength="100" value="<?php echo "test $output" ?>"><br> Session Time:<input type="text" name="practtime" id="practtime">min. <input type="button" value=" + " onClick="addmin(practtime);"> <input type="button" value=" - " onClick="submin(practtime);"><br> Practice Content:<input type="text" name="practnotes"><br> <input type="submit" name="submit" value="Submit"><br> </form> I've been moving code around trying to solve the problem so its a bit messy. Hi How are you all, I will explain me issue one by one first of all I have created a mysql database ((ftest)) and it contain a table ((test1)) and that table contin a filed ((name)) In that filed I have 3 names 1- James 2- Moly 3- Cris let's start with the first file I have it's the config.php which will connect to the mysql database second we have index.php which contain Code: [Select] <?php /////////////////////////////////////////////////////////////////////////////// require_once "easytemplate.php"; $easy = new EasyTemplate(); $easy->Temp = 'template'; $easy->Cache = 'easycache'; include 'config.php'; /////////////////////////////////////////////////////////////////////////////// $e = mysql_query("select name from test1"); while ($row = mysql_fetch_array($e)) { extract($row); $name = $row ['name']; print $easy->display("html.tpl"); } ?> As you can see I'm defining Code: [Select] require_once "easytemplate.php"; which is a normal Template Engine anyway It will extract all the 3 names then it will call html.tpl which contain the html design code let's see what the html.tpl contain Code: [Select] <form action='main.php' method=post> <head> <meta http-equiv="Content-Language" content="en-us"> </head> <p><font color="#FF0000"><span style="background-color: #FFFFFF">{name}</span></font></p> <input type="checkbox" name="name" value="{name}"> <input type="submit" name="submit" value="submit" /> </form> No I will run the Index.php file to see how it looks with the template file (html.tpl) this is the snapshot from the browser What I want exactly if I did check more than one name for example Cris and Moly and then press any of the submit buttons I want the names ((Cris & Moly) to be printed in the next page which is main.php Code: [Select] <?php /////////////////////////////////////////////////////////////////////////////// include 'config.php'; /////////////////////////////////////////////////////////////////////////////// if(isset($_POST['name'])) $names = $_POST['name']; if ($_POST){ echo $names; } ?> Now It will work but it will print only one name thank you for your time Hi freaks, I'm new to php first of all. I'm dynamically binding a dropdownlist with mysql database . After the user selects an item from it , I want to match that item with another table so as to populate another database. The code I'm using to populate dropdown: Code: [Select] <?php $con = mysql_connect("localhost","root",""); if(!$con) { die ('Can not connect to : '.mysql_error()); } mysql_select_db("ims",$con); $result=mysql_query("select cat_id,cat_name from category"); echo "<select name=cat>"; while($nt=mysql_fetch_array($result)) { echo "<option value=$nt[cat_id]> $nt[cat_name] </option>"; } echo "</select>"; mysql_close($con); ?> Now after the user selects any one of the item , I want to bind another dropdown on the same page using such query like $result=mysql_query("select subcategory.sc_id,subactegory.sc_name from subcategory,category where subcategory.sc_id=$nt[cat_id]"); Please anyone tell me the logic and code to do it. Also tell me do I need an intermediate page to post the 1st dropdown value and then continue with 2nd dropdown. I couldn't figure out the concept anyhow. Help on this will be highly appreiable . (Tell me if I'm not clear with my question) Hi i have this simple update form and scrip but somehow it doesnt seem to be update the field on the database can someone help out please. The html form is the second form bellow where the action send to status_update.php HTML FORM Code: [Select] <?php include("../header.html"); ?> <?php include("header_news.html"); extract($_REQUEST,EXTR_SKIP); ?><?php /* print("sfilm_refnum = $sfilm_refnum<BR>"); print("sfilm_addr01 = $sfilm_addr01<BR>"); print("sfilm_postcode = $sfilm_postcode<BR>"); print("Film Client = $fclient<BR>"); */ ?> <form id="search" action="list.php" method="post" name="search"> <table width="780" border="0" cellspacing="0" cellpadding="4" bgcolor="#eeeeee"> <tr> <td align="right" width="140"></td> <td width="320"><span class="hofblack10"> </span> </td> <td align="center" width="100"><input type="hidden" name="lstart" value="<?php print("$lstart"); ?>" /><input type="hidden" name="lend" value="<?php print("$lend"); ?>" /><input type="hidden" name="lamount" value="<?php print("$lamount"); ?>" /></td> <td align="center" width="100"></td> <td align="right"></td> </tr> </table> </form> <table width="780" border="0" cellspacing="0" cellpadding="4" bgcolor="#4050c4"> <tr> <td width="60" class="hofwhite10">action</td> <td width="140"><span class="hofwhite14">DATE</span></td> <td width="80"><span class="hofwhite14">ID</span></td> <td><span class="hofwhite14">News Titile</span></td> <td width="100"><span class="hofwhite14">Status</span></td> </tr> <tr height="0"> <td bgcolor="white" width="60"></td> <td bgcolor="white" width="140" height="0"></td> <td bgcolor="white" width="80" height="0"></td> <td bgcolor="white" height="0"></td> <td bgcolor="white" width="100" height="0"></td> </tr> </table><table width="780" border="0" cellspacing="0" cellpadding="4"><tr> <td width="60"></td> <td width="80"></td> <td><a class="blueullrg" href="add.php">Add News</a></td> <td align="right" width="120"></td> </tr> <tr height="0"> <td width="60" height="0"></td> <td width="80" height="0"></td> <td height="0"></td> <td align="right" width="120" height="0"></td> </tr> </table> <?php //get the DB connection variables include("../../../includes/config.php"); //connect to DB $connection = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select DATABASE."); $query2="SELECT * FROM news WHERE !(news_status='deleted')"; $result2 = mysql_query($query2) or die("Couldn't execute QUERY - Select NEWS Qty"); $fqty = mysql_num_rows($result2); //SELECT or FIND the same USERNAME $query3="SELECT * FROM news WHERE !(news_status='deleted') ORDER BY news_id DESC"; $result3 = mysql_query($query3) or die("Couldn't execute QUERY - Select NEWS"); while ($row = mysql_fetch_array($result3)) { $news_id = $row['news_id']; $news_title = $row['news_title']; $news_story = $row['news_story']; $news_image = $row['news_image']; $news_image_caption = $row['news_image_caption']; $news_image_link = $row['news_image_link']; $news_date_day = $row['news_date_day']; $news_date_month = $row['news_date_month']; $news_date_year = $row['news_date_year']; $news_status = $row['news_status']; $news_website = $row['news_website']; $news_date_created = $row['news_date_created']; $news_date_modified = $row['news_date_modified']; ?> <table width="780" border="0" cellspacing="0" cellpadding="4" bgcolor="#eeeeee"> <tr> <td width="60"><span class="hofblack10"> <?php if($news_status=="deleted"){ print("<a class='hifblack10'>deleted</span>"); }ELSE{ print("<a class='blueul' href='edit.php?id=$news_id'>edit</a>"); } ?> </span></td> <td width="140"><span class="titlegrey12"> <?php if(!$news_date_day) { echo "00"; } else{ echo $news_date_day; } echo "/"; if(!$news_date_month) { echo "00"; }else{ echo $news_date_month; } echo "/"; if(!$news_date_year) { echo "0000"; }else{ echo $news_date_year; } ?> </span></td> <td width="80"><span class="titlegrey12"><?php print("$news_id"); ?></span> </td> <td><?php if($news_status=="deleted") { print("<class='hofblack10'>$news_title</span>"); }ELSE{ print("<a class='blueul' href='edit.php?id=$news_id'>$news_title</a>"); } ?></td> <td width="100"> <form id="list_update" action="status_update.php" method="post" name="list_update"> <select name="newnstatus" size="1"> <option <?php if($row['news_status'] == "") { print("selected"); } ?> selected="selected" value="">Status...</option> <option <?php if($row['news_status'] == "on") { print("selected"); } ?> value="on">On</option> <option <?php if($row['news_status'] == "off") { print("selected"); } ?> value="off">Off</option> <option <?php if($row['news_status'] == "deleted") { print("selected"); } ?> value="deleted">Delete</option> </select> <input type="hidden" name="nstatus" value="<?php echo $row[news_status]; ?>" /> <input type="hidden" name="id" value="<?php echo $row[news_id]; ?>" /> <input type="submit" name="update" value="update" /> </form> </td> </tr> <tr height="0"> <td bgcolor="white" width="60"></td> <td bgcolor="white" width="140" height="0"></td> <td bgcolor="white" width="80" height="0"></td> <td bgcolor="white" height="0"></td> <td bgcolor="white" width="100" height="0"></td> </tr> </table> <?php } mysql_close($connection);//}?> <table width="780" border="0" cellspacing="0" cellpadding="4"> <tr> <td width="60"></td> <td width="80"></td> <td><a class="blueullrg" href="add.php">Add News</a></td> <td align="right" width="120"></td> </tr> </table><?php // include("list_navigation.html"); ?> <?php include("../footer.html"); ?> </div></body></html> The action script php Code: [Select] <?php /* echo "fstatus: ".$fstatus."<BR>"; echo "id: ".$id."<BR>"; echo "fclient: ".$fclient."<BR>"; echo "newfstatus: ".$newfstatus."<BR>";*/ //set the date of agreement $timestamp = date('l jS \of F Y h:i:s A'); //get the DB connection variables include("../../../includes/config.php"); //connect to DB $connection = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select FILMS DATABASE."); // All appears well, so enter into database $query= "UPDATE news SET news_status = '$newnstatus' WHERE news_id='$id'"; $result = mysql_query($query) or die("could not execute query - Update FILMS Record to DB"); //setup an email to the Admin @ hof, w/o attachment $emailto="xx@xxx.co.uk"; $emailfrom="no-reply@xxxx.co.uk"; $emailsubject="xx Record Updated"; $emailmessage="Hello Registrar\n\n"; $emailmessage.="News ID: ".$id."\n"; $emailmessage.="Updated on: ".$timestamp."\n\n"; $emailmessage.="Status was: ".$nstatus."\n"; $emailmessage.="Status now: ".$newfnstatus."\n"; $emailmessage.="Thank you,\n\n"; $emailmessage.="Web Site ROBOT\n"; $emailmessage.="(Administrator)\n"; $emailmessage.="xxx.co.uk | xxx.biz\n"; $emailmessage.="----------------------------------------------\n"; $emailmessage.="e. http://www.xxx.co.uk/contact.php\n"; $emailmessage.="w. http://www.xxx.co.uk\n"; $emailheader="From: xxx.co.uk<$emailfrom>"; $emailheader .= 'Cc: xxx@xxx.co.uk'."\r\n"; $emailheader .= 'Bcc: xxx@xxxxx.co.uk'."\r\n"; $ok=mail($emailto,$emailsubject,$emailmessage,$emailheader); mysql_close($connection); if ($ok) { header("Location: list.php"); /* Redirect browser */ exit; } else { $errmsg="There was a problem, please try later or telephone us direct."; $errsta="1"; include("edit_error.html"); //echo "<p>Mail could not be sent. Sorry!</p>"; exit; } ?> Thanks in advance Hi guys, Doing a small project and i'm pretty new to php/mysql so hoping someone can help. Also i wasn't sure if this should be in php section or mysql, so apologises if it's in the wrong section. Basically... I have a form with a table in it with the fields (id, model, current stock level, new stock level) The table is populated using a mysql query to get the data from 1 table in a database. In the new stock column there's a simple text box to put a number in. Sooo like (ID) (Model) (current stock level) (new stock level) 1 AAA 3 [ ] 2 BBB 1 [ ] 3 CCC 4 [ ] A user will then put a new number in the 'new stock level' text box and when it gets submitted the new number replaces the number in 'current stock level' Basically i know how to do it if it was just the one record, but how do i get it to update all the ones with numbers in the new stock level column at the same time, and ignore it if it doesn't have anything entered in the text box? appreciate any help! thanks! My form has 40 fields, and I want to re-generate it to be reviewed as it was when submitted. Next, I want to be able to UPDATE the forms values, where necessary. Is there an easy way to UPDATE the entire form from the reviewable version. Is it smarter to update ONLY the specific items that need modification? Any examples would be helpful. Hi, I have a simple mySQL database and I would like to update using a simple html form. One of the field is "accepted" and is type "boolean". I have a texbox where I will write the record id and another button which will change the "accepted" value from 0 to 1 for that record id. The problem is that I don't know how to start.... Thanks in advance Sergio I'm having an issue updating a records. The insert and delete functions are working fine. The $submit variable is being passed 'Update' ~ that is working. This is some extremely old code that has migrated to a new server and is no longer working. Code: [Select] <?php $id = $_GET["id"]; $delete = $_GET["submit"]; $sortorder = $_POST["sortorder"]; $name = $_POST["name"]; $content = $_POST["content"]; $submit = $_POST["submit"]; require'../include/maindb.php'; if($submit=="Submit") { $sql="INSERT INTO biography (id, sortorder, name, content) VALUES (NULL, '".$sortorder."', '".nl2br(addslashes(trim($name)))."', '".htmlentities(addslashes(trim($content)))."')"; } if ($submit == "Update") { $sql="UPDATE biography SET sortorder='".$sortorder."', name='".nl2br(addslashes(trim($name)))."', content='".htmlentities(addslashes(trim($content)))."' WHERE id='".$id."'"; } if ($delete=="Delete") { $sql="DELETE FROM biography WHERE id='".$id."'"; } mysql_query($sql); echo(mysql_error()); header('Location: index.php'); ?> Code: [Select] $new_array2=array_diff($my_array,$itemIds); $updatedb = mysql_query("UPDATE content_type_ads SET field_expire_value = '666' WHERE $new_array2 = field_item_id_value"); "$new_array2" has only 12 digit numbers for each item in the array, and I want to match them to the "field_item_id_value" field in the table, updating the "field_expire_value" field for the record where they match. I know I am close because the UPDATE code works before I add the WHERE statement (it of course adds '666' to EVERY field, but for a noobie it's a start!). Hi all, Im having some trouble trying to update my table using an array, It processes and doesnt throw up any errors so im at a loss as to whats happening as its not updating my table? my page is Code: [Select] mysql_select_db($database_saucy_connection, $saucy_connection); $query_allphotos = "SELECT * FROM model_login, model_pictures WHERE model_pictures.user_id=model_login.id"; $allphotos = mysql_query($query_allphotos, $saucy_connection) or die(mysql_error()); $row_allphotos = mysql_fetch_assoc($allphotos); $totalRows_allphotos = mysql_num_rows($allphotos); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Id</strong></td> <td align="center">Picture Name</td> <td align="center">Upload Date</td> <td align="center"><strong>No Downloads</strong></td> <td align="center"> Approved? </td> <td align="center"> Hunnies Gallery </td> <td align="center"> Hunks Gallery </td> <td align="center"> Default Pic </td> <td align="center"> Theme Pic </td> <td align="center"> Homepage Pic </td> </tr> <?php while($rows=mysql_fetch_array($allphotos)){ ?> <tr> <td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td> <td align="center"><? $user_picture[]=$rows['user_picture']; ?><?php echo $rows['user_picture']; ?></td> <td align="center"><? $user_picture_date[]=$rows['user_picture_date']; ?><?php echo $rows['user_picture_date']; ?></td> <td align="center"><? $picture_downloads[]=$rows['picture_downloads']; ?><?php echo $rows['picture_downloads']; ?></td> <td align="center"><? $user_pic_approval[]=$rows['user_pic_approval']; ?><?php echo $rows['user_pic_approval']; ?> </td> <td align="center"><? $hotties_gallery[]=$rows['hotties_gallery']; ?><?php echo $rows['hotties_gallery']; ?> </td> <td align="center"><? $hunks_gallery[]=$rows['hunks_gallery']; ?><?php echo $rows['hunks_gallery']; ?> </td> <td align="center"><? $default_pic[]=$rows['default_pic']; ?><?php echo $rows['default_pic']; ?> </td> <td align="center"><? $theme_gallery[]=$rows['theme_gallery']; ?><?php echo $rows['theme_gallery']; ?> </td> <td align="center"><? $homepage=$rows['homepage_pic']; ?><?php echo $rows['homepage_pic']; ?> </td> </tr> <?php } ?> <tr> <td colspan="5" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE $model_pictures SET user_pic_approval='$user_pic_approval[$i]', hotties_gallery='$hotties_gallery[$i]', hunks_gallery='$hunks_gallery[$i]', default_pic='$default_pic[$i]', theme_gallery='$theme_gallery[$i]', homepage_pic='$homepage_pic[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } There are 50 csv files. each csv file have the same column's name. some content in the column are the same, some don't. eg:test1.csv, example1.csv, hello.csv, world.csv.......test70.csv. now, i want to make a change to two column's content. a, all csv files have a column named qty. whose rows content are all 0. now, i want to change it into Code: [Select] 888 b, all csv files have a column named image. whose rows content are all Code: [Select] upload/img1.jpg upload/img2.jpg upload/img3.jpg upload/img01.jpg upload/img14.jpg upload/img01.jpg .......If i open each csv file then do a search and replace. i fell it too bored. Thank you in advance. i want to delete Uploadin the image column, change 0 to 888 in the qty column. i using the file change.php to update the record. one csv file. http://phplist.xxmn.com/women.csv the code: Code: [Select] <?php $dir = getcwd(); $files = array_diff(scandir($dir), array('..', '.','change.php')); foreach ($files as $file) { if (($handle = fopen($file, "r")) !== FALSE) { $new_content = ''; while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) { //var_dump($data); $data[2]=888; $new_content .= implode(',', $data); //var_dump($new_content); } file_put_contents($file, $new_content); echo 'down'; } } ?> the code doesn't work how to correct it . thank u Thanks for reading my post. How can I update the ten rows from MYSQL Thanks in advance Hi, I am trying to update the status of the record. I don't want to insert the record if not exists. I just want to know the update is success or not. I tried using affected_rows but it returns 0 if the existing status is same as the new status or if no record exists. Please help. Anyone have any idea what I did wrong this time? This is def where my problem is Code: [Select] // UPDATE THE RECORD WITH THE CURRENT FORM DATA $edit_query_insert="UPDATE client_information SET account_number = '$account_number', name_first = '$name_first', name_last = '$name_last', address = '$address', city = '$city', state = '$state', zipcode = '$zipcode', telephone = '$telephone', telephone_alt = '$telephone_alt', email = '$email'"; This is the code for the page itself: Code: [Select] // SELECT THE DATABASE mysql_select_db("terra_elegante_operations", $con); // GET THE FORM DATA FROM PREVIOUS PAGE // ASSIGN NEW VARIABLES $account_number = $_POST['account_number']; $name_first = $_POST['name_first']; $name_last = $_POST['name_last']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zipcode = $_POST['zipcode']; $telephone = $_POST['telephone']; $telephone_alt = $_POST['telephone_alt']; $email = $_POST['email']; // UPDATE THE RECORD WITH THE CURRENT FORM DATA $edit_query_insert="UPDATE client_information SET account_number = '$account_number', name_first = '$name_first', name_last = '$name_last', address = '$address', city = '$city', state = '$state', zipcode = '$zipcode', telephone = '$telephone', telephone_alt = '$telephone_alt', email = '$email'"; if (!mysql_query($edit_query_insert,$con)) { die('Error: ' . mysql_error()); } ?> <table border="0" cellspacing="0" cellpadding="3" width="960" bordercolor="#000000"> <tr> <td valign="top" width="50%"><!-- Open Main left Cell --><table border="0" cellspacing="0" cellpadding="1" width="100%" bordercolor="#000000"><tr><td colspan="4"><B>CLIENT PROFILE</B></td></tr> <?php // Query & assign to the $client_information table. $get_client_information = "SELECT * from client_information where account_number = $account_number"; $client_information = mysql_query($get_client_information) or die (mysql_error()); // The Array & Output - Included HTML Output here for $client_information while ($row = mysql_fetch_array($client_information)) { ?> <tr> <td width="30%"><font face="verdana" size="2" color="#000000">Account Number:</font></td><td colspan="2"><font face="verdana" size="2" color="#000000"><?php echo $row['account_number']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">Last Name:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['name_last']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">First Name:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['name_first']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">Address:</font></td><td><font face="verdana"size="2" color="#000000"><?php echo $row['address']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">City:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['city']; ?></font></td> </tr> <tr> <td width="10%"><font face="verdana" size="2" color="#000000">State:<font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['state']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">Zipcode:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['zipcode']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">Telephone:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['telephone']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">Telephone 2:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['telephone_alt']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">E-mail</td></td><td><font face="verdana" size="2" color="#000000"><?php echo "<a class=\"bubble_nav\" href='mailto:?id=$row[email]'>$row[email]</a\>"; } ?></font></td> </tr> </table> <?php include('includes/footer.php'); ?> Not sure how to update a record in my table here. I got my insert and delete statement working. Just can't get the update to work correctly. I'm not really sure how to do it. Here is my code for my page, and my update and delete page Code: [Select] <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); require_once('database.php'); session_start(); if (isset($_POST['add_grade'])) { $query = "INSERT INTO grades (grade_id, student_id, grade_type, grade_name, grade_points) "; $query .= "VALUES (:grade_id, :student_id, :grade_type, :grade_name, :grade_points) "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $_SESSION['student_id']); $statement->bindValue (':grade_id', $_SESSION['grade_id']); $statement->bindValue (':grade_type', $_POST['grade_type']); $statement->bindValue (':grade_name', $_POST['grade_name']); $statement->bindValue (':grade_points', $_POST['grade_point']); $statement->execute(); $statement->closeCursor(); $grade_type = $_POST['grade_type']; if ($grade_type == 'Lab') { $final *= .60; } echo $final; $grade_type = $_POST['grade_type']; if ($grade_type == 'Mid-Term') { $final *= .20; } echo $final; $grade_type = $_POST['grade_type']; if ($grade_type == 'Final') { $final *= .20; } echo $final; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>View Course Grades</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <?php $student_name = $_SESSION['student_name']; $student_id = $_SESSION['student_id']; $query = "SELECT * FROM grades WHERE student_id = :student_id "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $student_id); $statement->execute(); $grades = $statement->fetchAll(); $statement->closeCursor(); echo "<h1>Show Grades for $student_name </h1>"; foreach ($grades as $grade) { echo $grade['grade_type'] . " " . $grade['grade_name']. " " . $grade['grade_points'] . "<br />"; } ?> <div id="content"> <!-- display a table of products --> <table> <tr> <th>Grade Type</th> <th>Grade Name</th> <th>Grade Points</th> <th>Remove</th> </tr> <?php foreach ($grades as $grade) : ?> <tr> <td><?php echo $grade['grade_type']; ?></td> <td><?php echo $grade['grade_name']; ?></td> <td><?php echo $grade['grade_points']; ?></td> <td><form action="delete_grade.php" method="post"> <input type="submit" name="remove" value="Delete" /> </form></td> </tr> <?php endforeach; ?> </table> </div> </div> <div id="footer"> </div> <form name="grades" method="post" action="grades.php"> <p>Grade Type<SELECT NAME="grade_type"> <OPTION VALUE="Mid-Term">Mid-Term <OPTION VALUE="Final">Final <OPTION VALUE="Lab">Lab </SELECT> <br> Grade Name:<input type="text" name="grade_name" value=""><br /> Grade Points:<input type="text" name="grade_point" value=""> <input type="submit" name="add_grade" value="Add Grade"> </form> </table> </body> </html> My delete and update page Code: [Select] <html> <head> <title>Delete Grade</title> </head> <body> <form method="post" action="delete_grade.php"> <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $dbc = mysqli_connect('localhost', 'se266_user', 'pwd', 'se266') or die(mysql_error()); //delete grades if (isset($_POST['remove'])) { foreach($_POST['delete'] as $delete_id) { $query = "DELETE FROM grades WHERE grade_id = $delete_id"; mysqli_query($dbc, $query) or die ('can\'t delete user'); } echo 'user has been deleted.<br />'; } if (isset($_POST['update'])) { foreach($_POST['update'] as $update_id) { $query = "UPDATE grades SET grade_id = $grade_id"; mysqli_query($dbc, $query) or die ('can\'t update user'); } } //Display grade info with checkbox to delete $query = "SELECT * FROM grades"; $result = mysqli_query($dbc, $query); while($row = mysqli_fetch_array($result)) { echo '<input type="checkbox" value="' .$row['grade_id'] . '" name="delete[]" />'; echo ' ' .$row['grade_type'] .' '. $row['grade_name']; echo '<br />'; } mysqli_close($dbc); ?> <input type="submit" name="remove" value="Remove" /> <input type="submit" name="update" value="Update" /> </form> </body> </html> Hello,
Anyone can suggest me what is the best way to update table records. I'm kinda scared to make an update on a table because it may damage the system and I am not really good on SQL commands.
Right now I just made a process on PHP to update table records. It does update email records on but it stop because of the limit of loading the page. Is there anyway accurately update all the data of the table.
Here is what I want to achieve.
I have a table with an "email" field on it, those email data from "email" field on tb_one must be change to cID records base on tb_two.
tb_one
Field =
- id
- email
- etc.
tb_two
Field =
- id
- email (same as on tb_one)
- cID
|