Jump to content

mysqli prepared statements help


ccirish

Recommended Posts

Try though I might I cannot find a solution to this problem. When replacing ? with an actual value it works fine. Why can't I get bind_param to work with this? What am I doing wrong? 

 

Thanks.

<?php
//Config Settings
 $mysqli = new mysqli("localhost", "a", "b", "c");
 $TeamID = $_GET["TeamID"];

//Check that we have a DB
 if (!$mysqli)
 {
        printf("Connect failed: %s\n", mysqli_connect_error);
        exit();
 }

//StartHTML
 header("Content-Type: application/xml; charset=ISO-8859-1");
 echo '<?xml version="1.0" encoding="ISO-8859-1" ?>
 <rss version="2.0">
 <channel>
 <title>Title</title>
 <link>Link</link>
 <description>Description</description>';

//Pull Data
 $stmt = $mysqli->stmt_init();
 if ($stmt = $mysqli->prepare("SELECT title, link, description FROM ( ? )"))
 {
        $stmt->bind_param('s', $TeamID);
        $stmt->execute();
        $stmt->fetch();
        $stmt->bind_result($title, $link, $description);
 }
 else
 {
        echo $mysqli->error;
 }

//Loop Through Data
 while ($stmt->fetch())
 {
        echo '<item>
        <title>'.$title.'</title>
        <link>'.$link.'</link>
        <description>'.$description.'</description>
        </item>';
 }

//Shut this bitch down
 $stmt->close();
 $mysqli->close();
 echo '</channel></rss>';
?>
Link to comment
https://forums.phpfreaks.com/topic/282154-mysqli-prepared-statements-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.