0

我的问题涉及我的下一个/上一个按钮。我可以让我的更新/删除按钮工作,但我已经准备好在处理下一个/上一个按钮时撕掉我的头发。任何帮助都会很壮观!这是我的代码。另外,我对 PHP 很陌生,所以如果这是不好的编码,请让我知道并指出正确的方向,以便我可以修复我的错误。谢谢!!!

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>
4

1 回答 1

1

尝试在else上面添加一个 right mysql_close($connect);。我的猜测是,在初始页面加载时,您没有发布任何值,因此没有采取任何措施。ID如果您的 top 中没有定义,这将创建一个默认值if

else{
$query = mysql_query("SELECT * FROM `Logins` 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'];
}

此外,在您的 上if ($_POST['submit']==3),您需要将您的 更改=>$query以便获得下一条记录。当前,您将选择相同的 ID,而不是下一个更高的 ID。

$query = mysql_query("SELECT * FROM `Logins` WHERE ID > '". $id ."' ORDER BY ID ASC LIMIT 1;");

最后,在执行 Previous/Next 时,您还需要考虑Previous在第一个IDNext最后一个时如何处理id,因为您将返回一个空的结果集MySQL

于 2012-09-24T20:40:32.960 回答