You are viewing our Forum Archives. To view or take place in current topics click here.
php error help please ??
Posted:

php error help please ??Posted:

blueninjn
  • Junior Member
Status: Offline
Joined: Dec 28, 201310Year Member
Posts: 85
Reputation Power: 3
Status: Offline
Joined: Dec 28, 201310Year Member
Posts: 85
Reputation Power: 3
error code

Fatal error: Call to undefined method mysqli::fetch_array() in C:\Users\Huby\Documents\Xammp\htdocs\BBMPinList\index.php on line 39


<html>
<head>
<title>
       Home- Page
</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
      <header id="main_header">
           <div id="middle_nav">
             <div id="left_child">
                 <img src="images/logo.png" width="300px" height="25px"/>
             </div>
             <div id="right_child">
                 <a href="index.php">Home</a>
                 <a href="bbmlist.php">BBM list</a>
             </div>
          </div>
      </header>

      <div id="main_content">
          <div id="main_screen">
              <div id="bbmboys">
                  <h1>
                    Boys BBM pin list
                  </h1>
                  <br />
                  <div id="profile">
                      <div id="left_profile">
                          <img src="images/defualt.jpg" width="75px" height="75px"/>
                      </div>
                      <?php

                      $mysqli = new mysqli("localhost", "root", "", "bbm");

                      $query = "SELECT * FROM pins WHERE gender='male'";
                      $result = $mysqli->query($query);

                      while($row = $mysqli->fetch_array($result)) {
                      echo $row['Name'];
                      echo "<br />";
                      }

                      ?>
                      <div id="right_profile">
                           <h4>Name:Andrew Jack Huby</h4>
                           <h6>Date:<?php echo date("d")?>/<?php echo date("m")?>/<?php echo date("Y"); ?></h6>
                           <h4>Pin:234533</h4>
                      </div>
                  </div>
              </div>
              <div id="bbmgirls">
                  <h1>
                      Girls BBM pin list
                  </h1>
                  <br />

              </div>
          </div>
      </div>
      <footer id="main_footer">
            <div id="holder">
            &copy SocialEYE <?php echo date("Y");   ?>. All rights reserved
            </div>           
      </footer>
</body>
</html>
#2. Posted:
iyop45
  • Prospect
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83

$mysqli = new mysqli("localhost", "root", "", "bbm");
if($stmt = $mysqli->prepare("SELECT name FROM pins WHERE gender='name'")){
   $stmt->execute();
   $stmt->bind_result($name);
   while($stmt->fetch()){
      echo $name.'<br>';
   }
   $stmt->close();
}else{
   echo 'failed to prepare query';
}

In your case you could of just used mysqli_fetch_array tp fix the error but what I've posted above is probably a better solution.


Last edited by iyop45 ; edited 1 time in total
#3. Posted:
blueninjn
  • Junior Member
Status: Offline
Joined: Dec 28, 201310Year Member
Posts: 85
Reputation Power: 3
Status: Offline
Joined: Dec 28, 201310Year Member
Posts: 85
Reputation Power: 3
iyop45 wrote

$mysqli = new mysqli("localhost", "root", "", "bbm");
if($stmt = $mysqli->prepare("SELECT name FROM pins WHERE gender='name'")){
   $stmt->execute();
   $stmt->bind_result($name);
   while($stmt->fetch()){
      echo $name.'<br>';
   }
   $stmt->close();
}else{
   echo 'failed to prepare query';
}


I get this error

Notice: Undefined variable: mysqli in C:\Users\Huby\Documents\Xammp\htdocs\BBMPinList\index.php on line 40

Fatal error: Call to a member function prepare() on a non-object in C:\Users\Huby\Documents\Xammp\htdocs\BBMPinList\index.php on line 40
#4. Posted:
iyop45
  • Prospect
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83
So you don't even know how to use php? I assumed you had at least some understanding but obviously not.


 $mysqli = new mysqli("localhost", "root", "", "bbm");

^that line connects to your mysql database, if it fails it will be assigned bool(false) and so you won't be able to execute any proceeding queries with it.
At least try die(var_dump($mysqli)); before you prepare the statement and if it does evaluate as false then you haven't entered the correct database credentials.
Whenever you learn a language you really must learn how to debug, this may help you see if the connection is made.

if(mysqli_connect_errno()){
    printf("DB error: %s", mysqli_connect_error());
    exit();
}

Though considering the two errors are on the same line I assume you tried to prepare the statement before assigning the object to $mysqli, which is just stupid. You can't use a variable before you've assigned and I was under the assumption that is common sense.
#5. Posted:
blueninjn
  • Junior Member
Status: Offline
Joined: Dec 28, 201310Year Member
Posts: 85
Reputation Power: 3
Status: Offline
Joined: Dec 28, 201310Year Member
Posts: 85
Reputation Power: 3
iyop45 wrote So you don't even know how to use php? I assumed you had at least some understanding but obviously not.


 $mysqli = new mysqli("localhost", "root", "", "bbm");

^that line connects to your mysql database, if it fails it will be assigned bool(false) and so you won't be able to execute any proceeding queries with it.
At least try die(var_dump($mysqli)); before you prepare the statement and if it does evaluate as false then you haven't entered the correct database credentials.
Whenever you learn a language you really must learn how to debug, this may help you see if the connection is made.

if(mysqli_connect_errno()){
    printf("DB error: %s", mysqli_connect_error());
    exit();
}

Though considering the two errors are on the same line I assume you tried to prepare the statement before assigning the object to $mysqli, which is just stupid. You can't use a variable before you've assigned and I was under the assumption that is common sense.

can you explain the code you gave me please i really want to learn and know what its doing and i want it to select every profile that is a male and echo out the Name,Date,pin of them how would i do this pleas ehelp and explain i would really appreciate it
#6. Posted:
iyop45
  • Prospect
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83
php.net/mysqli        
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.