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="12605532y";
- $dbname = "widget_crop";
- $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
- $menu_name = ""Edit me"";
- $position=4;
- $visible = 1;
- // Often these are form values in POST
- // 2.Perform a db query
- $query ="INSERT INTO ";
- $query .="subjects (menu_name,position,visible) ";
- $query .="VALUES($menu_name,$position,$visible);rn";
- $query .="SELECT *";
- $query .="FROM subjects ";
- $query .="WHERE visible = 1 ";
- $query .="ORDER BY position ASC;";
- echo $query;
- $result = mysqli_multi_query($connection,$query);
- if(!$result){
- die("Database query failed !");
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/html4/loose.dtd">
- <style>
- body{
- font-family:tahoma;
- font-size:0.75em;
- }
- table{
- border-collapse: collapse;
- }
- td{
- padding-top:5px;
- padding-bottom:5px;
- padding-right:15px;
- padding-left:15px;
- background: lightblue;
- border-color: white;
- }
- </style>
- <html lang="en">
- <head>
- <title>untitled</title>
- </head>
- <body>
- <table border="2">
- <?php
- while($row = mysqli_fetch_assoc($result)){
- // 3. Use returned Data
- // output date from each row
- echo "<tr>";
- echo"<td>". $row["id"] ."</td>";
- echo"<td>". $row["menu_name"] ."</td>";
- echo"<td>". $row["position"] ."</td>";
- echo"<td>". $row["visible" ]."</td>";
- echo "</tr>";
- }
- ?>
- </table>
- <?php
- // 4. release the returned data
- mysqli_free_result($result);
- ?>
- </body>
- </html>
- <?php
- // 5. Close the connection
- mysqli_close($connection);
- ?>
- do {
- /* store first result set */
- if ($result = mysqli_store_result()) {
- while ($row = $result->fetch_row()) {
- if(!empty($row["id"])){
- echo "<tr>";
- echo"<td>". $row["id"] ."</td>";
- echo"<td>". $row["menu_name"] ."</td>";
- echo"<td>". $row["position"] ."</td>";
- echo"<td>". $row["visible" ]."</td>";
- echo "</tr>";
- }
- }
- $result->free();
- }
- /* print divider */
- if (mysqli_more_results()) {
- printf("-----------------n");
- }
- } while (mysqli_next_result());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement