我的問題涉及我的下一個/上一個按鈕。我可以讓我的更新/刪除按鈕起作用,但在處理下一個/上一個按鈕時,我準備好撕掉我的頭髮。任何幫助將是壯觀的!這是我的代碼。另外,我對PHP很新,所以如果這是不好的編碼,請讓我知道並指出我正確的方向,以便我可以修復我的錯誤。謝謝!!!上一個/下一個記錄按鈕php/mysql woes
session_start();
include "connectionfile.php";
if (isset($_POST['fname']) &&
isset($_POST['lname']) &&
isset($_POST['email']) &&
isset($_POST['login']) &&
isset($_POST['password']) &&
isset($_POST['super']) &&
isset($_POST['foldername']))
{
$id = get_post('id');
$fname = get_post('fname');
$lname = get_post('lname');
$email = get_post('email');
$login = get_post('login');
$password = hash('sha256', get_post('password'));
$super = get_post('super');
$foldername = get_post('foldername');
if ($_POST['submit']==0){
$query = mysql_query("SELECT * FROM `Logins` WHERE ID < '".$id."' ORDER BY ID DESC LIMIT 1;");
while($row = mysql_fetch_array($query)){
$id = $row['ID'];
$fname = $row['fname'];
$lname = $row['lname'];
$email = $row['email'];
$login = $row['login'];
$password = $row['password'];
$super = $row['super'];
$foldername = $row['foldername'];
}
}else if ($_POST['submit']==1){
$query = "UPDATE Logins SET fname = '$fname', lname='$lname', email='$email".'@carouselclinical.com'."', login='$login', password='$password', super='$super', foldername='$foldername'";
$query .= "WHERE ID = '$id';";
if (!mysql_query($query, $connect))
echo "INSERT failed: $query<br />" .
mysql_error() . "<br /><br />";
}else if($_POST['submit']==2){
$delete_query = "DELETE FROM Logins WHERE ID = '".$id."';";
mysql_query($delete_query);
$rc = mysql_affected_rows();
echo "Rows Affected " . $rc;
}
if ($_POST['submit']==3){
$query = mysql_query("SELECT * FROM `Logins` WHERE ID= '". $id ."' ORDER BY ID ASC LIMIT 1;");
while($row = mysql_fetch_array($query)){
$id = $row['ID'];
$fname = $row['fname'];
$lname = $row['lname'];
$email = $row['email'];
$login = $row['login'];
$password = $row['password'];
$super = $row['super'];
$foldername = $row['foldername'];
}
}
}
mysql_close($connect);
function get_post($var)
{
return mysql_real_escape_string($_POST[$var]);
}
?>
<form action="" method="post"><pre>
id <input type="text" readonly="readonly" name="id" value="<?php echo "$id"; ?>" />
First Name <input type="text" name="fname" value="<?php echo "$fname"; ?>" />
Last Name <input type="text" name="lname" value="<?php echo "$lname"; ?>" />
Email <input type="text" name="email" value="<?php echo "$email"; ?>" /> There's no need to put @carouselclinical.com.
Login <input type="text" name="login" value="<?php echo "$login"; ?>"/>
Password <input type="text" name="password" value="<?php echo "$password"; ?>"/>
Super? <input type="text" name="super" value="<?php echo "$super"; ?>" />
foldername <input type="text" name="foldername" value="<?php echo "$foldername"; ?>" />
<button name="submit" value="0">Previous</button>
<button name="submit" value="1">UPDATE</button>
<button name="submit" value="2">Delete</button>
<button name="submit" value="3">Next</button>
</pre>
<a href="super.php">Home</a> <br />
<a href="logout.php">Log out</a>
</form>
你的問題並不清楚,但似乎你可能需要傳遞'id's爲next和previous,所以在mysql中你實際上可以訪問正確的數據集。 – Horen
不確定你到底有什麼問題,但有一件事可能會讓你失望,就是你正在使用'=='而不是'==='來檢查$ _POST ['submit']'。任何字符串值,與使用'=='的0相比,都將評估爲** true **。不知道這是否對您造成了問題,但您一定要意識到這一點。 – Travesty3
另外,您應該避免使用'mysql_ *'函數,而應該使用'mysqli_ *'或PDO。如果你只需要字符串鍵,你也不應該使用'mysql_fetch_array()'。改用'mysql_fetch_assoc()'。那麼不要使用'mysql_fetch_assoc()'。使用mysqli或PDO。 – Travesty3