Reputation: 1
<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.
Upvotes: 0
Views: 71
Reputation: 7948
mysql_
functionsmysql_
and mysqli_
). Choose mysqli_*
instead.$row = mysql_fetch_row($result)
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>
Upvotes: 0
Reputation: 1132
change $array = mysql_fetch_row($result) in to $row = mysql_fetch_row($result)
Upvotes: 1
Reputation: 54252
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.
Upvotes: 2
Reputation: 664
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>";
...
}
Upvotes: 2
Reputation: 158
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.
Upvotes: 1