Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //1. create a database connection
- $dbhost = "localhost";
- $dbuser = "widget_cms";
- $dbpass = "funkyguy";
- $dbname = "widget_corp";
- $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
- // Test database connection
- if(mysqli_connect_errno()) {
- die("database connection failed: " .
- mysqli_connect_error() .
- "(" . mysqli_connect_errno() . ")"
- );
- }
- ?>
- <?php
- //this are the form values from $_POST
- $id = 6;
- $menu_name = "Delete me";
- $position = 4;
- $visible = 1;
- //2. perform database query
- $query = "UPDATE subjects SET ";
- $query .= "menu_name = '{$menu_name}', ";
- $query .= "position = {$position}, ";
- $query .= "visible = {$visible}, ";
- $query .= "WHERE id = {$id}";
- echo $query;
- $result = mysqli_query($connection, $query);
- // test if there was a query error
- if($result) {
- echo "success";
- }else {
- die(" Database query failed: " . mysqli_error($connection));
- }
- ?>
- <!doctype html>
- <html lang="en">
- <head>
- <title>Database</title>
- </head>
- <body>
- </body>
- </html>
- <?php
- //5. Close the connection
- mysqli_close($connection);
- ?>
- $query = "UPDATE subjects SET ";
- $query .= "menu_name = '{$menu_name}', ";
- $query .= "position = {$position}, ";
- $query .= "visible = {$visible} ";
- # Comma removed here ----------^
- $query .= "WHERE id = {$id}";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement