Skip to content

Instantly share code, notes, and snippets.

@maxixo
Created January 20, 2026 20:13
Show Gist options
  • Select an option

  • Save maxixo/722565e3233b55f840ea70114d983ae2 to your computer and use it in GitHub Desktop.

Select an option

Save maxixo/722565e3233b55f840ea70114d983ae2 to your computer and use it in GitHub Desktop.
creating and reading data in php
<?php
// Create
$conn= new mysqli('localhost', "root", "", "myapp");
$name = "Alice";
$email = "[email protected]";
$age = 25;
$sql = "INSERT INTO users_ (name, email, age) VALUES ('$name', '$email', $age)";
if ($conn->query($sql)) {
echo "user added successfully";
} else {
echo "Error: : " . $conn->error;
}
//Read
$result = $conn->query("SELECT * FROM users_");
while($row = $result-> fetch_assoc()) {
echo "Name : ". $row['name'] . " | Email: " . $row['email'] . "<br>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment