-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgodowns.php
135 lines (121 loc) · 3.66 KB
/
godowns.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
session_start();
if(!(isset($_SESSION['userid']) && $_SESSION['userid']=="admin"))
echo '<meta http-equiv="Refresh" content="0;http://localhost/cart" />';
$ar=array("Godown Name"=>"name","Location"=>"location","Phone"=>"phone","Incharge Person"=>"incharge");
foreach ($ar as $val)
${$val}="";
echo ' <a href="http://localhost/cart?logout=true">LogOut</a><br/><br/>';
if($_SESSION['userid']=="admin")
{
echo '<a href=prod.php>Products</a> <a href=cat.php>Categories</a> <a href=godowns.php>Godowns</a> <a href=suppliers.php>Suppliers</a>  <a href=buy.php>Buy from Supplier</a>';
}
echo '<br/><a href=user.php>Edit User Profile</a> <a href=disp.php>Display and Confirm Products</a> <a href=ordersview.php>View Order History</a><br/><br/>';
mysql_connect('localhost','root','root');
mysql_select_db('osc') or die(mysql_error());
$tq="";
if(isset($_GET["gid"])) $gid=$_GET["gid"];
//Add data
if(isset($_POST["submit"]))
{
$vl=implode(",",$ar);
$i=0;
foreach($ar as $val)
{$t[$i]="'".$_POST[$val]."'";$i++;}
$v=implode(",",$t);
$query="insert into godowns (".$vl.") values (".$v.")";
$tq.=$query."<br/>";
mysql_query($query);
}
//Delete the Category
if(isset($_GET["o"]) && $_GET["o"]=="d")
{
mysql_query("delete from godowns where gid='$gid'");
}
//Update Data
if(isset($_POST["update"]))
{
$query="update godowns set ";
foreach ($ar as $val)
$query.=$val."="."'".$_POST["$val"]."'"." , ";
$query=substr($query,0,-2);
$query.=" where gid='$gid'";
$tq.=$query."<br/><br/>";
mysql_query($query);
}
//Show data to be edited
if((isset($_GET["gid"]) && isset($_GET["o"]) && $_GET["o"]=="e") || isset($_POST["update"]))
{
$query="select * from godowns where gid='$gid'"; $tq.=$query;
$res=mysql_query($query);
foreach ($ar as $val)
${$val}=mysql_result($res,0,$val);
}
?>
<br/>
godowns
<form method="post" action="<?php if(isset($_GET["gid"])) echo "?gid=".$_GET["gid"]; ?>">
<table>
<?php
foreach ($ar as $text=>$val)
if($val!="pgid")
echo "<tr><td>$text : </td><td><input type=text name=$val value=\"${$val}\" size=70></td></tr>";
else
{
echo "<tr><td>$text : </td><td><select name=$val>";
$res1=mysql_query("select gid,cname from godowns order by cname");
echo "<option "; if(0==${$val}) echo 'selected="selected"'; echo "value=0>None</option>";
for($i=0;$i<mysql_num_rows($res1);$i++)
{
echo "<option ";
if(mysql_result($res1,$i,"gid")==${$val})
echo 'selected="selected"';
echo "value=".mysql_result($res1,$i,"gid").">".mysql_result($res1,$i,"cname")."</option>";
}
echo "</select></td></tr>";
}
?>
</table>
<?php
if(isset($_GET["gid"]) && (isset($_POST["update"]) || (isset($_GET["o"]) && $_GET["o"]=="e")))
echo '<input type="submit" name="update" value="Update" />';
else
echo '<input type="submit" name="submit" value="Add" />';
?>
</form>
<br/><br/><br/><br/>
<table border=2>
<?php
//The Table showing all godowns
$res=mysql_query("select * from godowns");
echo "<tr>";
foreach ($ar as $text=>$val)
echo "<th>".$text."</th>";
echo "<th>Edit</th>";
echo "<th>Delete</th>";
echo "</tr>";
for($i=0;$i<mysql_num_rows($res);$i++)
{
echo "<tr>";
foreach ($ar as $val)
{
if($val!="pgid")
echo "<td>".mysql_result($res,$i,$val)."</td>";
else
{
$pgid=mysql_result($res,$i,$val);
if($pgid!=0)
echo "<td>".mysql_result(mysql_query("select gid,cname from godowns where gid='$pgid'"),0,"cname")."</td>";
else
echo "<td></td>";
}
}
echo '<td><a href="?gid='.mysql_result($res,$i,"gid").'&o=e">Edit</a></td>';
echo '<td><a href="?gid='.mysql_result($res,$i,"gid").'&o=d">Delete</a></td>';
echo "</tr>";
}
?>
</table>
<?php
echo $tq;
?>