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 = "secretpassword";
- $dbname = "widget_corp";
- $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
- // test if connection occured
- if(mysqli_connect_errno())
- {
- die("database connection failed:". mysqli_connect_error() .
- " " . mysqli_connect_errno() . " " );
- }
- ?>
- <?php
- //often these are $_POST values through a web form.
- // 2. Perform the database query
- $id = 5;
- $menu_name = "delete me";
- $position = 4;
- $visible = 1;
- $query = "UPDATE subjects SET ";
- $query .= "menu_name = '{ menu_name}', ";
- $query .= "position = {$position}, ";
- $query .= "visible = {$visible}, ";
- $query .= "WHERE id = {$id} ";
- $result = mysqli_query($connection, $query);
- if ($result)
- {
- //success
- //redirect to somepage.php
- echo "success!";
- }
- else
- {
- //failure
- //$message = "subjet update failed.";
- die("database query failed. " . mysqli_error($connection));
- }
- ?>
- <DOCTYPE HTML>
- <head>
- <title> databases </title>
- </head>
- <body>
- </body>
- </html>
- <?php
- // 5. close the database connection
- mysqli_close($connection);
- ?>
- $query = "UPDATE subjects SET ";
- $query .= "menu_name = '{ menu_name}', ";
- $query .= "position = {$position}, ";
- $query .= "visible = {$visible} ";
- $query .= "WHERE id = {$id} ";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement