<?php
error_reporting(0);
session_start();
if( $_SESSION["logging"]&& $_SESSION["logged"])
{
print_secure_content();
}
else {
if(!$_SESSION["logging"])
{
$_SESSION["logging"]=true;
loginform();
}
else if($_SESSION["logging"])
{
$number_of_rows=checkpass();
if($number_of_rows==1)
{
$_SESSION[user]=$_GET[userlogin];
$_SESSION[logged]=true;
$_SESSION[user_id]=$row['id'];
print"<h1>You have loged in successfully</h1>";
print_secure_content();
}
else{
print "Wrong password or username, please try again.".'<br/>';
loginform();
}
}
}
function loginform()
{
print "Please enter your login information to proceed with our site.".'<br/>'.'<br/>';
print ("<table border='2'><tr><td>Username</td><td><input type='text' name='userlogin' size'20'></td></tr><tr><td>Password</td><td><input type='password' name='password' size'20'></td></tr></table>").'<br/>';
print "<input type='submit' >";
print "<h3><a href='registerform.php'>Register now!</a></h3>";
print "<br><a href='admin.php'>Admin login</a><br>";
}
function checkpass()
{
$servername="localhost";
$username="root";
$conn= mysql_connect($servername,$username)or die(mysql_error());
mysql_select_db("kviz",$conn);
$sql="select * from korisnici where name='$_GET[userlogin]' and password='$_GET[password]'";
$result=mysql_query($sql,$conn) or die(mysql_error());
return mysql_num_rows($result);
}
function print_secure_content()
{
print("<b><h1>Hi mr.$_SESSION[user]</h1>");
print "<br><h2>Only a logged in user can see this</h2><br><a href='index.htm'>Počni kviz</a><br><br><a href='logout.php'>Logout</a><br>";
}
?>
这是我将他的数据插入数据库的地方
$sql = "INSERT INTO tacni (id_tacnog, id_pitanja, id_korisnik,stanje) VALUES ('', '".$row['odg_id']."','$id_korisnika','tačan')";
////$id_korisnika means id_user
这是我从数据库检索的地方
$result = mysql_query("SELECT pitanja.*,tacni.*,korisnici.*
FROM pitanja
INNER JOIN tacni ON pitanja.id = tacni.id_pitanja
INNER JOIN korisnici ON pitanja.id = korisnici.id
WHERE korisnici.id = '$id_korisnika'");
我需要识别哪个用户已登录,他的答案必须插入到具有 id 字段的表 korisnici(users) 中。我尝试过这样但没有任何反应,没有插入任何行。任何人都可以帮助我,并且给我写几行代码来完成这项工作,我将不胜感激任何帮助?