Jump to content

help required


narjis

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.