我正在創建一個電話簿程序,我可以在其中註冊並創建我自己的聯繫人列表。登錄後,該頁面將被導向到tabmain
頁面,我可以在其中查看,添加,編輯或刪除聯繫人,以多選形式。無法將輸入變量傳遞給我的查詢
問題出在這裏:每當我點擊保存按鈕(功能displayNew
中的按鈕),它應該獲得名和姓,然後查找數據庫是否匹配。如果沒有,那麼應該添加它們。現在,發生什麼是,我點擊保存按鈕後,沒有任何東西被傳遞給變量。
這裏是我的代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Tab-View Sample</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<link rel="stylesheet" type="text/css" href="css_collect/distribution/tab-view.css" />
</head>
<body>
<?php $id = isset($_GET['id']) ? $_GET['id'] : 1; ?>
<?php
include 'conSql.php';
session_start();
$mySession = $_SESSION['user'];
//displays firsname and lastname of the user
$getNames = getNames($mySession);
$gET = explode("^", $getNames);
echo "Hi, "."<b>". $gET[0] ." ". $gET[1] ."</b>"."!";
echo "</br>";
echo "</br>";
?>
<div class="TabView" id="TabView">
<!-- ***** Tabs ************************************************************ -->
<div class="Tabs" style="width: 452px;">
<a <?=($id == 1) ? 'class="Current"' : 'href="sample.php?id=1"';?>>Contact List</a>
<a <?=($id == 2) ? 'class="Current"' : 'href="sample.php?id=2"';?>>Add contact</a>
<a <?=($id == 3) ? 'class="Current"' : 'href="sample.php?id=3"';?>>Edit/Delete</a>
</div>
<!-- ***** Pages *********************************************************** -->
<div class="Pages" style="width: 450px; height: 300px;">
<div class="Page" style="display: <?=($id == 1) ? 'block' : 'none';?>"><div class="Pad"></div>
list of query
</div>
<div class="Page" style="display: <?=($id == 2) ? 'block' : 'none';?>"><div class="Pad"></div>
<Form Name ='' Method ='GET' action = 'tabmenu.php'>
<?php
displayNew();
if(isset($_GET['btnAdd'])){
$fname = $_GET['txtFname'];
$lname = $_GET['txtLname'];
// $s = "SELECT * ";
// $s .="FROM tbl_contactlist ";
// $s .="WHERE fname = '". $_GET['txtFname'] ."' and lname = '". $_GET['txtLname'] ."'";
echo $s;
}
?>
</div>
<div class="Page" style="display: <?=($id == 3) ? 'block' : 'none';?>"><div class="Pad"></div>
<?php
displayEdit();
?>
</div>
</div>
</div>
<script type="text/javascript" src="css_collect/distribution/tab-view.js"></script>
<script type="text/javascript">
tabview_initialize('TabView');
</script>
<?php
function getNames($mySession){
//get the real name of the user (firstname and lastname)
$s = "SELECT * ";
$s .="FROM tbl_users ";
$s .="WHERE username = '". $mySession ."' ";
$rc = mysql_query($s);
$row = mysql_fetch_assoc($rc) or die();
$details = $row["fname"]."^".$row["lname"];
return $details;
}
function displayNew(){
echo "<table border = '0'>";
echo "<tr>";
echo "<td colspan='2'><b>New Contact</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='2'>Please fill up the fields.</td>";
echo "</tr>";
echo "<tr>";
echo "<td>First Name: </td>";
echo "<td><input type='text' name='txtFname' id='txtFname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Last Name: </td>";
echo "<td><input type='text' name='txtLname' id='txtLname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Nick Name: </td>";
echo "<td><input type='text' name='txtNicname' id='txtNicname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Contact Number: </td>";
echo "<td><input type='text' name='txtContactNum' id='txtContactNum'></td>";
echo "</tr>";
echo "<tr>";
echo "<td></td>";
echo "<td><input type='submit' name='btnAdd' id='btnAdd' value='SAVE'></td>";
echo "</tr>";
echo "</table>";
}
function displayEdit(){
echo "<table border = '0'>";
echo "<tr>";
echo "<td colspan='2'><b>Edit/Delete Page</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='2'>You can edit or delete:</td>";
echo "</tr>";
echo "<tr>";
echo "<td>First Name: </td>";
echo "<td><input type='text' name='txtFname' id='txtFname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Last Name: </td>";
echo "<td><input type='text' name='txtLname' id='txtLname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Nick Name: </td>";
echo "<td><input type='text' name='txtNicname' id='txtNicname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Contact Number: </td>";
echo "<td><input type='text' name='txtContactNum' id='txtContactNum'></td>";
echo "</tr>";
echo "<tr>";
echo "<td></td>";
echo "<td><input type='submit' name='btnEdit' id='btnEdit' value='EDIT'>";
echo "<input type='submit' name='btnDelete' id='btnDelete' value='DELETE'></td>";
echo "</tr>";
echo "<tr>";
echo "<td></td>";
echo "<td><input type='submit' name='btnCancel' id='btnCancel' value='Cancel'></td>";
echo "</tr>";
echo "</table>";
}
function testMe(){
echo "<script type='text/javascript'>\n";
echo "alert('T E S T');\n";
echo "</script>";
}
?>
</body>
</html>
你能刪除了一些「嘈雜」的代碼?只需發佈相關內容(即發佈的表單以及處理它的PHP代碼)。 – Matt 2012-08-02 14:38:51
您必須調用session_start();在打印任何回顯,打印或html代碼之前,或者您將收到一個錯誤消息,說明標題已被髮送... – Oussama 2012-08-02 14:39:24
您需要進行調試,當您遇到特定錯誤時,我們可以爲您提供幫助。 – Jocelyn 2012-08-02 14:39:27