Jump to content

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '<?php include "connection.php"' at line 1


Zany

Recommended Posts

<?php
include "connection.php";
?>

<html lang="en">
<head>
  <title>belgicaAct2_Add/Edit/Delete/View</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body

<div class="container">
<div class="col-lg-4">
  <h2>Course & Learning Management System</h2>
  <h2>Add/Edit/Delete/View</h2>
  <form action="" name="form1" method="post">
    <div class="form-group">
      <label for="email">firstname</label>
      <input type="text" class="form-control" id="firstname" placeholder="Enter firstname" name="firstname">
    </div>
    <div class="form-group">
      <label for="pwd">lastname</label>
      <input type="text" class="form-control" id="lastname" placeholder="Enter lastname" name="lastname">
    </div>
    <div class="form-group">
      <label for="pwd">email</label>
      <input type="text" class="form-control" id="email" placeholder="Enter email" name="email">
    </div>
    <div class="form-group">
      <label for="pwd">contact</label>
      <input type="text" class="form-control" id="contact" placeholder="Enter contact" name="contact">
    </div>
    <button type="submit" name="insert" class="btn btn-default">Insert</button>
    <button type="submit" name="update" class="btn btn-default">Update</button>
    <button type="submit" name="delete" class="btn btn-default">Delete</button>
  </form>
</div>
</div>

<div class="col-lg-12">

<table class="table table-bordered">
    <thead>
      <tr>
      <th>#</th>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Email</th>
        <th>Contact</th>
        <th>Edit</th>
        <th>Delete</th>
      </tr>
    </thead>
    <tbody>
      
    <?php
    $result=mysqli_query($link,"select * from table1");
    while($row=mysqli_fetch_array($result))
    {
       echo "<tr>";
       echo "<td>"; echo $row["id"]; echo "</td>";
       echo "<td>"; echo $row["firstname"]; echo "</td>";
       echo "<td>"; echo $row["lastname"]; echo "</td>";
       echo "<td>"; echo $row["email"]; echo "</td>";
       echo "<td>"; echo $row["contact"]; echo "</td>";
       echo "<td>"; ?> <a href="edit.php?id=<?php echo $row["id"]; ?> "><button type="button" class="btn btn-success">Edit</button></a> <?php echo "</td>";   
       echo "<td>"; ?> <a href="delete.php?id=<?php echo $row["id"]; ?> "><button type="button" class="btn btn-danger">Delete</button></a> <?php echo "</td>";   
       
       echo "</tr>";
        
        
    }
    
    ?>
    
    
    </tbody>
 </table>

</div>

</body>


<?php
if(isset($_POST["insert"]))
{
    mysqli_query($link,"insert into table1 values(NULL,'$_POST[firstname]','$_POST[lastname]','$_POST','$_POST[contact]')"); 

    ?>
    <script type="text/javascript">
    window.location.href=window.location.href;
    </script>
    <?php
  
}

if(isset($_POST["delete"]))
{
    mysqli_query($link, "delete from table1 where firstname='$_POST[firstname]'") or die(mysqli_error($link));
    ?>
    <script type="text/javascript">
    window.location.href=window.location.href;
    </script>
    <?php
    
}

if(isset($_POST["update"]))
{
    mysqli_query($link, "update table1 set firstname='$_POST[lastname]' where firstname='$_POST[firstname]'") or die(mysqli_error($link));
    ?>
    <script type="text/javascript">
    window.location.href=window.location.href;
    </script>
    <?php
}

?>

</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.