我不明白为什么我的查询不起作用?
他们立即转到else并跳过if块来测试返回的行数。我一直收到3条消息,说我有一个以ap / es / wb开头的项目,我不知道为什么。我真的坚持这个。
$username="root";
$password="23994";
$database="urenselector";
mysql_connect("localhost",$username,$password);
mysql_select_db($database) or die( "Unable to select database");
//button bezig joey mikkers
$query= "SELECT projecten.keuze_selectie, projecten.do, projecten.vak, projecten.uren, projecten.proj_id,".
" urenlijst.username, urenlijst.proj_status FROM projecten,urenlijst Where projecten.proj_id = urenlijst.proj_id AND urenlijst.username = '".$_SESSION['user']."'";
//die($query);
$result=mysql_query($query);
//$button_name = "btn".$row['proj_id'];
//if(isset($_GET[$button_name]))
//{
if($result)
{
$query2= "SELECT urenlijst.proj_status FROM urenlijst WHERE proj_status = 'b' and username = " . $_SESSION['user'];
$result2=mysql_query($query2) or die(mysql_error());
$numrows = mysql_num_rows($result2);
$query3= "SELECT projecten.vak, urenlijst.username, urenlijst.proj_id, urenlijst.proj_status FROM projecten, urenlijst WHERE vak = 'AP' and proj_status = 'b' and username = " . $_SESSION['user'];
$result3=mysql_query($query3);
$numrows2 = mysql_num_rows($result3);
$query4= "SELECT projecten.vak, urenlijst.username, urenlijst.proj_id, urenlijst.proj_status FROM projecten, urenlijst WHERE vak = 'ES' and proj_status = 'b' and username = " . $_SESSION['user'];
$result4=mysql_query($query4);
$numrows3 = mysql_num_rows($result4);
$query5= "SELECT projecten.vak, urenlijst.username, urenlijst.proj_id, urenlijst.proj_status FROM projecten, urenlijst WHERE vak = 'WB' and proj_status = 'b' and username = " . $_SESSION['user'];
$result5=mysql_query($query5);
$numrows4 = mysql_num_rows($result5);
while($row = mysql_fetch_array($result))
{
$button_name = "btn".$row['proj_id'];
if(isset($_GET[$button_name]))
{
//print_r($numrows);
$message = "";
$message1 = "";
$message2 = "";
if($numrows3 < 1)
{
echo 'test1';
if($numrows > 2)
{
$message = "je hebt al drie projecten geselecteerd met status \"bezig\"";
}
else
{
mysql_query("UPDATE urenlijst SET proj_status = 'b' WHERE proj_id = ".$row['proj_id']);
}
}
else
{
$message2 = "je hebt al een project geselecteerd met het vak ES";
}
if($numrows4 < 1)
{
echo 'test2';
if($numrows > 2)
{
$message = "je hebt al drie projecten geselecteerd met status \"bezig\"";
}
else
{
mysql_query("UPDATE urenlijst SET proj_status = 'b' WHERE proj_id = ".$row['proj_id']);
}
}
else
{
$message1 = "je hebt al een project geselecteerd met het vak WB";
}
if($numrows2 < 1)
{
echo 'test3' . $numrows2;
if($numrows > 2)
{
$message = "je hebt al drie projecten geselecteerd met status \"bezig\"";
}
else
{
mysql_query("UPDATE urenlijst SET proj_status = 'b' WHERE proj_id = ".$row['proj_id']);
}
}
else
{
$message = "je hebt al een project geselecteerd met het vak AP";
}
}
}
}
答案 0 :(得分:0)
您使用了$ _SESSION,请在查询中使用之前检查该数组并输入
session_start(); // at your first line of script