php - Retrieveing data from database results in 0 results -


i've got multiple entries in database, yet php code returns 0 entries.

here's php:

error_reporting(e_all);  ini_set('display_errors', 1);    $conn = new mysqli($host, $user, $pass, $databasename);    // check connection can established  if ($conn->connect_error) {      die("connection failed: " . $conn->connect_error);  }    $sql = "select charts_url, charts_date, charts_retrace, charts_start_of_swing_trade, charts_end_of_swing_trade, charts_bull_flag, charts_bear_flag, charts_ema_crossover, charts_trading_instrument charts";    $result = $conn->query($sql);    if($result && $result->num_rows > 0) {      // output data of each row    echo "       <table>         <tr>           <td><strong><u>chart</u></strong></td>           <td><strong><u>date</u></strong></td>           <td><strong><u>retrace</u></strong></td>           <td><strong><u>start of swing trade</u></strong></td>           <td><strong><u>end of swing trade</u></strong></td>           <td><strong><u>bull flag</u></strong></td>           <td><strong><u>bear flag</u></strong></td>           <td><strong><u>ema crossover</u></strong></td>           <td><strong><u>trading instrument</u></strong></td>         </tr>";      while ($row=mysqli_fetch_array($sql)) {          echo  "<tr><td><a href=" . $row['charts_url']. "><img src=". $row['charts_url']. "></a></td>";          echo  "<td>" . $row['charts_date']. "</td>";          echo  "<td>" . $row["charts_retrace"]. "</td>";          echo  "<td>" . $row["charts_start_of_swing_trade"]. "</td>";          echo  "<td>" . $row["charts_end_of_swing_trade"]. "</td>";          echo  "<td>" . $row["charts_bull_flag"]. "</td>";          echo  "<td>" . $row["charts_bear_flag"]. "</td>";          echo  "<td>" . $row["charts_ema_crossover"]. "</td>";          echo  "<td>" . $row["charts_trading_instrument"]. "</td></tr>";      }       echo "</table>";  } else {      echo "0 results";  }  $conn->close();     ?>

obviously, cut out actual database info such username, password, etc. here's snippet php code used submit data database submits data database.

 $sql = "insert charts (charts_url, charts_date, charts_retrace, charts_start_of_swing_trade, charts_end_of_swing_trade, charts_bullflag, charts_bearflag, charts_ema_crossover, charts_trading_instrument) values (?, ?, ?, ?, ?, ?, ?, ?, ?)";

so can double check variables between data retrieval/display code , data insertion code. data insertion code works perfectly. see data inthe database submitted through form. when try , retrieve data , display it, "0 results" message. ideas?

issue #1
have typos in query

insert ... charts_bullflag, charts_bearflag ... select ... charts_bull_flag, charts_bear_flag ... 

you have _ in 2 of column names in select

issue #2
doing fetch_array() on query string

while ($row=mysqli_fetch_array($sql)) { 

you need on query result - $result

while ($row=mysqli_fetch_array($result)) { 

or since using oop style query, loop in oop style

while ($row=$result->fetch_array(mysqli_num)) { 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -