Created
January 20, 2026 20:13
-
-
Save maxixo/722565e3233b55f840ea70114d983ae2 to your computer and use it in GitHub Desktop.
creating and reading data in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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