如何在$ result中将变量设置为email列?

时间:2017-06-23 09:43:37

标签: php mysql

我是PHP的新手。我试图将用户名和电子邮件作为$ _SESSION发送到index.php。 我试过用mysql_data_seek重置指针($ result,0); 然后使用mysql_fetch ... 在此先感谢您的帮助。

$query = "SELECT * FROM `users` WHERE username='$username' and password='".md5($password)."'";
    $result = mysqli_query($con,$query) or die(mysql_error());
    $rows = mysqli_num_rows($result);
    if($rows==1){

        $_SESSION['email'] ="emailcolumn in $result"; //<---- How to set this?
        $_SESSION['username'] = $username;
        header("Location: index.php"); // Redirect user to index.php
        }else{

3 个答案:

答案 0 :(得分:7)

$_SESSION['email']

确保在脚本顶部开始会话($result= mysqli_fetch_assoc($result); //make the result an associative array $_SESSION['email'] = $result['email_column']; <--This is how we extract value from an associative array ) 感谢@Mayank指出这个

答案 1 :(得分:0)

import gab.opencv.*; PImage img; OpenCV opencv; Histogram histogram; int lowerb = 50; int upperb = 100; ArrayList<Contour> contours; ArrayList<Contour> polygons; void setup() { size(800,400); img = loadImage("grape-harvest-inside.jpg"); opencv = new OpenCV(this, img); opencv.useColor(HSB); } void draw() { opencv.loadImage(img); image(img, 0, 0); opencv.setGray(opencv.getH().clone()); opencv.inRange(lowerb, upperb); histogram = opencv.findHistogram(opencv.getH(), 255); image(opencv.getOutput(), width/2, height/2, width/2,height/2); noStroke(); fill(0); histogram.draw(10, height - 230, 400, 200); noFill(); stroke(0); line(10, height-30, 410, height-30); text("Hue", 10, height - (textAscent() + textDescent())); float lb = map(lowerb, 0, 255, 0, 400); float ub = map(upperb, 0, 255, 0, 400); stroke(255, 0, 0); fill(255, 0, 0); strokeWeight(2); line(lb + 10, height-30, ub +10, height-30); ellipse(lb+10, height-30, 3, 3 ); text(lowerb, lb-10, height-15); ellipse(ub+10, height-30, 3, 3 ); text(upperb, ub+10, height-15); contours = opencv.findContours(); for (Contour contour : contours) { stroke(0, 255, 0); noFill(); contour.draw(); } } void mouseMoved() { if (keyPressed) { upperb += mouseX - pmouseX; } else { if (upperb < 255 || (mouseX - pmouseX) < 0) { lowerb += mouseX - pmouseX; } if (lowerb > 0 || (mouseX - pmouseX) > 0) { upperb += mouseX - pmouseX; } } upperb = constrain(upperb, lowerb, 255); lowerb = constrain(lowerb, 0, upperb-1); } 放在代码的第一行,然后将会话设置为:

session_start()

答案 2 :(得分:0)

使用mysqli_fetch_assoc($result)获取数据

$query = "SELECT * FROM `users` WHERE username='$username' and password='".md5($password)."'";
$result = mysqli_query($con,$query) or die(mysql_error());
$rows = mysqli_num_rows($result);
if($rows==1){

    $data = mysqli_fetch_assoc($result);
    $_SESSION['email'] = $data['your_column_name']; 

    $_SESSION['username'] = $username;
    header("Location: index.php"); // Redirect user to index.php
    }else{