วันอังคารที่ 5 มีนาคม พ.ศ. 2556

update1


<?php

require('config.php');
$myConn = mysql_connect($hostname_library, $username_library, $password_library) or die(mysql_error());
mysql_select_db($database_library,$mycon);
$pass=$_POST["txtStreet"];
$name = $_POST["txtname"];
$gender = $_POST["selCity"];

//header('Location: list.php');

echo "<br />"."customer_name :".$name;
echo "<br />"."customer_name :".$pass;
echo "<br />"."customer_name :".$gender;

$update = mysql_query("update user set password = '".$_POST["txtStreet"]."' , gender = '".$_POST["selCity"]."' where username = '".$_POST["txtname"]."' ");

?>

<script type="text/javascript">
window.location = "index.php"
</script>

update


<?
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update</title>
</head>

<body>

<p>
<?php
require('config.php');
$myConn = mysql_connect($hostname_library, $username_library, $password_library) or die(mysql_error());
mysql_select_db($database_library,$mycon);


$update = mysql_query("update user set password = '$street_conf' where username ='".$_GET['name']." ");
?>
</p>


<form id="form1" name="form1" method="post" action="update1.php">
<?php
$nameup = $_GET['name'] ;
?>
<table width="399" border="0">
<tr>
<td width="97" bgcolor="#FF9900">Username</td>
<td width="286" bgcolor="#FFCC66"><input type="hidden" name= "txtname" value="<?php echo $_GET['name'] ?>"><?php echo $_GET['name'] ?>
        </td>
  </tr>
<tr>
<td bgcolor="#FF9900">Password</td>
<td bgcolor="#FFCC66"><input name="txtStreet" type="text" id="txtStreet" value="<? echo $result['password'];?>" />
        </td>
</tr>
  <tr>
<td bgcolor="#FF9900">Gender</td>
<td bgcolor="#FFCC66">

<select name="selCity">
<?
require('config.php');
$myConn = mysql_connect($hostname_library, $username_library, $password_library) or die(mysql_error());
mysql_select_db($database_library);
if (!$myConn)die('Could not connectooo:' . mysql_error());

$query= "SELECT distinct(gender) FROM user";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
?>
<option value = "<? echo $row['gender'];?>" <? if($row[ 'gender']==$city){ echo "selected"; } ?> > <? echo $row['gender'];?>
    </option>
<?

}

echo $result;
mysql_free_result($result); // เมื่อ process เสร็จแล้วให้ free result set ด้วย
mysql_close($mycon); // ปิด connection กับ MySQL Server
?>
</select>

</form>
<input type="submit" name="submit" id="submit" value="Update" />
</td>
<a href="index.php"><input type="button" name="button" id="button" value="Back" /></a>

</tr>
</form>
</body>
</html>

insert.php


<?
session_start();
?>
<form name="form1" method="post" >
  <table width="258" border="0">
    <tr>
      <td width="101" bgcolor="#FF9900">Username :</td>
      <td width="147" bgcolor="#FFCC66">
      <input name="username" type="text">
      </td>
    </tr>
    <tr>
      <td  bgcolor="#FF9900">Password :</td>
      <td bgcolor="#FFCC66">
      <input type="password" name="password">
      </td>
    </tr>
    <tr>
    <td bgcolor="#FF9900">(ยืนยัน) password :</td>
    <td bgcolor="#FFCC66"><input type="password" name="re_password" /></td>
  </tr>
    <tr>
    <td  bgcolor="#FF9900">เพศ :</td>
    <td bgcolor="#FFCC66"><select name="gender" id="gender">
      <option value="male">ชาย</option>
      <option value="femal">หญิง</option>
    </select></td>
    </tr>
  </table>
  <p>
    <input type="submit" name="submit" id="button" value="Submit">
    <input type="reset" name="button2" id="button2" value="Reset">
  </p>
</form>
<a href="index.php"><input type="button" name="button" id="button" value="Back" /></a>
<?
require('config.php');
echo $_POST['username']."<br />";
echo $_POST['password']."<br />";
echo $_POST['gender']."<br />";
//กด submit
if(isset($_POST['submit'])){
$hve = mysql_query("select* from user where username ='".$_POST['password']."'");
$user_in_DB = mysql_fetch_array($hve);
echo $user_in_DB['username'];
//ถ้าทุกช่องว่าง
if(empty($_POST['username'])|empty($_POST['password'])|empty($_POST['re_password'])|empty($_POST['gender']))
{
?>
        <script>
alert ('ท่่านกรอกข้อมูลไม่ครบ');
window.location ="insert.php";
</script>
<?
}//ถ้าไม่ว่าง
else {
if(empty($user_in_DB))
{//ถ้า password เหมือนกัน
if($_POST['password']==$_POST['re_password'])
{
echo "complete";
mysql_query("insert into user (username,password,gender) values('".$_POST['username']."','".$_POST['password']."','".$_POST['gender']."')");
?>
        <script>
alert ('สมัครเสมาชิครียบร้อยแล้ว');
window.location ="index.php";
</script>
<?
}//ถ้าไม่เหมือน
else{
?>
        <script>
alert ('รหัสผ่านไม่ตรงกัน');
window.location ="insert.php";
</script>
        <?
}
}//ถ้ามีชื่อนี้อยู่แล้ว
else{
?>
        <script>
alert ('username นี้มีผู้ใช้งานแล้ว');
window.location ="insert.php";
</script>
      <?
}}}
?>




index.php


<?
session_start();
?>
<?
include("config.php");
$query = "SELECT * FROM user" ;
$result = mysql_query($query,$mycon);
///order by----------------------------------------------------------------
if($count_click1 =$_GET['count1'])
{
///order by customer_name
if ($count_click1%2 == 0)
{$query = "select * from user  order by username " ;}
else
{$query = "select * from user  order by username  DESC";}
}
else if($count_click2 =$_GET['count2'])
{///order by customer_street
if ($count_click2%2 == 0)
{$query = "select * from user order by password " ;}
else
{$query = "select * from user order by password  DESC";}
}
else if($count_click3 =$_GET['count3'])
{///order by customer_city
if ($count_click3%2 == 0)
{$query = "select * from user order by gender " ;}
else
{$query = "select * from user order by gender  DESC";}
}
///delete row
if(isset($_POST['submit']))
{
foreach($_POST['chk']as $name)
{$query = "DELETE FROM user WHERE username = '".$name."'";
  mysql_query($query,$mycon);
}
}
///search word customer_name
$name = $_POST['Search'];
if(isset($_POST['Search-bt'])){
$query = "SELECT * FROM user WHERE username like '$name%' ";
$result = mysql_query($query,$mycon);
}
else $result = mysql_query($query,$mycon);
//search customer_city by list
$gender = $_POST['gender_list'];
if(isset($_POST['Search-2']))
{
    if($gender == 'All'){
$gender = $_POST['gender_list'];
$query = "SELECT * FROM user" ;
}else {
$gender = $_POST['gender_list'];
$query = "SELECT * FROM user where gender = '$gender' ";
}
$result = mysql_query($query,$mycon);
}
?>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <p>
    <input type="text" name="Search" id="Search" />
    <input type="submit" name="Search-bt" id="Search-bt" value="Search_name" title="ค้นหาชื่อลูกค้า" />
  </p>
  <p>
    <label for="gender_list"></label>
    <select name="gender_list" >
     <option value="All">All</option>
      <option value="femal">หญิง</option>
      <option value="male">ชาย</option>
    </select>
    <input type="submit" name="Search-2" id="Search" value="Select_gender">
  </p>
  <table width="458" border="0">
 <tr>
 <td width="22" bgcolor="#FF9900">&nbsp;</td>
 <td width="26" bgcolor="#FF9900"><strong>Edit</strong></td>
 <td width="115" bgcolor="#FF9900" title="username"><strong><a href=index.php?count1=<?=$count_click1+1?>>Username</a></strong></td>
 <td width="111" bgcolor="#FF9900" title="password"><strong><a href=index.php?count2=<?=$count_click2+1?>>Password</a></strong></td>
 <td width="105" bgcolor="#FF9900" title="gender"><strong><a href=index.php?count3=<?=$count_click3+1?>>Gender</a></strong></td>
 </tr>
 <?
 while($row = mysql_fetch_array($result))
 {
 ?>
 <tr bgcolor="#FFCC66">
 <td><input type="checkbox" name="chk[]" id="chk[]" title="คลิกเลือก"value="<?php echo $row['username'];?>" /></td>
 <td><a href ="update.php?name=<?php echo $row['username'];?>">
   <img src="img/b_edit.png" width="16" height="16" alt="Edit" title="แก้ไข" /></a></td>

 <td><?php echo $row['username'];?></td>
 <td><?php echo $row['password'];?></td>
 <td><?php echo $row['gender'];?></td>
 </tr>
 <?
 }
mysql_close($mycon);
 ?>
 </table>
  <p>
    <input type="submit" name="submit" id="submit" value="Delete" title="ลบ"/>
    <input type="reset" name="reset" id="reset" value="Reset" title="ยกเลิก" />
  </p>
 
</form>
<p><a href="insert.php">ลงทะเบียน</a></p>
<form enctype="multipart/form-data"  id="form1" name="form1" method="post" action="upload.php" >
<input type="file" name="imagefile" />
<input type="submit" name="submit" value="submit" />
</form>

config.php