narjis Posted August 31, 2012 Share Posted August 31, 2012 I've been trying to edit my enum values in the database while retrieving them at the same time and if required editing them.How can i do that we'll I've tried the following code. The form which is inserting the values is as follows <?php mysql_connect("localhost","root",""); mysql_select_db("Test"); if(isset($_POST['status'])){ $val=$_POST['status']; $sql = "INSERT INTO test_tb (my_opt) VALUES ('".$val."')"; echo ($sql); if (mysql_query($sql)){ echo "Inserted"; } } ?> <!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> <form method="post" action=""> <select name="status" class="chzn_status" style="width:250px"> <option value="0">Seelect Procress</option> <option value="In Process">In Procress</option> <option value="Completed">Completed</option> <option value="Deadline Crossed">Deadline Crossed</option> </select> <br /> If u want to view or edit ur insersions <a href='enumEg2.php'>click </a>here <input type="submit" value="submit" /> </form> </body> </html> and the one which is editing and updating is as follows. <?php mysql_connect("localhost","root",""); mysql_select_db("Test"); $arr = array("In Process", "Completed","Deadline Crossed"); $sql = "SELECT * FROM test_tb "; $table="<table border='0' >"; $res = mysql_query($sql); while($rows = mysql_fetch_assoc($res)) { $table .= "<tr><td>".$rows['id']."</td>"; $table .= "<td>"; $table .= "<form method='post' action=''><select name=\"status\"> <option value=".$rows['my_opt'].">". $rows['my_opt'] ."</option>"; foreach($arr as $key=>$val){ $table .= "<option value=$key>$val</option>"; $table .= ($val==$rows['my_opt'])?$rows['my_opt']:''; } $table .= "</form>"; $table .=" </select><td><a href='enumEg2.php?opt_id=".$rows['id']."&opt=".$_REQUEST['name']."'>Change"; $table .="</td></tr>"; } $table .="</table>"; ?> <?php if(isset($_GET['id'])){ $id = $_GET['id']; $opt_val = $_GET['opt']; $sql = "UPDATE test_tb SET my_opt='".$opt_val."'"; mysql_query($sql); } ?> <!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> <?php echo $table;?> </body> </html> Pls somebody help me. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 1, 2012 Share Posted September 1, 2012 Start by telling us what part of the database queries doesn't work. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.