I need help mga master please
my Main.php
my code.php
my code2.php
sample usn id: aa
OUPUT for retrieving data is ok :
error in inserting data I dont know why huhu
input:
firstname : phcorner
lastname: phcorner
and got this error
nag eexpect sya ng apat daw since okay naman sa retrieving data dito lang talaga ako may problema insert chuchu ano ba problema sa function ko
GOAL is to make a function that could execute all queries.
my Main.php
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="POST" action="code2.php">
<input type="text" name="usn">
<input type="text" name="fname" placeholder="first name">
<input type="text" name="lname" placeholder="Last name">
<input type="submit" name="view" value="SELECT">
<input type="submit" name="insert" value="INSERT">
</form>
</body>
</html>
my code.php
PHP:
<?php
include('includes/db_connection.php');
$conn = getDB();
function sql($conn, $q, $params, $return){
//prepare statement
$stmt = $conn->prepare($q);
//execute statement
$stmt->execute($params);
//Decide whether to return the rows themselves , or just the rows
if ($return == "rows") {
return $stmt->fetchAll();
}
elseif ($return == "count") {
return $stmt->rowCount();
}
}
?>
my code2.php
PHP:
<?php
// Select / Call function
include('code.php');
$usn = $_POST['usn'];
if (isset($_POST['view'])) {
# code...
$conn = getDB();
$rows = sql($conn, "SELECT * FROM tbl_student WHERE usn = ?", array($usn), "rows");
// Get results
foreach ($rows as $row) {
echo $row['usn'].' '.$row['fname'].' '.$row['lname'];
}
}
//INSERT
if (isset($_POST['insert'])) {
# code...
$lname = $_POST['lname'];
$fname = $_POST['fname'];
$conn = getDB();
sql($conn, "INSERT INTO tbl_student('fname','lname') VALUES (?,?)", array($fname, $lname));
}
// //UPDATE
// sql($conn, "UPDATE tbl_student SET fname = ? WHERE usn = ?", array($fname, $usn))
// //DELETE
// sql($conn, "DELETE FROM tbl_student WHERE usn = ?", array$usn);
?>
sample usn id: aa
OUPUT for retrieving data is ok :
error in inserting data I dont know why huhu
input:
firstname : phcorner
lastname: phcorner
and got this error
nag eexpect sya ng apat daw since okay naman sa retrieving data dito lang talaga ako may problema insert chuchu ano ba problema sa function ko
GOAL is to make a function that could execute all queries.
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.