$sql = "insert into sports (sport_name) values("Soccer');
if(mysqli_query($conn, $sql)){
echo("New record added");
}else{
echo $sql." ". mysqli_error($conn)) ;
}
}
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
sql with inclusion of variables
$sql = "INSERT INTO table_name (first, last, age, ...)
VALUES ('$first','$last', $age)";
DELETE FROM table_name WHERE condition;
$sql = "DELETE FROM students WHERE student id = '$id'";
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
$sql = "UPDATE students
SET year = 1
WHERE student_id = 1";
<?php
//store the query into a variable
$sql = "SELECT id, firstname, lastname FROM MyGuests";
//run the query and store the result of the query in a variable called $result
$result = mysqli_query($conn, $sql); //run the query
// print table header and opening table tag
echo "<table><tr><th>ID</th><th>Name</th></tr>";
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "<tr><td>".$row["id"]."</td><td>".$row["firstname"]." ".$row["lastname"]."</td> </tr>";
}
echo "</table>";
//close connection
mysqli_close($conn);
?>
Activity: <select name="activity">
<?php
$sql = "select * from activities order by activity_name");
$options = mysqli_query($conn,$sql);
if(mysqli_num_rows($option)){
while($row = mysqli_fetch_assoc($options)){
echo("<option value=\"".$row["activity_id"]."\">".$row["activity_name"]."</option>");
}
}else{
echo("no records");
}
?>
</select>
header('location:index.php');
Array length - count(array_name)
Check to see if form variable has a value - isset($_POST['field_name']);
Cast variable to integer - intval(var)
In this example I have placed the Jquery function in outer function so it can be called after the table has been created as its dynamically created each time.
<head>
<!-- CDN to jquery for clicker -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
function addClicks(){
$('td').click(function() { //add listener to each td cell for on click
var col = $(this).index() //get col location as int
var row = $(this).parent().index(); //get row location as int
console.log("row index:" + row + ", col index :" + col);
//output the row and col that you clicked
});
}