如何在可能的null处理下在相应的linq中转换下面的foreach语句:
foreach (var val in userData.ManagedUsers.Values)
{
if (val.UserId == userId)
{
foreach (var role in val.Roles)
{
switch (role.ToLower())
{
case "underwriter1":
return "1";
case "underwriter2":
return "2";
case "underwriter3":
return "3";
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 当用户点击登录按钮(index.php)时,我正在调用chechlogin.php,我在这里检查loginId密码为 -
if($count==1)
{
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
$_SESSION['UserId'] = $myusername;
$_session['SessionId'] = session_id();
header("location:LoggedUser.php");
}
Run Code Online (Sandbox Code Playgroud)
在LiggedUser.php中
<?php session_start(); //starting session
Run Code Online (Sandbox Code Playgroud)
if(!isset($ _ SESSION ['SessionId'])|| $ _SESSION ['SessionId'] ==''){header("location:index.php"); }?>
问题:它总是回到index.php页面,虽然我输入正确的用户名和密码.我认为session_id()工作不正常或??
我有7个缩略图图像菜单.当用户指向(mouseover)特定缩略图时,我想将背景图像更改<div>为该缩略图的相关图像.
缩略图图像菜单位于diff div中
如何$result在二维数组中存储值.我的代码 -
$sql="SELECT a.userId, b.name, b.dob FROM tbltree a INNER JOIN tblprofile b ON a.userId = b.userId WHERE a.superId ='$uid'";
$result=mysql_query($sql,$link)or die(mysql_error());
Run Code Online (Sandbox Code Playgroud)
具有三列的2d阵列 - userId | name | dob
我的index.php页面代码是 -
<?php
if(!$_COOKIE['authorized'] == 1) {
header("Location: login.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Photo Website</title>
<script src="js/jquery-1.2.6.pack.js" type="text/javascript"></script>
<script src="js/jquery.lightbox-0.5.pack.js" type="text/javascript"></script>
<script src="js/myscript.js" type="text/javascript"></script>
<link rel="stylesheet" href="css/default.css" />
<link rel="stylesheet" href="css/jquery.lightbox-0.5.css" />
</head>
<body>
<form method="post" action="changePhotoTitle.php">
<div id="container">
<h1>My Photos <small>click on the text to change the title.</small></h1>
<a href="login.php?logout=1" id="logout">logout</a>
<div id="main">
<?php require 'getPhotos.php'; ?>
<div id="response" class="hidden" />
</div><!-- end main-->
</div><!-- end …Run Code Online (Sandbox Code Playgroud) 我的javascript-
function validate_loginform(loginform)
{
var uid = loginform.uid.value;
var pass = loginform.pass.value;
if(uid == "")
{
color('uid');
return false;
}
if(pass == 0)
{
color('pass');
return false;
}
return true;
Run Code Online (Sandbox Code Playgroud)
}
function color(traget)
{
var targetbox = document.getElementById(target);
targetbox.style.backgroundColor="red";
}
Run Code Online (Sandbox Code Playgroud)
但是背景颜色不会改变,即使它没有返回fasle值.如果我删除color('uid');nad put alert("user name required");然后这个脚本工作正常.什么错了?
它在实际程序中的backgroundColor我只是错过了它
我的代码 -
document.getElementById("lblmsg").innerHTML=xmlhttp.responseText;
if(xmlhttp.responseText == 'Available')
{
document.getElementById("newid").value = "";
}
Run Code Online (Sandbox Code Playgroud)
虽然响应文本Available但仍然没有进入条件???
我的代码 -
require 'database.php';
$title = mysql_real_escape_string($_POST['title']); //line 48
$cat = $_POST['cat'];
$txtart = mysql_real_escape_string($_POST['artbody']); //line 50
$date = date("d-m-y");
$q = "INSERT INTO tblarticle (art_title, art_cat, art_des, art_date) VALUES ('$title', '$cat', '$txtart', '$date')";
Run Code Online (Sandbox Code Playgroud)
错误 - >
警告:mysql_real_escape_string()[function.mysql-real-escape-string]:在C:\ xampp\htdocs\shizin\admin \中拒绝用户'ODBC'@'localhost'(使用密码:NO)访问第48行的newArticle.php
警告:mysql_real_escape_string()[function.mysql-real-escape-string]:无法在第48行的C:\ xampp\htdocs\shizin\admin \newArticle.php中建立到服务器的链接
警告:mysql_real_escape_string()[function.mysql-real-escape-string]:在C:\ xampp\htdocs\shizin\admin \newArticle.php中拒绝用户'ODBC'@'localhost'(使用密码:NO)的访问权限第50行
警告:mysql_real_escape_string()[function.mysql-real-escape-string]:无法在第50行的C:\ xampp\htdocs\shizin\admin \newArticle.php中建立到服务器的链接
但是数据被保存在数据库中,但是null titile和artbody字段
当用户更改密码时,我想显示消息"已成功更改!" 当用户点击警告框的OK按钮时,我调用logout.php并强制用户使用新密码登录.但问题是PHP header()没有等待alertbox并直接转到logout.php.我的代码 -
if($count==1)
{
$sqlchange="UPDATE $tbl_name SET password='$newpassword' WHERE userId='$myusername'";
unset($result);
$result=mysql_query($sqlchange,$link);
if($result>0)
{ ?>
<script type="text/javascript">
alert("Your Password has been changed successfully.Please login again.");
</script>
<?php
header("location:logout.php");
exit;
}
else
{....
Run Code Online (Sandbox Code Playgroud) 我的代码:
$fileid = $_GET['imgid'];
$fileid = (int)$fileid; //id is int type in photos table
require 'database.php';
//get the image sourc name
$q = "SELECT src form photos WHERE id='$fileid'";
$result = $mysqli->query($q) or die(mysqli_error($mysqli));
if ($result)
{
$row = $result->fetch_object();
$filename = $row->src;
Run Code Online (Sandbox Code Playgroud)
错误:您的SQL语法有错误; 查看与您的MySQL服务器版本对应的手册,以便在第1行的'photos WHERE id = '12''附近使用正确的语法
php ×5
javascript ×4
mysql ×2
ajax ×1
c# ×1
http-headers ×1
jquery ×1
linq ×1
mouseover ×1
onmouseover ×1
select-query ×1
session ×1
sessionid ×1
string ×1
syntax ×1
warnings ×1