Data not fetched from MySQL table in PHP -


i want print name , last name of id entered in text box. here php , html code:

    <head>         <title>             search name id         </title>     </head> <?php if(isset($_post["searchname"])) {     $id = $_post["searchname"];      $connect = new mysqli("localhost","adarsh","yeah!","adarsh");     $a = mysql_query("select * users id='$id'",$connect);     $row = mysql_fetch_assoc($a);     echo "$row[0] , $row[1] , $row[2]"; } else {     echo "error"; } ?>     <body>         <form method="post" action="<?php echo htmlspecialchars($_server["php_self"]);?>">             <input type="text" maxlength="6" name="searchname">             <input type="submit" name="submit">         </form>     </body> 

output when enter id:

 , ,  

there entries in mysql table unable fetch them. wrong code?

update: have tried mysql_fetch_array not working.

main problem you're miximg mysqli , mysql. these absolutely different apis. assuming have

$id = $_post["searchname"];  $connect = new mysqli("localhost","adarsh","yeah!","adarsh"); 

next should:

$result = $connect->query("select * users id='$id'"); 

then results:

while ($row = $result->fetch_assoc()) {     var_dump($row); } 

and of course, instead of directly putting values query use prepared statements.

update: mistakes:

  • your main mistake mixing apis. when use mysql (which deprecated , mustn't use anymore) can't use of mysqli functions , vice versa.

  • next - create mysqli object new, should work in object-oriented style, i.e. calling methods mysqli object.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -