douliao2493 2014-04-13 17:13
浏览 93
已采纳

使用mysqli编写的mysql数据库获取名字和姓氏?

This is a small problem but I have been spending hours trying to figure out why it doesn't work.

I am trying to get firstname or lastname from the mysql database using the following code:

<?php
 include "config/connect.php";

 $manager = 'myemail@yahoo.co.uk';

    $stmt = mysqli_prepare(
    $db_conx,
    "SELECT  lastname
     FROM members
     WHERE email = ?
     AND lastname = ?");
//after validation, of course
mysqli_stmt_bind_param($stmt, "ss", $manager, $lastname);
mysqli_stmt_execute($stmt);
print $lastname;
if (mysqli_affected_rows($db_conx))
{
    mysqli_stmt_close($stmt);//<-- CLEAN UP AFTER YOURSELF!
    $id = mysqli_insert_id($db_conx);


}
?>

for some strange reason it just doesn't print the lastname or the lastname at all. but if I print manager, it prints it out properly.

what am I doing wrong?

P.S. i know the email, firstname and lastname all exist in the database.

EDIT:

 include "config/connect.php";

 $manager = 'MYEMAIL@yahoo.co.uk';


$stmt = $db_conx->prepare("SELECT  email, firstname
     FROM members
     WHERE email = ?
       AND firstname = ?");
    $stmt->bind_param('ss', $manager, $firstname);
    $stmt->execute();
    $stmt->bind_result($manager, $firstname);
    $stmt->store_result();
    if($stmt->num_rows == 1)  //To check if the row exists
        {
            while($stmt->fetch()) //fetching the contents of the row

              { 
         $firstname = $firstname;
         $manager = $manager;


              }
        }
        $stmt->close();
  • 写回答

1条回答 默认 最新

  • douwenpin0428 2014-04-13 17:34
    关注

    i didn't understand ,what your trying to do,

    If you want to get FIRSTNAME AND LASTNAME

    $stmt = mysqli_prepare($db_conx,"SELECT  firstname,lastname FROM members WHERE email = ?");
    $stmt->bind_param('s', $manager);
    
     $stmt->execute();
    $stmt->bind_result($fname, $lname);
    
    /* fetch values */
    
    while ($stmt->fetch()) {
        printf("%s %s
    ", $fname, $lname);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题