Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

php - Fatal error: Call to a member function prepare() on a non-object in

this is how I have to build the transmitters infomation on to a php file to send to login page when it is

<form action="http://,,,.dk/activate_updater.php" method="post" name="formular" onsubmit="return validerform ()">
                                 <table border="0">
                                     <tr>
                                         <td id="tb-w_a"><p>Kategori</p></td>
                                         <td>:</td>
                                         <td>
                                         <select name="kategori">
                                         <?php
                                         $query = "SELECT id_katogori, navn FROM kategori";
                                         $result = $mysqli->query($query);
                                         while(list($id_katogori, $navn) = $result->fetch_row())
                                         {
                                             echo "<option value="$id_katogori">$navn</option>";  
                                         }
                                         ?>
                                         </select>
                                         </td>
                                     </tr>
                                     <tr>
                                         <td id="tb-w_a"><p>Djnavn</p></td>
                                         <td>:</td>
                                         <td><input type="text" name="djnavn"></td>
                                     </tr>
                                     <tr>
                                         <td id="tb-w_a"><p>Facebook</p></td>
                                         <td>:</td>
                                         <td><input type="text" name="facebook"></td>
                                     </tr>
                                     <tr>
                                         <td id="tb-w_a"><p>Pris</p></td>
                                         <td>:</td>
                                         <td><input type="text" name="pris"></td>
                                     </tr>
                                     <tr>
                                         <td id="tb-w_a"><p>Booking Email</p></td>
                                         <td>:</td>
                                         <td><input type="email" name="booking"></td>
                                     </tr>
                                     <tr>
                                         <td id="tb-w_a"><p>Mobil</p></td>
                                         <td>:</td>
                                         <td><input type="text" name="mobil"></td>
                                     </tr>
                                     <tr>
                                         <td id="tb-w_a"><p>Upload Profil</p></td>
                                         <td>:</td>
                                         <td><input type="file" name="profilbillede" /></td>
                                     </tr>
                                 </table>
                             <textarea name="profiltekst" style="width:500px; height:170px;"></textarea><br />
                             <input type="submit" value="Godkend brugere" name="godkendt-brugere">
                         </form>

so the new page file is like this where there are errors on the page ..

<?php
     if($stmt = $mysqli->prepare('UPDATE `brugere` SET `rank`=2, `katogori`=?, `djnavn`=?, `profilbillede`=?, `profiltekst`=?, `facebook`=?, `pris`=?, `booking`=?, `mobil`=? WHERE `code`=?'))
     {

         $stmt->bind_param('iiiiiiiis', $katogori, $djnavn, $profilbillede, $profiltekst, $facebook, $pris, $booking, $mobil, $g_code);
         //fra input ting ting..
         $katogori = $_POST["kategori"];
         $djnavn = $_POST["djnavn"];
         $profilbillede = $_POST["profilbillede"];
         $profiltekst = $_POST["profiltekst"];
         $facebook = $_POST["facebook"];
         $pris = $_POST["pris"];
         $booking = $_POST["booking"];
         $mobil = $_POST["mobil"];
         $g_code = $_GET["code"];

         $stmt->execute();
         $stmt->close();
         header('http://....dk/ (...));
     }
     else
     {
         echo 'Der opstod en fejl i erkl?|ringen: ' . $mysqli->error;
     }
 ?>

but when it comes onto the file / page says it like this ...

Fatal error: Call to a member function prepare() on a non-object in /home/jesperbo/public_html/....dk/activate_updater.php on line 2

that is the where it says like this

if($stmt = $mysqli->prepare('UPDATE `brugere` SET `rank`=2, `katogori`=?, `djnavn`=?, `profilbillede`=?, `profiltekst`=?, `facebook`=?, `pris`=?, `booking`=?, `mobil`=? WHERE `code`=?'))

I'm not exactly the best person to see the error but it would be super if you had seen what I've needless churning wrong since it will not be up on the database

hope you can help me with this problem!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As far as I can see, you never actually create your $mysqli object (unless it's loaded in another file, which includes this one). You need to create it:

$mysqli = new MySQLi('localhost', 'username', 'password', 'dbname');

// then
if($stmt = $mysqli->prepare('UPDATE `brugere` SET `rank`=2, `katogori`=?, `djnavn`=?, `profilbillede`=?, `profiltekst`=?, `facebook`=?, `pris`=?, `booking`=?, `mobil`=? WHERE `code`=?'))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...