0
   <table border="2">
                   <tr>
                      <th>Memeber Id</th>
                      <th>Lastname</th>
                      <th>Firstname</th>
                      <th>Birthdate</th>
                      <th>Gender</th>
                      <th>Status</th>
                      <th>Dedication Date</th>
                      <th>Acceptance Date</th>
                      <th>Baptism Date</th>
                      <th>Mother</th>
                      <th>Father</th>
                      <th>Decription</th>
                    </tr>    

            <?php
                  $con = mysql_connect("localhost", "root", "");
                  $er = mysql_select_db("memberdb");
                  $query = "insert into memberinformation values('$memberid','$lastname','$firstname','$birthdate','$gender','$status','$dedicationdate'
                    ,'$acceptancedate','$baptismdate','$mother','$father','$description')";
                  $result = mysql_query($query);
                  $result = mysql_query("SELECT * FROM memberinformation");

                  if (mysqli_connect_errno())
                    {
                        echo "Failed to connect to MySQL: " . mysqli_connect_error();
                        //you need to exit the script, if there is an error
                        exit();
                    } 

                    while ($array = mysql_fetch_row($result));
                    {
                        echo "<tr>";
                        echo "<td>" . $row['memberid'] . "</td>";
                        echo "<td>" . $row['lastname'] . "</td>";
                        echo "<td>" . $row['firstname'] . "</td>";
                        echo "<td>" . $row['birthdate'] . "</td>";
                        echo "<td>" . $row['gender'] . "</td>";
                        echo "<td>" . $row['status'] . "</td>";
                        echo "<td>" . $row['dedicationdate'] . "</td>";
                        echo "<td>" . $row['acceptancedate'] . "</td>";
                        echo "<td>" . $row['baptismdate'] . "</td>";
                        echo "<td>" . $row['mother'] . "</td>";
                        echo "<td>" . $row['father'] . "</td>";
                        echo "<td>" . $row['description'] . "</td>";
                        echo "</tr>";

                        echo "<script> alert('Tama ka.'); </script>";
                    }

                    echo "</table>";

                    mysql_close($con);
            ?>

I have a problem because the code does not output what I am expecting. It should output the data from memberinformation table from the member database. Please help me if there is some lacking lines in this code or I have some mistakes.

3
  • First: where are you getting the variables you're inserting from? Second: you're using both mysql and mysqli..? Third: what's the output? Provide us more informations Commented Jul 10, 2014 at 8:36
  • 2
    Yes, NEVER EVER mix mysql and mysqli. And you say you get output you don't expect. But WHAT output do you get? Tell us more, so we can help you, we are no wizards (not all of us). Commented Jul 10, 2014 at 8:37
  • $array and $row aren't the same, and the semi-colon at the end of mysql_fetch_row($result)); also causes issues. Enabling error reporting probably would have given you these answers. Commented Jul 10, 2014 at 8:39

5 Answers 5

2

You are reading the value $row, while the data is in $array:

while ($array = mysql_fetch_row($result));
...
echo "<td>" . $row['memberid'] . "</td>";

This should work:

while ($row = mysql_fetch_row($result)){
...
echo "<td>" . $row['memberid'] . "</td>";
...
}
Sign up to request clarification or add additional context in comments.

Comments

2

You mixed up MySQL and MySQLi libraries.

Replace mysqli_connect_errno() with mysql_errno() to use MySQL library. (also for mysqli_connect_error())

But it's very important that you shouldn't use deprecated MySQL library (mysql_* functions). Replace it with MySQLi and PDO instead.

Comments

1

You have $array = mysql_fetch_row($result) but in table you are printing e.g. $row['memberid'] instead of $array['memberid']. I believe that will be your problem.

Comments

1

change $array = mysql_fetch_row($result) in to $row = mysql_fetch_row($result)

Comments

0
  • First of all, stop using mysql_ functions
  • Second, you're mixing API's (mysql_ and mysqli_). Choose mysqli_* instead.
  • Third, it should be $row = mysql_fetch_row($result)
  • Fourth, as much as possible use parameterized queries / prepared statements
  • Fifth, always turn on error reporting

Example:

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

$con = new mysqli('localhost', 'root', '', 'memberdb');
$result = mysqli_query($con, 'SELECT * FROM memberinformation');
 if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    echo "<script> alert('May Mali Ka.');</script>";
    //you need to exit the script, if there is an error
    exit();
}

$stmt = $con->prepare('INSERT INTO memberinformation VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
$stmt->bind_param('ssssssssssss', $memberid,$lastname,$firstname,$birthdate,$gender,$status,$dedicationdate,$acceptancedate,$baptismdate,$mother,$father,$description);
$stmt->execute();

?>
<style>table, tr, td {border: 1px solid black;}</style>
<table>
    <tr>
        <th>Memeber Id</th><th>Lastname</th><th>Firstname</th><th>Birthdate</th><th>Gender</th><th>Status</th><th>Dedication Date</th>
        <th>Acceptance Date</th><th>Baptism Date</th><th>Mother</th><th>Father</th><th>Decription</th>
    </tr>
    <?php while($row = $result->fetch_assoc()): ?>
        <tr>
            <td><?php echo $row['lastname']; ?></td>
            <td><?php echo $row['firstname']; ?></td>
            <td><?php echo $row['birthdate']; ?></td>
            <td><?php echo $row['gender']; ?></td>
            <td><?php echo $row['status']; ?></td>
            <td><?php echo $row['dedicationdate']; ?></td>
            <td><?php echo $row['acceptancedate']; ?></td>
            <td><?php echo $row['baptismdate']; ?></td>
            <td><?php echo $row['mother']; ?></td>
            <td><?php echo $row['father']; ?></td>
            <td><?php echo $row['description']; ?></td> 
        </tr>
    <?php endwhile; ?>
</table>

2 Comments

sidenote: do not use border="2"; use CSS instead
@Raptor haha actually i didn't notice i put two in there, yeah of course css is way way better against attribute border

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.