例如,我有一个名为的文件file.txt,其中包含个人信息(id、name、salary):
A123 Anna 3000
A234 Alex 4000
A986 Jame 5000
Run Code Online (Sandbox Code Playgroud)
如何编写允许用户输入人员ID并补充工资的Java代码?最终输出将如下所示:
输入编号:A123
输入补薪:2000
运行程序后的file.txt:
A123 Anna 5000
A234 Alex 4000
A986 Jame 5000
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所做的,但没有奏效:
public static void addDalary() throws IOException {
String ID, Nanme;
double salary;
Scanner console = new Scanner(System.in);
System.out.print("Enter ID : ");
String pID = console.nextLine();
System.out.print("Enter replenish salary: ");
replenish = console.nextInt();
Scanner input = new Scanner(new File("file.txt"));
while (input.hasNext()) {
ID = input.next();
Name = input.next();
salary = input.nextDouble();
if (ID == pID) …Run Code Online (Sandbox Code Playgroud) 我创建登录会话,它已显示错误:未识别myusername和mypassword在这些行中.我不知道为什么.
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
Run Code Online (Sandbox Code Playgroud)
这是我的checklogin.php
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
Run Code Online (Sandbox Code Playgroud)
这是我的登录表格:
<form action='checklogin.php' method="post" >
Username
<input name='myusername' type="text">
Password
<input name='mypassword' type="password">
<input type="submit" name="Submit" value="Login">
</form>
Run Code Online (Sandbox Code Playgroud) 我的问题解决了.我不希望得到更多答案.所以,请不要投票,因为我需要一些声誉来投票给别人发帖.谢谢
我尝试md5()用于登录系统,但它不加密密码.它仍然在我的数据库上显示原始密码.这是我的代码:
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$myusername=$_POST['myusername'];
$mypassword=md5($_POST['mypassword']);
$sql="select * from $tbl_name where username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
header("location:login.html");
}
?>
Run Code Online (Sandbox Code Playgroud)
我只是编辑我的代码 $mypassword=md5($_POST['mypassword']);