0

I am having trouble with my script. I know that the database has two rows and it is not outputting. I don't think I'm getting an data for my query. Maybe I am doing something wrong. I trying to output contents. Maybe another pair of eyes would help?

<?php


$host = "blah. Com";
$database = "blah";
$user = "blah";
$password = "blah";

$con =mysqli_connect($host,$user,$password,$database);

if(!$con)
{
echo "Could not connect: " . $database;
}

$sql = "SELECT * FROM CreditCards";

$result = mysqli_query($con,$sql);

echo "<select name=\"word\">";


while($ary = mysql_fetch_array($result))
{
    echo "<option value=\"" . $ary[cc_id] . "\">" . $ary[type] . "-" . $ary[last_four] . "</option>";
}
echo "</select>";
mysqli_close($con);

?>

Sorry in advance about the formatting. I on my mobile device...

4
  • Try echoing this: mysqli_error($con) and write what error message you are receiving.
    – cbronson
    Jul 19, 2013 at 2:03
  • Why is it people never check the result of a query? Try if (($result = mysqli_query($con, $sql)) == false) {echo "SQL error:".mysqli_error;}
    – user1864610
    Jul 19, 2013 at 2:05
  • 1
    @Mike W: We don't check the result of a query, because we like to put our little pinky to the corner of our mouth, Dr. Evil style, and say "I just assume it will all go to plan. What?" :) But we do check if the connection was made, echo out a message if it wasn't. Then, whether or not the connection was successful, we proceed to execute a query on that connection. "I just assume the query will work without a connection. What?" :) Jul 19, 2013 at 2:17
  • Is it showing any error that we may think on? or a blank page? Jul 19, 2013 at 3:13

1 Answer 1

0

Have you tried mysqli_fetch_array instead of mysql_fetch_array at your while loop?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.