PHP - Lots Of Duplicate Rows With An Update?
My site seems to be going well, but on the back end, the users database is going crazy with duplicate entrys. but its not doing it from an INSERT. it seems to be doing it with this code:
Code: [Select] $bitquery = $bitcoin->move("bittleship$username", "bittleships", $cost, $minconfirmations); if ($bitquery == true){ $query = mysql_query("INSERT INTO `transactions` ( `id` , `username` , `type` , `amount`, `address`) VALUES ('', '$username', 'buyclicks', '$cost', '')") or die(mysql_error()); $query = mysql_query("UPDATE users SET `clicks` = `clicks`+$quantity, `balance`=`balance`-$cost WHERE `username` = '$username' ") or die(mysql_error()); include('update.php'); Similar Tutorialswhat Im basically trying to do is just like a phpmyadmin function... you select rows you want to update with a checkbox and then it takes you to a page where the rows that are clicked are shown in forms so that you can view and edit info in them... and then have 1 submit button to update them all at once. Alright, I need to find a way to display the top ten duplicated rows for a table in my database. I have tried multiple methods but I have failed. Can you please assist me with this problem. I currently run a query in phpmyadmin to get the result, but i cant figure out how to properly code the php script. Hi, I need help to check multiple rows for many columns, so that the script won't re-insert a duplicate entry. For eg: $isRowExist=mysql_query("SELECT (field1,field2) from table1 WHERE field1='$f1' AND field2='$f2' "); if(mysql_num_rows($isRowExist)==1) print "already in table1!"; else //proceed to insert into table table1 *BUT I tried this and it says mysql_num_rows expects resource, and this warning only shows when I have multipel columns I want to compare (it works just fine with one column in the WHERE clause above) Please help! This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=327017.0 hi, i have some code that i need to update existing columns in a table, but i just cant seem to get it to work if anyone caan please help it would be appreciated. Quote // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); $insert = mysql_query("insert into $table values ('NULL', '".$_POST['email']."', '".$_POST['password']."', '".$_POST['name']."', '".$_POST['Gender']."', '".$_POST['Age']."', '".$_POST['Race']."', '".$_POST['SpecialtyOne']."', '".$_POST['Feet']."', '".$_POST['Weight']."', '".$_POST['Eyes']."', '".$_POST['Hair']."', '".$_POST['Strength']."', '".$_POST['Stamina']."', '".$_POST['Perception']."', '".$_POST['Agility']."', '".$_POST['Intelligence']."', '".$_POST['Tech']."', '".$_POST['Luck']."', '".$_POST['Appearance']."', '".$_POST['Background']."', '".$_POST['Weapons']."', '".$_POST['Armour']."', '".$_POST['Items']."', '".$_POST['Enhancements']."', '".$_POST['Skills']."')") or die("Could not insert data because ".mysql_error()); ?> <?php This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=349470.0 As the title says I need help with multiple update system.. Can't really get it to work at all >.< Here's some code: $selectt = mysql_query("SELECT * FROM exercises WHERE user='" . $_SESSION["user"] . "' AND exname='" . $_GET["edit"] . "'"); echo '<form method="POST" action="exercises.php?edited">'; echo '<div id="newexx">'; while($raw = mysql_fetch_array($selectt)) { echo '<input type="text" name="up[' . $raw["id"] . ']" value="' . $raw["swe"] . '">'; echo '<input type="text" name="up1[' . $raw["id"] . ']" value="' . $raw["eng"] . '"><br>'; echo '<input type="hidden" name="id[' . $raw["id"] . ']">'; } echo '</div>'; echo '<input type="submit" value="Update Exercise">'; echo '</form>'; if(isset($_GET["edited"])) { $swe = $_POST["up"]; $eng = $_POST["up1"]; $id = $_POST["id"]; foreach($id as $value => $index) { $update = "UPDATE exercises SET swe='".$swe."', eng='".$eng."' WHERE id='".$index."'"; mysql_query($update); } Would be thankful for reply! Hi, Ok, so I'm making a registration form system, where I can create new registration forms for the users to pick a date etc. In my form I can add and remove text fields via Javascript - to add additional dates etc. so I don't know if I'll be submitting 3 fields or 15. The could look like this: <input type="hidden" name="session_id[]" value="<?php echo $session_id; ?>"> <input type="text" name="picked_date[]"> <input type="text" name="picked_room[]"> They are put in a big array: De bliver smidt i et stort array: $n=0; foreach ($session_id as $_session_id) { $bigar[$n][1] = $_session_id; $n++; } $n=0; foreach ($picked_date as $_picked_date) { $bigar[$n][2] = $_picked_date; $n++; } $n=0; foreach ($picked_room as $_picked_room) { $bigar[$n][3] = $_picked_room; $n++; } $n=0; which is then updated in the database using: foreach ($bigar as $part) { mysql_query("UPDATE... } Right - so far so good. The updating works fine with existing fields, but if I remove some of the fields (via JS) it obviously only updates the remaining in the array. The left out will be ignored. On the same note I would like to add fields as well, so - the bottom line - I want to: - UPDATE rows, where the ID is in the array - DELETE existing rows, WHERE the ID is NOT in the array - CREATE new rows for the new fields in the array (not having an ID) How can this be achieved? Hope someone can help... I have ran this code before and it worked but not it won't update. Can anyone see what I am doing wrong? Code: [Select] <? if(isset($_POST[sort_invest])) { // if form was submitted $id = $_POST['sel_record']; $sort = $_POST['sort']; for($i=0;$i<$count;$i++){ $sql = "UPDATE invest SET id='$id[$i]', sort='$sort[$i]' WHERE id='$id[$i]'"; $sql_result = mysql_query($sql,$con) or die (mysql_error()); } } // if form was submitted or if it came from another page if (isset($_POST['order_invest']) || isset($_POST['sort_invest'])) { ?> <p><strong>Order Invest</strong></p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <? $sql = "SELECT id, sort, title FROM invest ORDER BY sort ASC"; $sql_result = mysql_query($sql,$con) or die(mysql_error()); while ($row = mysql_fetch_array($sql_result)) { $id = $row["id"]; $title = $row["title"]; $sort = $row["sort"]; ?> <input type="hidden" name="sel_record[]" value="<? echo "$row[id]"; ?>"> <table width="545" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="69"><input type="text" name="sort[]" value="<? echo "$row[sort]"; ?>" size="3"></td> <td width="476"><? echo "$row[title]"; ?></td> </tr> </table> <br> <? } } ?> <input name="sort_invest" type="submit" value="Sort"> </form> hey can someone advice me on how to make my update script update multiple rows. here's what i've got so far: update.php <?php require('connect.php'); $update = mysql_query("SELECT DISTINCT rideName FROM ride ORDER BY rideName DESC" ); $numrows = mysql_num_rows($update); echo "<form action='mysql_update.php' method='POST'> <select name='updateRide' >"; while ($row=mysql_fetch_assoc($update)) { #$rideID = $row ['rideID']; $rideName = $row ['rideName']; #$seatNumber = $row ['seatNumber']; #$time = $row ['time']; #$price = $row ['price']; echo "<option value='$id'> $rideName </option>"; } echo "</select> <input type='text' name='tochange'> <input type='submit' name='submit' value='change'> </form>"; ?> and now the handler script: mysql_update.php <?php require ('connect.php'); $updateRide=$_POST['updateRide']; $tochange=$_POST['tochange']; if ($updateRide&&$tochange) { $change = mysql_query("UPDATE ride SET rideName='$tochange' WHERE $id='updateRide'"); } ?> When I try this I get nothing, no changes. In the table there is 3 distinct rideNames each have more than 20 rows. Is there a way using the drop down box and ext field like i Have to update all of the distinct rideNames in the table? Thanks. Hey. Third question today. Very stuck on this one. I am displaying a ton of while loops to display a bunch of data from two different tables. there is NO possible way i can combine the two tables. I mean, I can, but I'm not going to because they are two totally different thins. Anyway. Here is what I'm trying to do: Lets say I have 3 items, a grape, an orange and an apple. - 3 apples - 2 oranges - 1 grape I'm displaying an update price box for each different fruit. (so 3 different boxes), and one submit button. I update it, and it does update the price but it only updates the very first row. I want to be able to update every row I types the price in for. Here is my code: (it is quite long): Code: [Select] <?php session_start(); include("config536.php"); ?> <html> <head> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <?php if(!isset($_SESSION['username'])) { echo "<banner></banner><nav>$shownavbar</nav><ubar><a href=login.php>Login</a> or <a href=register.php>Register</a></ubar><content><center><font size=6>Error!</font><br><br>You are not Logged In! Please <a href=login.php>Login</a> or <a href=register.php>Register</a> to Continue!</center></content>"; } if(isset($_SESSION['username'])) { echo "<nav>$shownavbar</nav><ubar>$ubear</ubar><content><center><font size=6>User Shops</font><br><br>"; $action = $_GET['action']; if(!isset($action)) { echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br>"; } if(isset($action)) { $getshopq = "SELECT * FROM usershops WHERE owner='$showusername'"; $getshop = mysql_query($getshopq); while($tri = mysql_fetch_array($getshop)) { $theid = $tri['ushopid']; $owner = $tri ['owner']; $desc = $tri['description']; $image = $tri['image']; $name = $tri['name']; $status = $tri['status']; $discount = $tri['discount']; } $countq = "SELECT * FROM usershops WHERE owner='$showusername'"; $countit = mysql_query($countq); if($action == "edit") { echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br><font size=5>Edit Shop</font><br><br>"; if(mysql_num_rows($countit)) { ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> <?php } if(!mysql_num_rows($countit)) { $create = $_POST['create']; $thename = $_POST['thename']; $thedesc = $_POST['thedesc']; $thestatus = $_POST['thestatus']; $theimage = $_POST['theimage']; if(!isset($create)) { ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> Shop Name: <input type="text" name="thename"><br>Description<br><textarea name="thedesc" rows="5" cols="25"></textarea><br> Status: <select name="thestatus"> <option>Open</option> <option>Closed</option> <option>Gallery</option> </select><br><br> <input type="submit" name="create" value="Create Shop"></form> <?php } if(isset($create)) { if($thename == "" || $thedesc == "") { echo "<font color=red>Error! Please fill out the entire form!</font><br><br>"; ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> Shop Name: <input type="text" name="thename"><br>Description<br><textarea name="thedesc" rows="5" cols="25"></textarea><br> Status: <select name="thestatus"> <option>Open</option> <option>Closed</option> <option>Gallery</option> </select><br><br> <input type="submit" name="create" value="Create Shop"></form> <?php } if($thename != "" && $thedesc != "") { mysql_query("INSERT INTO usershops (owner, name, description, image, status, discount) VALUES ('$showusername', '$thename', '$thedesc', 'image.gif', '$thestatus', 'None')"); echo "<font color=green>Success! You have created your shop! Click <a href=?action=view>here</a> to view it.</font><br><br>"; } } } } if($action == "view") { echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br><font size=5>Shop Name Here</font><br><br>"; $wowq = "SELECT * FROM uitems WHERE username='$showusername' AND location='2'"; $wow = mysql_query($wowq); while($wrow = mysql_fetch_array($wow)) { $umid = $wrow['uitemid']; $umiid = $wrow['theitemid']; $umloc = $wrow['location']; $umprice = $wrow['price']; $infoq = "SELECT * FROM items WHERE itemid='$umiid'"; $info = mysql_query($infoq); while($row = mysql_fetch_array($info)) { $myname = $row['name']; $myid = $row['itemid']; $myimage = $row['image']; $mydesc = $ow['description']; $myrarity = $row['rarity']; echo "$myname"; } } } if($action == "stock") { $setprice = $_POST['price']; $updateprice = $_POST['updateprice']; echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br><font size=5>Stock Shop</font><br><br>"; $eq = "SELECT * FROM uitems WHERE username='$showusername' AND location='2' GROUP BY theitemid"; $ee = mysql_query($eq); while($erow = mysql_fetch_array($ee)) { $eeloc = $erow['location']; $eeid = $erow['theitemid']; $eenowid = $erow['uitemid']; $eeprice = $erow['price']; $wq = "SELECT * FROM items WHERE itemid='$eeid'"; $ww = mysql_query($wq); while($wrow = mysql_fetch_array($ww)) { $cq = mysql_query("SELECT * FROM uitems WHERE username='$showusername' AND location='2' AND theitemid='$eeid'"); $lcq = mysql_num_rows($cq); $fid = $wrow['itemid']; $fname = $wrow['name']; $fimage = $wrow['image']; $frarity = $wrow['rarity']; $fdesc = $wrow['description']; echo "$fname<br><img src=/images/items/$fimage>"; ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> <input type="text" name="price" maxlength="5"><br><br> <?php } } if(isset($updateprice)) { mysql_query("UPDATE uitems SET price='$setprice' WHERE username='$showusername' AND theitemid='$fid'"); echo "<font color=green>Success! Your prices have been set and updated!</font>"; } ?> <input type="submit" name="updateprice" value="Update Prices"> <br> <?php } if($action == "quick") { echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br><font size=5>Quick Stock</font><br><br>"; } } } ?> </html> To help you find it, I'm asking about the "stock" $_GET part, about three quarters down. Thanks in advance for anybody who can help me, I've been stuck on this script all day! Thanks again! Hi, I want to update a txt files 10. row with a form but I could not it how can I do it? Hey Guys. I have tried looking this up on Google but the only answers I am finding is using there where clause. I wanted to know if I can update or delete a range of rows like from id 100-200. Is there a way to do that? Thanks!
Only the last row will update when I submit. I have this form (and one nerve left): <form action="" method="post" > echo" <input style=\"text-align:center\" type=\"text\" name=\"linkorder\" value=\"".$row['order']."\" /> <input type=\"hidden\" name=\"id\" value=\"".$row['id']."\"/> "; <input type="submit" name="updateorder" value="Save Order" /> </form> On Submit: if (isset($_POST['updateorder'])){ connect(); $changeorder = mysql_unbuffered_query("update links set `order` = '".$_POST['linkorder']."' where id = '".$_POST['id']."'") or die(mysql_error()); } I was going put my fist through the monitor but then I remembered I could get help here. Thank you! I have 3 set of pages. The first html page only contains a search textbox and a submit button which then call up the second page search.php which populate html table with search result. The third page is update.php which allows to update the records populated by search.php. The problem is that it when it update the records it automatically updates all rows in the table making all records look the same. I do not know where I have made a mistake please help. When I use phpadmin to update the records no problem as I can specifically input the cf_id number directly. Search.php code Code: [Select] <?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("^/[A-Za-z]+/", $_POST['name'])){ $name=$_POST['name']; } } else{ echo "<p>Please enter a search query</p>"; } } //connect to the database $con = mysql_connect("localhost","dbusrn","dbpwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); $name = $_POST['name']; $result = mysql_query ("select * from Customer_Registration where Firstname like '%$name%' or lastname like '%$name%' "); $row = mysql_fetch_row($result); $cf_uid = $row[0]; $Firstname = $row[6]; $lastname = $row[7]; $Address = $row[8]; $Postcode = $row[9]; $Phone = $row[10]; $Email = $row[11]; $Customer_Type = $row[12]; $Computer_type = $row[13]; $Computer_maker = $row[14]; $Model = $row[15]; $OS = $row[16]; $Appointment_date = $row[17]; $Problem = $row[18]; $Solution = $row[19]; $Comment = $row[20]; ?> <form action="updatecus.php" method="post"> <table width="100%" border="2" cellspacing="0" cellpadding="8"> <tr><td width="45%" class="FormText">Customer ID:</td> <td width="55%"><?php echo $row[0];?></td></tr> <tr><td width="45%" class="FormText">First name:</td> <td width="55%"><input name="Firstname" type="text" value="<?php echo $Firstname;?>"?> </td></tr> <tr><td width="45%" class="FormText">Last name:</td> <td width="55%"><input name="lastname" type="text" value="<?php echo $lastname;?>"?> </td></tr> <tr><td width="45%" class="FormText">Address:</td> <td width="55%"><input name="Address" type="text" value="<?php echo $Address; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Postcode:</td> <td width="55%"><input name="Postcode" type="text" value="<?php echo $Postcode; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Phone:</td> <td width="55%"><input name="Phone" type="text" value="<?php echo $Phone; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Email:</td> <td width="55%"><input name="Email" type="text" value="<?php echo $Email; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Customer:</td> <td width="55%"><input name="Customer_Type" type="text" value="<?php echo $Customer_Type; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Computer :</td> <td width="55%"><input name="Computer_type" type="text" value="<?php echo $Computer_type; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Manufactural:</td> <td width="55%"><input name="Computer_maker" type="text" value="<?php echo $Computer_maker; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Model:</td> <td width="55%"><input name="Model" type="text" value="<?php echo $Model; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Operating System:</td> <td width="55%"><input name="OS" type="text" value="<?php echo $OS; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Appointment:</td> <td width="55%"><input name="Appointment_date" type="text" value="<?php echo $Appointment_date; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Problem:</td> <td width="55%"><textarea name="Problem" rows="10" cols="20" ><?php echo $Problem; ?></textarea></td></tr> <tr><td width="45%" class="FormText">Solution:</td> <td width="55%"><textarea name="Solution" rows="10" cols="20" ><?php echo $Solution; ?></textarea></td></tr> <tr><td width="45%" class="FormText">Comment:</td> <td width="55%"><textarea name="Comment" rows="10" cols="20" ><?php echo $Comment; ?></textarea></td></tr> <td width="55%"><input name="submit" value="submit" type="submit" <br> <input type="Submit" value="Cancel"</br></td> </form> <?php ?> update.php code Code: [Select] <?php //connect to the database $con = mysql_connect("localhost","dbusrn","dbpwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); //if (isset($_POST['submit'])) { $cf_id = $_POST['cf_id']; $Firstname = $_POST['Firstname']; $lastname = $_POST['lastname']; $Address = $_POST['Address']; $Postcode = $_POST['Postcode']; $Phone = $_POST['Phone']; $Email = $_POST['Email']; $Customer_Type = $_POST['Customer_Type']; $Computer_type = $_POST['Computer_type']; $Computer_maker = $_POST['Computer_maker']; $Model = $_POST['Model']; $OS = $_POST['OS']; $Appointment_date = $_POST['Appointment_date']; $Problem = $_POST['Problem']; $Solution = $_POST['Solution']; $Comment = $_POST['Comment']; if (isset($_POST['submit'])) { $query ="UPDATE Customer_Registration SET Firstname='$Firstname',lastname='$lastname',Address='$Address',Postcode='$Postcode',Phone='$Phone',Email='$Email',Customer_Type='$Customer_Type',Computer_type='$Computer_type',Computer_maker='$Computer_maker',Model='$Model',OS='$OS', Appointment_date='$Appointment_date',Problem='$Problem',Solution='$Solution',Comment='$Comment' WHERE cf_id=cf_id"or die (mysql_error()); echo $query; mysql_query($query) or die(mysql_error()); //mysql_close($con); echo "<p>Congrats Record Updated</p>"; } ?> Thank you in advance for your help can anyone see anything wrong here?? it wont update the Ships table.. i should of gone bed hours ago but its bugging me: <?php $sql="SELECT * FROM ships ORDER BY auction='Yes' DESC"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Active?</strong></td> <td align="left"><strong>typeID</strong></td> <td align="left"><strong>Item Name</strong></td> <td align="left"><strong>Base Price</strong></td> <td align="left"><strong>Market Price</strong></td> <td align="center"><strong>Auction</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <?php if ($rows['auction'] != "Yes") { ?> <td align="center"><img src="../images/site/delete.png" /></td> <?php } else { ?> <td align="center"><img src="../images/site/accept.png" /></td> <? } ?> <td align="left"><span class="isk"> <? $typeID[]=$rows[typeID]; ?> <? echo $rows['typeID']; ?></span></td> <td align="left"><span class="eveyellow"><? echo $rows['typeName']; ?></span></td> <td align="left"><span class="normal"><?php echo number_format($rows['basePrice'])?> isk</span></td> <td align="left"><input name="marketPrice[]" type="text" size="10" id="marketPrice" value="<? echo $rows['marketPrice']; ?>"> <span class="credits">(<?php echo number_format($rows['marketPrice']/1000000, 2)?> m)</span></td> <td align="center"><input name="auction[]" type="text" size="6" id="auction" value="<? echo $rows['auction']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE ships SET marketPrice='$marketPrice[$i]', auction='$auction[$i]' WHERE typeID='$typeID[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:ship.php"); } mysql_close(); ?> typeID is my primary key in the table and i only want to update "marketPrice" and "auction" upon submit. its a update multiple rows form by the way. thank you so much for helping me... again.. would be lost without phpfreaks. Hi there. I have a page that lists the records of a table. On this page I want to be able to edit/update two attributes of these records by a checkbox - e.g., being able to update multiple records at once. I thought the smartest way to achieve this would be by using arrays. I've implemented one checkbox array and have two fields. Currently when I change both fields and hit submit, the height value changes and the name value is changed to the last record displayed in the table. E.g. Height - 170 -> 160 -> UPDATED TO 160 Name - Test1 -> Test2 -> UPDATED TO VICTORY (last record listed in table; displayed alphabetically) My code is as follows: <?php include("connection.php"); $conn = oci_connect($UName,$PWord,$DB) or die("Database Error - Contact Admin - sjrei5@student.monash.edu"); if (empty($_POST["check"])) { $query = "SELECT * FROM HORSE ORDER BY HORSE_NAME"; $stmt = oci_parse($conn,$query); oci_execute($stmt); $Horses = oci_fetch_array ($stmt); ?> <form method="post" action="horse_multi.php"> <table border="1" id="customers"> <tr> <th>ID</th> <th>EDIT</th> <th>NAME</th> <th>HEIGHT</th> </tr> <?php while ($Horses = oci_fetch_array ($stmt)) { ?> <tr> <td><?php echo $Horses["HORSE_ID"]; ?></td> <td align="center"><input type="checkbox" name="check[]" value="<?php echo $Horses["HORSE_ID"]; ?>"></td> <td align="center"><input type="text" size="5" name="<?php echo $Horses["HORSE_ID"]; ?>" value="<?php echo $Horses["HORSE_HEIGHT"]; ?>"></td> <td align="center"><input type="text" size="20" name="HORSE_NAME" value="<?php echo $Horses['HORSE_NAME']; ?>"></td> </tr> <?php } ?> </table><p /> <h4><input type="submit" value="Update Selected Horses"></h4> </form> <?php oci_free_statement($stmt); } else { foreach($_POST["check"] as $horse_id) { $query = "UPDATE HORSE SET HORSE_NAME= '$_POST[HORSE_NAME]', HORSE_HEIGHT = ".$_POST[$horse_id]." WHERE HORSE_ID ='".$horse_id."'"; $stmt = oci_parse($conn,$query); oci_execute($stmt); } } ?> </body> </html> Any ideas? Hi all, I have a data base with the following table: ---member_data--- id ^ mid ^fieldname^ fieldvalue 1 - 2 - applicant - Seth Smith 2 - 4 - firstname - Chris 3 - 4 - lastname - Cooper 4 - 7 - full_name - Joey Jones 5 - 7 - occupation - Programmer 6 - 7 - phone - 800-555-1212 And below is a snippet that I use to display the selected members data for editing ------------------------------- <table> <tr> <td>Name:</td> <td>Value:</td> </tr> <?php $query = "SELECT * FROM member_data WHERE mid='$mid'"; $result= mysql_query($query); while($row = mysql_fetch_array($result)) { $fieldname = $row["fieldname"]; $fieldvalue = $row["fieldvalue"]; ?> <tr> <td><input type="text" name="<?php echo $fieldname;?>" value="<?php echo $fieldname;?>"></td> <td><input type="text" name="<?php echo $fieldvalue;?>" value="<?php echo $fieldvalue;?>"></td> <?php } ?> </tr> </table> ------------------------------- My question is: - using the Db example above: - lets say Ive selected mid#7 (member id 7) to edit which is displayed using the snippet code from above. - once displayed how do I edit mid#7 given the fact that mid#7 is located on 3 seperate rows from the same table? Thank you, Dave *ALSO - I tried the snippet below which did Not work. foreach($_POST as $key => $val) { $sql = "UPDATE member_data SET fieldname='$key', fieldvalue='$val' WHERE mid='$mid'"; $result = mysql_query($sql); } My code: Code: [Select] $rank = implode(',', $ibforums->input['rank']); echo $rank; For that form, it will show: '2,0,0' Problem is, I need to update each row with each individual value, and is this possible with using 1 query? This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=325508.0 |