Data

zigi 01

JF-Expert Member
Joined
Oct 22, 2017
Posts
325
Reaction score
198
What are the problem on that code
1.php script
2.database table
 
nimejaribu kupandisha code hapa, zimekataa, lkn jaribu kutoa hiyo ID hapo kwenye inset kama id ni primary key
 
nimejaribu kupandisha code hapa, zimekataa, lkn jaribu kutoa hiyo ID hapo kwenye inset kama id ni primary key
Id siyo primary key kwenye request table ni foreign key from another table
 
Id siyo primary key kwenye request table ni foreign key from another table


PHP:
<?php
session_start();
$_SESSION['messsage'] = '   ';
$mysqli = new mysqli('host', 'user', 'password', 'databases');
// Eg: $mysqli = new mysqli('localhost', 'root', '', 'alpha');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
      $smg= $mysqli->real_escape_string($_POST['smg']); // kujikinga na sql injection
     // $smg= htmlentities($_POST['smg']); kutoa tags kwenye inputs
      //$smg= htmlspecialchars($_POST['smg']);
     // $smg= strip_tags($_POST['smg']);

       $sql = "INSERT INTO request (smg) "
               . "VALUES ('$smg' )";
                if ($mysqli->query($sql) === true){
                $_SESSION['message'] = "Saccessful text hire!";
                header("location: index.php");
                    }
                  else {
                        $_SESSION['message'] = "ERROR TEXT";
                                }
                          }
?>

<!DOCTYPE html>
<html>
<head>
   <title></title>
</head>
<body>
<!--page start--->
<h3> <?= $_SESSION['message'] ?></h3>
  <!--end of the page-->
<form action="request_book.php" method="post" enctype="multipart/form-data">
  <!--form code--->
  </form>
</body>
</html>
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…