tet3828 Posted November 2, 2006 Share Posted November 2, 2006 I have a SQL database containing some product information.The php script displays the information of each item in the database. Below the [b]information display[/b] is some fields (soon to be 7) that give the user the option to modify the database. The user will most likely [i]not[/i] want to change all the information at once. say for instance he/she just wants to [b]change the price but not the item name[/b]; in this case I want the user to be able to [b]leave the name field blank and fill in the price field[/b]. My script isn't smart enough yet to achieve this... I tried but I need a new approach I think. [b]should I use checkboxs near each form that needs updating to decide which fields get updated? or is there a way to revise my if statement I've attemped below?[/b] here is the whole script<br><?php[color=orange]/// if submit button is pressed[/color]if (isset($_POST['submit'])){$id = $_GET['id'];$qry = "SELECT itemName,itemCat,itemSub,itemId,itemPrice,itemDesc,itemSmall FROM `products` WHERE `itemId`=\"$id\"";$result = mysql_query($qry) or die(mysql_error()); if(!empty($_POST['newName'])) {$newName = $_POST['newName']; $query = "UPDATE products SET itemName='$newName' WHERE `itemId`=\"$id\""; $result = mysql_query($query); } else { $newName = "['itemName']"; $query = "UPDATE products SET itemName='$newName' WHERE `itemId`=\"$id\""; $result = mysql_query($query); } if(!empty($_POST['newDesc'])) {$newDesc = $_POST['newDesc']; $query = "UPDATE products SET itemDesc='$newDesc' WHERE `itemId`=\"$id\""; $result = mysql_query($query); } else { $newDesc = "['itemDesc']"; $query = "UPDATE products SET itemDesc='$newDesc' WHERE `itemId`=\"$id\""; $result = mysql_query($query); } }?><?php/// Store Passed Data as $id$id = $_GET['id'];$qry = "SELECT itemName,itemCat,itemSub,itemId,itemPrice,itemDesc,itemSmall FROM `products` WHERE `itemId`=\"$id\"";/// Select data from mySQL table$result = mysql_query($qry) or die(mysql_error());/// page headerecho "Listed below is the stored data for the item #$id <br /> Use the fields below the item table to modify the information.";/// Display item data loopwhile($row = mysql_fetch_array($result)){ echo "<table border=\"1\"><tr><td>".$row['itemName']."<td>Item ID#".$row['itemId']."</td></td></tr>"; echo "<tr><td><img src=\"".$row['itemSmall']."\" /></td><td valign=top width=150>Description:".$row['itemDesc']."</td>"; echo "</tr><tr><td>Price: $".$row['itemPrice']."</td><td>Avilibility: </td></tr>"; echo "<tr><td width=150>Catagory: ".$row['itemCat']."</td><td width=150>Sub-Catagory:".$row['itemSub']."</td></tr>";}echo "</table>";echo " ";?><form method="post" action="<?php echo $PHP_SELF;?>"><p>Item Name:</p><input type=hidden name=id value="<?=$_GET['id']?>"><input type="text" name="newName" size="10" maxlength="10" value="<?=$row['itemName']?>" /><br /><textarea name="newDesc" rows="3" cols="25" > <?=$row['itemDesc']?></textarea> <br /><input type=submit name=submit value=Submit /></form> Link to comment https://forums.phpfreaks.com/topic/25959-ignoring-blank-forms/ Share on other sites More sharing options...
gluck Posted November 2, 2006 Share Posted November 2, 2006 I would have the entire form displayed for the user. If the user decides to update any of the fields, irrespective of the fields he changed, you should update it. In your code you are firing multiple update statements for updating one particular record. If I were you I would update all fields with one statement. Link to comment https://forums.phpfreaks.com/topic/25959-ignoring-blank-forms/#findComment-118589 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.