I have a db called 'members' and a table called 'users'. I want an id to be taken when a user signs up and then that id used to display just that one users details from the table rather than all rows in the table. This is my sign up code:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("members", $con);
$sql="INSERT INTO users (name, email, address, dob, password)
VALUES('$_POST[name]','$_POST[email]','$_POST[address]','$_POST[dob]','$_POST[mypassword]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
{
header ("Location: sign_in.php");
exit;
}
mysql_close($con)
?>
And this is my display table code:
<?php
// Create connection
$conn = new mysqli("localhost", "root", "", "members");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT name, email, address, dob FROM users";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>Name</th><th>Email</th><th>Address</th> <th>DOB</th></tr> id-";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["name"]."</td><td>".$row["email"]."</td><td>".$row["address"]."</td><td>".$row["dob"]."</td></tr>";
}
echo "</table>";
} else {
echo "<p>No Details</p><style>p{color: #336699; font-size: 20pt; font-family: Gulim; font-weight: bold; align: center; padding: 10px; position: absolute; top: 80; left: 560; z-index: 2; border-spacing: 0px;}</style> ";
}
$conn->close();
?>