Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ทำให้หน้าที่บันทึกข้อมูลลงฐานข้อมูล แสดงแบบ alert โดยไม่เปลี่ยนหน้า และสามารถลิงค์ไปหน้าแสดงข้อมูลแบบเป็นตารางได้



 

ทำให้หน้าที่บันทึกข้อมูลลงฐานข้อมูล แสดงแบบ alert โดยไม่เปลี่ยนหน้า และสามารถลิงค์ไปหน้าแสดงข้อมูลแบบเป็นตารางได้

 



Topic : 126490



โพสกระทู้ ( 51 )
บทความ ( 0 )



สถานะออฟไลน์




ผมอยากทราบว่าเมื่อเราทำแบบนี้

ไำ

พอเรากดปุ่ม OK แล้วจะให้มันไปที่หน้า แสดงข้อมูลแบบเป็นตาราง โดยมีไฟล์ชื่อว่า list.php

จะสามารถทำได้มั๊ยครับ

ผมเอาโค้ดมาจากอันนี้ครับ (ตัวอย่างที่1)

https://www.thaicreate.com/community/php-submit-form-action-target-iframe.html

ผมจะมีอยู่ 3 ไฟล์คือ

from.php = หน้าสำหรับกรอกข้อมูล
add.php = หน้าสำหรับบันทึกข้อมูลลงฐาน
list.php = หน้าสำหรับแสดงข้อมูลแบบเป็นตาราง



Tag : PHP, Ms SQL Server 2012









ประวัติการแก้ไข
2017-02-20 11:41:26
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2017-02-20 11:38:49 By : puruther View : 3730 Reply : 6
 

 

No. 1



โพสกระทู้ ( 110 )
บทความ ( 0 )



สถานะออฟไลน์


SaveForm.php
Code (PHP)
<?php
		$strFirstName = $_POST["txtFirstName"];
		$strLastName = $_POST["txtLastName"];
		echo "<script language=\"JavaScript\">";
		echo "alert('Sawatdee : $strFirstName $strLastName');";
		echo "location='list.php' ";
		echo "</script>";
?>









ประวัติการแก้ไข
2017-02-20 13:09:20
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-02-20 13:07:36 By : JJAAYY
 


 

No. 2



โพสกระทู้ ( 51 )
บทความ ( 0 )



สถานะออฟไลน์


ไม่ได้อ่ะครับ

Code (PHP)
 <?php
$re_name=$_POST['re_name'];
$ip=$_POST['ip'];
$com_name=$_POST['com_name'];
$mac=$_POST['mac'];
$start=$_POST['start'];
$finished=$_POST['finished'];
$remark=$_POST['remark'];

mysql_connect("localhost","root","1234");
mysql_select_db("bic");
mysql_query("SET NAMES UTF8");

$sql="INSERT INTO reguester_ip(re_name,ip,com_name,mac,start,finished,remark)
VALUES('$re_name','$ip','$com_name','$mac','$start','$finished','$remark')";
$rc=mysql_query($sql);
if($rc=="1"){
   		echo "<script language=\"JavaScript\">";
		echo "alert('บันทึกข้อมูลเรียบร้อยแล้ว');";
		echo "location='list.php'";
		echo "</script>";
}else{
   		echo "<script language=\"JavaScript\">";
		echo "alert('ไม่สามารถบันทึกข้อมูลได้');";
		echo "location='list.php'";
		echo "</script>";
}




ประวัติการแก้ไข
2017-02-20 13:17:07
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-02-20 13:15:40 By : puruther
 

 

No. 3



โพสกระทู้ ( 110 )
บทความ ( 0 )



สถานะออฟไลน์


ขอดูโค้ดทั้งหมดได้ป่าวครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-02-20 13:24:00 By : JJAAYY
 


 

No. 4



โพสกระทู้ ( 51 )
บทความ ( 0 )



สถานะออฟไลน์


from.php
<!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>
<script src="file:///C|/xampp/htdocs/bic/SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="file:///C|/xampp/htdocs/bic/SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Datepicker - Select a Date Range</title>
  <link rel="stylesheet" href="../jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/jquery-ui.css">
  <script src="../jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/external/jquery/jquery.js"></script>
  <script src="../jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/jquery-ui.js"></script>
  <script>
  $( function() {
    var dateFormat = "yy-mm-dd",
      from = $( "#start" )
        .datepicker({
          defaultDate: "+1w",
          changeMonth: true,
		  dateFormat : 'yy-mm-dd',
          numberOfMonths: 1
        })
        .on( "change", function() {
          to.datepicker( "option", "minDate", getDate( this ) );
        }),
      to = $( "#finished" ).datepicker({
        defaultDate: "+1w",
        changeMonth: true,
		dateFormat : 'yy-mm-dd',
        numberOfMonths: 1
      })
      .on( "change", function() {
        from.datepicker( "option", "maxDate", getDate( this ) );
      });
 
    function getDate( element ) {
      var date;
      try {
        date = $.datepicker.parseDate( dateFormat, element.value );
      } catch( error ) {
        date = null;
      }
 
      return date;
    }
  } );
  </script>

</head>


<script language="JavaScript">
	   var HttPRequest = false;

	   function doCallAjax() {
		  HttPRequest = false;
		  if (window.XMLHttpRequest) { // Mozilla, Safari,...
			 HttPRequest = new XMLHttpRequest();
			 if (HttPRequest.overrideMimeType) {
				HttPRequest.overrideMimeType('text/html');
			 }
		  } else if (window.ActiveXObject) { // IE
			 try {
				HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
				try {
				   HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			 }
		  } 
		  
		  if (!HttPRequest) {
			 alert('Cannot create XMLHTTP instance');
			 return false;
		  }
	
		  var url = 'check.php';
		  var pmeters = "ip=" + encodeURI( document.getElementById("ip").value);
		  
			HttPRequest.open('POST',url,true);

			HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			HttPRequest.setRequestHeader("Content-length", pmeters.length);
			HttPRequest.setRequestHeader("Connection", "close");
			HttPRequest.send(pmeters);
			
			
			HttPRequest.onreadystatechange = function()
			{

				if(HttPRequest.readyState == 3)  // Loading Request
				{
					document.getElementById("mySpan").innerHTML = "..";
				}

				if(HttPRequest.readyState == 4) // Return Request
				{
					if(HttPRequest.responseText == 'Y')
					{
						window.location = 'check.php';
					}
					else
					{
						document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
					}
				}
				
			}

	   }
	</script>



<body>

<p>&nbsp;</p>
<h2 style="text-align: center"><strong>ฟอร์มยื่นคำร้องขอ IP Address</strong></h2>
<form id="form2" name="form2" method="post" action="add.php"target="iframe_target">
<iframe id="iframe_target" name="iframe_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>
  <table width="500" border="0" align="center">
    <tr>
      <td width="184" height="38">Reguester name</td>
      <td width="14" align="center">:</td>
      <td width="319"><label for="re_name"></label>
        <input type="text" name="re_name" id="re_name" /></td>
    </tr>
    <tr>
      <td height="38">IP Address</td>
      <td align="center">:</td>
      <td><label for="textfield"></label>
      <label for="ip"></label>
      <span id="sprytextfield1">
      <input type="text" name="ip" id="ip" OnChange="JavaScript:doCallAjax();"/>
      <span id="mySpan"></span></span></td>
    </tr>
    <tr>
      <td height="40">Computer name</td>
      <td align="center">:</td>
      <td><label for="com_name"></label>
        <input type="text" name="com_name" id="com_name" /></td>
    </tr>
    <tr>
      <td height="39">Mac address</td>
      <td align="center">:</td>
      <td><label for="mac"></label>
        <input type="text" name="mac" id="mac" /></td>
    </tr>
    <tr>
      <td height="35">From</td>
      <td align="center">:</td>
      <td><label for="textfield5"></label>
        <input type="text" name="start" id="start" /></td>
    </tr>
    <tr>
      <td height="40">To</td>
      <td align="center">:</td>
      <td><label for="textfield6"></label>
        <input type="text" name="finished" id="finished" /></td>        
    </tr>
    <tr>
      <td>Remark</td>
      <td align="center">:</td>
      <td><label for="remark"></label>
        <label for="remark"></label>
        <textarea name="remark" id="remark" cols="45" rows="5"></textarea></td>
    </tr>
  </table>
  <p align="center">
    <input type="submit" name="button" id="button" value="บันทึก" />
    <input type="reset" name="button2" id="button2" value="ยกเลิก" />
  </p>
</form>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
</script>
</body>
</html>


add.php
<!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>

<p>
  <?php
$re_name=$_POST['re_name'];
$ip=$_POST['ip'];
$com_name=$_POST['com_name'];
$mac=$_POST['mac'];
$start=$_POST['start'];
$finished=$_POST['finished'];
$remark=$_POST['remark'];

mysql_connect("localhost","root","1234");
mysql_select_db("bic");
mysql_query("SET NAMES UTF8");


$sql = "SELECT * FROM reguester_ip WHERE ip = '".$_POST["ip"]."' ";
$rc = mysql_query($sql);
if (!filter_var($ip, FILTER_VALIDATE_IP) === true) {
   		echo "<script language=\"JavaScript\">";
		echo "alert('$ip is not a valid IP address');";
		echo "window.history.go(-1);</script>";
		exit;

} 


$sql = "SELECT * FROM reguester_ip WHERE ip = '".$_POST["ip"]."' ";
$rc = mysql_query($sql);
$objResult = mysql_fetch_array($rc);
if($objResult)
{
   		echo "<script language=\"JavaScript\">";
		echo "alert('IP Address นี้มีอยู่แล้ว ไม่สามารถบันทึกข้อมูลได้.');";
		echo "window.history.go(-1);</script>";
		exit;
}
else 
{

$sql="INSERT INTO reguester_ip(re_name,ip,com_name,mac,start,finished,remark)
VALUES('$re_name','$ip','$com_name','$mac','$start','$finished','$remark')";
$rc=mysql_query($sql);
if($rc=="1"){
   		echo "<script language=\"JavaScript\">";
		echo "alert('บันทึกข้อมูลเรียบร้อยแล้ว');";
		echo "location='list.php'";
		echo "</script>";
}else{
   		echo "<script language=\"JavaScript\">";
		echo "alert('ไม่สามารถบันทึกข้อมูลได้');";
		echo "location='list.php'";
		echo "</script>";
}

}
mysql_close(); 
?>
</p>
<p align="center"><a href="list.php">ดูข้อมูลการยื่นคำขอ IP</a></p>


</body>
</html>


list.php
<!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>
<p><a href="from.php">เพิ่มข้อมูลการยื่นคำร้องขอ IP</a></p>
<p><a href="list_save.php">SAVE</a></p>
<h2 align="center">แสดงข้อมูลการยื่นคำร้องขอ IP</h2>
<form id="form1" name="form1" method="post" action="">
  
  <p style="text-align: center"><span style="font-weight: bold">ค้นหาข้อมูลจาก</span>
    <label for="s"></label>
    <select name="s" id="s">
      <option>192.168.100</option>
      <option>192.168.101</option>
      <option>192.168.102</option>
      <option>192.168.103</option>
      <option>192.168.104</option>
      <option>192.168.105</option>
      <option>192.168.106</option>
      <option>192.168.107</option>
      <option>192.168.108</option>
      <option>192.168.109</option>
    </select>
    <input type="submit" name="button" id="button" value="ค้นหา" />
  </p>
</Form>
  
  </p>
<form id="form1" name="form1" method="post" action="">
  <div align="center">
    <div align="center">
      <table width="1012" border="1">
        <tr>
          <td width="168" align="center" bgcolor="#FF0000" style="color: #FFF; font-weight: bold;">Reguester name</td>
          <td width="135" align="center" bgcolor="#FF0000" style="color: #FFF; font-weight: bold;">IP Address</td>
          <td width="148" align="center" bgcolor="#FF0000" style="color: #FFF; font-weight: bold;">Computer name</td>
          <td width="125" align="center" bgcolor="#FF0000" style="color: #FFF; font-weight: bold;">Mac address</td>
          <td width="85" align="center" bgcolor="#FF0000" style="color: #FFF; font-weight: bold;">From</td>
          <td width="86" align="center" bgcolor="#FF0000" style="color: #FFF; font-weight: bold;">To</td>
          <td width="139" align="center" bgcolor="#FF0000" style="color: #FFF; font-weight: bold;">Remark</td>
          <td width="74" align="center" bgcolor="#FF0000" style="color: #FFF; font-weight: bold;">Edit</td>
        </tr>
  <?php

@$s=$_POST[s];
  
$con = mysql_connect("localhost","root","1234");
mysql_select_db("bic",$con);
mysql_query("SET NAMES UTF8");
$sql = "select * from reguester_ip where ip LIKE '%$s%' order by ip ASC "; // DESC//
$rs = mysql_query($sql,$con);
while($cols = mysql_fetch_row($rs)){
	
	
echo "<tr>
	<td><center>$cols[1]</center></td>
	<td><center>$cols[2]</center></td>
	<td><center>$cols[3]</center></td>
	<td><center>$cols[4]</center></td>
	<td><center>$cols[5]</center></td>
	<td><center>$cols[6]</center></td>
	<td><center>$cols[7]</center></td>
	<td><center><a href='edit.php?id=$cols[0]'><แก้ไข></a></center></td>
	</tr>
	";
}
mysql_free_result($rs);
mysql_close($con);
?>
      </table>
  </div>
</form>
<p align="center">&nbsp;</p>
</body>
</html>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-02-20 13:30:43 By : puruther
 


 

No. 5



โพสกระทู้ ( 110 )
บทความ ( 0 )



สถานะออฟไลน์


form.php
Code (PHP)
<form id="form2" name="form2" method="post" action="add.php" target="iframe_target">


แก้เป็น ลองดูครับ
Code (PHP)
<form id="form2" name="form2" method="post" action="add.php">

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-02-20 13:59:55 By : JJAAYY
 


 

No. 6



โพสกระทู้ ( 51 )
บทความ ( 0 )



สถานะออฟไลน์


ถ้าแก้ตรงนั้นมันลิงค์ได้ครับ แต่ว่ามันจะแสดง กล่องข้อความไปอยู่อีกหน้านึง คือผมอยากให้มันอยู่ในหน้า from.php อ่ะครับ

ไม่อยากให้มันไปแสดงที่ลิงค์ add.php ครับ มันพอจะทำได้หรือป่าวครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-02-20 14:04:33 By : puruther
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ทำให้หน้าที่บันทึกข้อมูลลงฐานข้อมูล แสดงแบบ alert โดยไม่เปลี่ยนหน้า และสามารถลิงค์ไปหน้าแสดงข้อมูลแบบเป็นตารางได้
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่