Highlighted

Exporting data from webpage?

New Here ,
Oct 03, 2018

Copy link to clipboard

Copied

Im currently looking for a way to export data locally from the webpage. Into either an excel table or the access database. this is the section of code I want to reference;

<div data-role="content" data-theme="a">

<div data-role="fieldcontain">

<select name="select-choice-a" id="select-choice-a" data-native-menu="false">

<option>Floor</option>

<option value="floor1">1</option>

<option value="floor2">2</option>

<option value="floor3">3</option>

<option value="floor4">4</option>

<option value="floor5">5</option>

<option value="floor6">6</option>

<option value="floor7">7</option>

<option value="floor8">8</option>

<option value="floor9">9</option>

</select>

</div>

There are similiar divisions with other fields labelled unique values, and below is the submit and reset buttons im currently using;

<div class="ui-body ui-body-b">

<fieldset class="ui-grid-a">

<div class="ui-block-a"><button type="reset" data-theme="d">Cancel</button></div>

<div class="ui-block-b"><button type="submit" data-theme="a">Submit</button></div>

    </fieldset>

</div>

Any help or advice as to where to find a forum with more information regarding locally exporting information from Dreamweaver to tables would be greatly appreciated.

You're trying to mix PDO and mysqli functions which isnt going to work and you have no name tag associated with any of your form inputs which php needs to suck out the information from the form fields.

There's plenty wrong with the code you have posted. Have a look at the working code below which uses mysqli. Your database table (itemdatabase) needs to have the columns: floor, room, item, brand, quality set as varchar(100) plus an id column set as INT(11) and should be the primary auto-increment identifier.

Obviously you need to replace YOUR-PASSWORD in the database connection string:

<?php $conn = new mysqli('localhost' , 'root' , 'YOUR-PASWORD' , 'travelodgehotel');

//make sure special characters output correctly

mysqli_query($conn, "SET NAMES 'UTF8'") or die("ERROR: ". mysqli_error($conn));

?>

<?php

if(isset($_POST['submit'])) {

$floor = $conn->real_escape_string($_POST['floor']);

if(empty($floor)) {

$error['floor'] = "Please provide floor information";

}

$room = $conn->real_escape_string($_POST['room']);

if(empty($room)) {

$error['room'] = "Please provide room information";

}

$item = $conn->real_escape_string($_POST['item']);

if(empty($item)) {

$error['item'] = "Please provide item information";

}

$brand = $conn->real_escape_string($_POST['brand']);

if(empty($brand)) {

$error['brand'] = "Please provide brand information";

}

$quality = $conn->real_escape_string($_POST['quality']);

if(empty($quality)) {

$error['quality'] = "Please provide quality information";

}

if(!$error) {

$conn->query("INSERT INTO itemdatabase

(floor,

room,

item,

brand,

quality

)

VALUES

('$floor',

'$room',

'$item',

'$brand',

'$quality')");

echo "<h5>Successfully Inserted</h5>";

}

else {

echo "<ul>";

foreach($error as $error) {

echo "<li>$error</li>";

}

echo "</ul>";

}

}

?>

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

<title>jQuery Mobile: Theme Download</title>

</head>

<body>

<div data-role="page" data-theme="a">

<div data-role="header" data-position="inline">

<h1><img src="themes/images/TravelodgeHotelLogo.png" alt="" style="width:123.5px;height:26.25px;"></h1>

<div data-role="navbar">

<ul>

<li><a href="index.html" data-icon="home" class="ui-btn-active">Home</a></li>

<li><a href="spreadsheet.html" data-icon="grid">Spreadsheet</a></li>

<li><a href="information.html" data-icon="info">Information</a></li>

<li><a href="settings.html" data-icon="gear">Settings</a></li>

</ul>

</div>

</div>

<div data-role="content" data-theme="a">

<form action="index.php" method="post">

<div data-role="fieldcontain">

<select name="floor"  name="floor" id="floor" data-native-menu="false">

<option value="<?php

if(!isset($error['floor'])) {

echo $floor; } ?>" selected><?php if($_POST['floor'] == "") {

echo "Floor"; } else { echo $floor; }?></option>

<option value="Floor 1">Floor 1</option>

<option value="Floor 2">Floor 2</option>

<option value="Floor 3">Floor 3</option>

<option value="Floor 4">Floor 4</option>

<option value="Floor 5">Floor 5</option>

<option value="Floor 6">Floor 6</option>

<option value="Floor 7">Floor 7</option>

<option value="Floor 8">Floor 8</option>

<option value="Floor 9">Floor 9</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="room" name="room" id="room" data-native-menu="false">

<option value="<?php

if(!isset($error['room'])) {

echo $room; } ?>" selected><?php if($_POST['room'] == "") {

echo "Room"; } else { echo $room; }?></option>

<option value="Room 1">Room 1</option>

<option value="Room 2">Room 2</option>

<option value="Room 3">Room 3</option>

<option value="Room 4">Room 4</option>

<option value="Room 5">Room 5</option>

<option value="Room 6">Room 6</option>

<option value="Room 7">Room 7</option>

<option value="Room 8">Room 8</option>

<option value="Room 9">Room 9</option>

<option value="Room 10">Room 10</option>

<option value="Room 11">Room 11</option>

<option value="Room 12">Room 12</option>

<option value="Room 13">Room 13</option>

<option value="Room 14">Room 14</option>

<option value="Room 15">Room 15</option>

<option value="Room 16">Room 16</option>

<option value="Room 17">Room 17</option>

<option value="Room 18">Room 18</option>

<option value="Room 19">Room 19</option>

<option value="Room 20">Room 20</option>

<option value="Room 21">Room 21</option>

<option value="Room 22">Room 22</option>

<option value="Room 23">Room 23</option>

<option value="Room 24">Room 24</option>

<option value="Room 25">Room 25</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="item" name="item" id="item" data-native-menu="false">

<option value="<?php

if(!isset($error['item'])) {

echo $item; } ?>" selected><?php if($_POST['item'] == "") {

echo "Item"; } else { echo $item; }?></option>

<option value="Iron">Iron</option>

<option value="Microwave">Microwave</option>

<option value="Kettle">Kettle</option>

<option value="TV">TV</option>

<option value="Clock Radio">Clock Radio</option>

<option value="Phone">Phone</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="brand" name="brand" id="brand" data-native-menu="false">

<option value="<?php

if(!isset($error['brand'])) {

echo $brand; } ?>" selected><?php if($_POST['brand'] == "") {

echo "Brand"; } else { echo $brand; }?></option>

<option value="Iron KAMBROOK KI785">Iron - KAMBROOK KI785</option>

<option value="Microwave SAMSUNG BLACK">Microwave - SAMSUNG BLACK</option>

<option value="Kettle NERO EXPRESS BLACK">Kettle - NERO EXPRESS BLACK</option>

<option value="TV SAMSUNG 43"">TV - SAMSUNG 43"</option>

<option value="TV PHILIPS 40"">TV - PHILIPS 40"</option>

<option value="Clock Radio PHILIPS">Clock Radio - PHILIPS</option>

<option value="Clock Radio - IHOME">Clock Radio - IHOME</option>

<option value="Phone - BLACK TE">Phone - BLACK TEL</option>

<option value="OTHER">OTHER</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="quality" name="quality" id="quality" data-native-menu="false">

<option value="<?php

if(!isset($error['quality'])) {

echo $quality; } ?>" selected><?php if($_POST['quality'] == "") {

echo "Quality"; } else { echo $quality; }?></option>

<option value="Poor">Poor</option>

<option value="Very Bad">Very Bad</option>

<option value="Bad">Bad</option>

<option value="Average">Average</option>

<option value="Good">Good</option>

<option value="Very Good">Very Good</option>

<option value="Excellent">Excellent</option>

</select>

</div>

<div class="ui-body ui-body-b">

<fieldset class="ui-grid-a">

<div class="ui-block-a"><input type="reset" id="reset" value="Reset" data-theme="d" value="Cancel"></div>

<div class="ui-block-b"><input type="submit" name="submit" id="submit" value="submit" data-theme="a" value="Submit"></div>

    </fieldset>

</div>

</form>

</div>

</div>

</body>

</html>

Views

284

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Exporting data from webpage?

New Here ,
Oct 03, 2018

Copy link to clipboard

Copied

Im currently looking for a way to export data locally from the webpage. Into either an excel table or the access database. this is the section of code I want to reference;

<div data-role="content" data-theme="a">

<div data-role="fieldcontain">

<select name="select-choice-a" id="select-choice-a" data-native-menu="false">

<option>Floor</option>

<option value="floor1">1</option>

<option value="floor2">2</option>

<option value="floor3">3</option>

<option value="floor4">4</option>

<option value="floor5">5</option>

<option value="floor6">6</option>

<option value="floor7">7</option>

<option value="floor8">8</option>

<option value="floor9">9</option>

</select>

</div>

There are similiar divisions with other fields labelled unique values, and below is the submit and reset buttons im currently using;

<div class="ui-body ui-body-b">

<fieldset class="ui-grid-a">

<div class="ui-block-a"><button type="reset" data-theme="d">Cancel</button></div>

<div class="ui-block-b"><button type="submit" data-theme="a">Submit</button></div>

    </fieldset>

</div>

Any help or advice as to where to find a forum with more information regarding locally exporting information from Dreamweaver to tables would be greatly appreciated.

You're trying to mix PDO and mysqli functions which isnt going to work and you have no name tag associated with any of your form inputs which php needs to suck out the information from the form fields.

There's plenty wrong with the code you have posted. Have a look at the working code below which uses mysqli. Your database table (itemdatabase) needs to have the columns: floor, room, item, brand, quality set as varchar(100) plus an id column set as INT(11) and should be the primary auto-increment identifier.

Obviously you need to replace YOUR-PASSWORD in the database connection string:

<?php $conn = new mysqli('localhost' , 'root' , 'YOUR-PASWORD' , 'travelodgehotel');

//make sure special characters output correctly

mysqli_query($conn, "SET NAMES 'UTF8'") or die("ERROR: ". mysqli_error($conn));

?>

<?php

if(isset($_POST['submit'])) {

$floor = $conn->real_escape_string($_POST['floor']);

if(empty($floor)) {

$error['floor'] = "Please provide floor information";

}

$room = $conn->real_escape_string($_POST['room']);

if(empty($room)) {

$error['room'] = "Please provide room information";

}

$item = $conn->real_escape_string($_POST['item']);

if(empty($item)) {

$error['item'] = "Please provide item information";

}

$brand = $conn->real_escape_string($_POST['brand']);

if(empty($brand)) {

$error['brand'] = "Please provide brand information";

}

$quality = $conn->real_escape_string($_POST['quality']);

if(empty($quality)) {

$error['quality'] = "Please provide quality information";

}

if(!$error) {

$conn->query("INSERT INTO itemdatabase

(floor,

room,

item,

brand,

quality

)

VALUES

('$floor',

'$room',

'$item',

'$brand',

'$quality')");

echo "<h5>Successfully Inserted</h5>";

}

else {

echo "<ul>";

foreach($error as $error) {

echo "<li>$error</li>";

}

echo "</ul>";

}

}

?>

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

<title>jQuery Mobile: Theme Download</title>

</head>

<body>

<div data-role="page" data-theme="a">

<div data-role="header" data-position="inline">

<h1><img src="themes/images/TravelodgeHotelLogo.png" alt="" style="width:123.5px;height:26.25px;"></h1>

<div data-role="navbar">

<ul>

<li><a href="index.html" data-icon="home" class="ui-btn-active">Home</a></li>

<li><a href="spreadsheet.html" data-icon="grid">Spreadsheet</a></li>

<li><a href="information.html" data-icon="info">Information</a></li>

<li><a href="settings.html" data-icon="gear">Settings</a></li>

</ul>

</div>

</div>

<div data-role="content" data-theme="a">

<form action="index.php" method="post">

<div data-role="fieldcontain">

<select name="floor"  name="floor" id="floor" data-native-menu="false">

<option value="<?php

if(!isset($error['floor'])) {

echo $floor; } ?>" selected><?php if($_POST['floor'] == "") {

echo "Floor"; } else { echo $floor; }?></option>

<option value="Floor 1">Floor 1</option>

<option value="Floor 2">Floor 2</option>

<option value="Floor 3">Floor 3</option>

<option value="Floor 4">Floor 4</option>

<option value="Floor 5">Floor 5</option>

<option value="Floor 6">Floor 6</option>

<option value="Floor 7">Floor 7</option>

<option value="Floor 8">Floor 8</option>

<option value="Floor 9">Floor 9</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="room" name="room" id="room" data-native-menu="false">

<option value="<?php

if(!isset($error['room'])) {

echo $room; } ?>" selected><?php if($_POST['room'] == "") {

echo "Room"; } else { echo $room; }?></option>

<option value="Room 1">Room 1</option>

<option value="Room 2">Room 2</option>

<option value="Room 3">Room 3</option>

<option value="Room 4">Room 4</option>

<option value="Room 5">Room 5</option>

<option value="Room 6">Room 6</option>

<option value="Room 7">Room 7</option>

<option value="Room 8">Room 8</option>

<option value="Room 9">Room 9</option>

<option value="Room 10">Room 10</option>

<option value="Room 11">Room 11</option>

<option value="Room 12">Room 12</option>

<option value="Room 13">Room 13</option>

<option value="Room 14">Room 14</option>

<option value="Room 15">Room 15</option>

<option value="Room 16">Room 16</option>

<option value="Room 17">Room 17</option>

<option value="Room 18">Room 18</option>

<option value="Room 19">Room 19</option>

<option value="Room 20">Room 20</option>

<option value="Room 21">Room 21</option>

<option value="Room 22">Room 22</option>

<option value="Room 23">Room 23</option>

<option value="Room 24">Room 24</option>

<option value="Room 25">Room 25</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="item" name="item" id="item" data-native-menu="false">

<option value="<?php

if(!isset($error['item'])) {

echo $item; } ?>" selected><?php if($_POST['item'] == "") {

echo "Item"; } else { echo $item; }?></option>

<option value="Iron">Iron</option>

<option value="Microwave">Microwave</option>

<option value="Kettle">Kettle</option>

<option value="TV">TV</option>

<option value="Clock Radio">Clock Radio</option>

<option value="Phone">Phone</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="brand" name="brand" id="brand" data-native-menu="false">

<option value="<?php

if(!isset($error['brand'])) {

echo $brand; } ?>" selected><?php if($_POST['brand'] == "") {

echo "Brand"; } else { echo $brand; }?></option>

<option value="Iron KAMBROOK KI785">Iron - KAMBROOK KI785</option>

<option value="Microwave SAMSUNG BLACK">Microwave - SAMSUNG BLACK</option>

<option value="Kettle NERO EXPRESS BLACK">Kettle - NERO EXPRESS BLACK</option>

<option value="TV SAMSUNG 43"">TV - SAMSUNG 43"</option>

<option value="TV PHILIPS 40"">TV - PHILIPS 40"</option>

<option value="Clock Radio PHILIPS">Clock Radio - PHILIPS</option>

<option value="Clock Radio - IHOME">Clock Radio - IHOME</option>

<option value="Phone - BLACK TE">Phone - BLACK TEL</option>

<option value="OTHER">OTHER</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="quality" name="quality" id="quality" data-native-menu="false">

<option value="<?php

if(!isset($error['quality'])) {

echo $quality; } ?>" selected><?php if($_POST['quality'] == "") {

echo "Quality"; } else { echo $quality; }?></option>

<option value="Poor">Poor</option>

<option value="Very Bad">Very Bad</option>

<option value="Bad">Bad</option>

<option value="Average">Average</option>

<option value="Good">Good</option>

<option value="Very Good">Very Good</option>

<option value="Excellent">Excellent</option>

</select>

</div>

<div class="ui-body ui-body-b">

<fieldset class="ui-grid-a">

<div class="ui-block-a"><input type="reset" id="reset" value="Reset" data-theme="d" value="Cancel"></div>

<div class="ui-block-b"><input type="submit" name="submit" id="submit" value="submit" data-theme="a" value="Submit"></div>

    </fieldset>

</div>

</form>

</div>

</div>

</body>

</html>

Views

285

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 03, 2018 0
Adobe Community Professional ,
Oct 03, 2018

Copy link to clipboard

Copied

Hello,

maybe this instruction written in German language (Google translate will be your friend ) will be a first step to solve your task:

Webseiteninhalte nach Excel importieren (Versionen: Excel 2010, 2007, 2003 und 2002/XP)

Sie möchten Webinhalte wie z.B. Hotline Tabellen oder Wirtschaftsdaten einer Stadt in eine Exceltabelle übernehmen, aber das Kopieren über die Zwischenablage bringt nicht das gewünschte Ergebnis? Dann versuchen Sie doch einmal den nachfolgenden Tipp:

Sie können Webseiteninhalte in Excel einbinden. Dafür müssen Sie die "Webabfrage" aus Excel heraus starten:

1.    Öffnen Sie die Webseite, von der Sie Inhalte in Excel einbinden wollen, in Ihrem Browser.

2.    Markieren Sie die komplette Webseitenadresse, die in der Adresszeile des Browsers angezeigt wird, und kopieren Sie sie mit Strg+C in die Zwischenablage.

3.    Starten Sie Excel, falls es nicht schon läuft, und lassen Sie sich die Tabelle anzeigen, in die Sie die Webseiteninhalte einfügen wollen.

4.    Wählen Sie in Excel 2010 und 2007 Daten-Externe Daten abrufen-Aus dem Web an. Oder rufen Sie in Excel 2003 und 2002/XP Daten-Externe Daten importieren-Neue Webabfrage auf.

5.    Im Fenster der Webabfrage entfernen Sie den Inhalt des Felds Adresse und ersetzen ihn durch die zuvor kopierte Webseitenadresse, indem Sie sie per Strg+V aus der Zwischenablage einfügen.

6.    Klicken Sie auf Ok (Excel 2010 und 2007) bzw. Start (Excel 2003 und 2002/XP), um die Webseite zu laden.

7.    Legen Sie fest, welcher Teil der Webseite in Ihre Excel-Tabelle integriert werden soll. Dazu klicken Sie auf das jeweilige Pfeilsymbol neben dem gewünschten Webseitenbereich.

8.    Klicken Sie auf die Schaltfläche Importieren.

9.    Im danach angezeigten Dialogfenster legen Sie fest, wo die Webseiteninhalte eingefügt werden sollen. Zur Bestätigung klicken Sie auf Ok. Excel stellt automatisch eine Verbindung zu der Webseite her und lädt die entsprechenden Daten in das ausgewählte Tabellenblatt.

Hans-Günter

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 03, 2018 1
LEGEND ,
Oct 03, 2018

Copy link to clipboard

Copied

Hello, kahlealp,

I am going to assume that since you pointed out the cancel and submit buttons that you are looking for a way to submit a form and store that form data into an Excel sheet or database (I would strongly advise against Access if this is a public-facing page.)

If this is the case, then you will need a server-side solution like PHP, JSP, ColdFusion, etc.  The server should have a connection to a database (Oracle, MySQL, MS-SQL, etc.), or for Excel it should have Excel support (ColdFusion does, via the Apache SOI.)

While I am no expert on Javascript, there might be a way to do this without the server-side solution, but I am not aware of it.

HTH,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 03, 2018 2
New Here ,
Oct 06, 2018

Copy link to clipboard

Copied

Hi WolfShade I've shifted things around and researched a bit more into alternatives you provided and landed at xampp

the mySQL and Apache is provided with it and I have my database setup as "travelodgehotel" and the table as "itemdatabase" via mySQL via PHPadmin. However my variables are still not being stored, I have placed the php code inside the same html page and renamed the index.html to index.php. It makes a connection to the database and the table but does not store the variables inside the database, im not sure wether its because the tables values are set to VARCHAR but below is the code:

      

<?php

    $hostname="localhost";

    $db="travelodgehotel";

    $Username="root";

    $Password="";

/*    $conn=new PDO("myspl:host=$hostname;dbname=$db", $Username, $Password);

    if(isset($_POST['submit']))

    {

        $floor=$_POST['floor'];

        $sql= $conn -> prepare("Insert Into itemdatabase (floor)

        values (:floor)");

        $conn->beginTransaction();

        $sql-> execute(array(':floor'->$floor));

        echo "<h2>Country Added Succesully .. !</h2>";

        $conn->commit();

    }

        $conn->null;*/

@$floor="";

@$room="";

@$item="";

@$brand="";

@$quality="";

?>

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

<title>jQuery Mobile: Theme Download</title>

<link rel="stylesheet" href="themes/TravelodgeTheme.min.css" />

<link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" />

<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>

<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

</head>

<body>

<div data-role="page" data-theme="a">

<div data-role="header" data-position="inline">

<h1><img src="themes/images/TravelodgeHotelLogo.png" alt="" style="width:123.5px;height:26.25px;"></h1>

<div data-role="navbar">

<ul>

<li><a href="index.html" data-icon="home" class="ui-btn-active">Home</a></li>

<li><a href="spreadsheet.html" data-icon="grid">Spreadsheet</a></li>

<li><a href="information.html" data-icon="info">Information</a></li>

<li><a href="settings.html" data-icon="gear">Settings</a></li>

</ul>

</div>

</div>

<div data-role="content" data-theme="a">

<form action="index.php" method="post">

<div data-role="fieldcontain">

<select name="floor" id="floor" data-native-menu="false">

<option>Floor</option>

<option value="floor1">1</option>

<option value="floor2">2</option>

<option value="floor3">3</option>

<option value="floor4">4</option>

<option value="floor5">5</option>

<option value="floor6">6</option>

<option value="floor7">7</option>

<option value="floor8">8</option>

<option value="floor9">9</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="room" id="room" data-native-menu="false">

<option>Room</option>

<option value="room1">1</option>

<option value="room2">2</option>

<option value="room3">3</option>

<option value="room4">4</option>

<option value="room5">5</option>

<option value="room6">6</option>

<option value="room7">7</option>

<option value="room8">8</option>

<option value="room9">9</option><option value="room10">10</option>

<option value="room11">11</option>

<option value="room12">12</option>

<option value="room13">13</option>

<option value="room14">14</option>

<option value="room15">15</option>

<option value="room16">16</option>

<option value="room17">17</option>

<option value="room18">18</option><option value="room19">19</option><option value="room20">20</option><option value="room21">21</option><option value="room22">22</option><option value="room23">23</option><option value="room24">24</option><option value="room25">25</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="item" id="item" data-native-menu="false">

<option>Item</option>

<option value="iron">Iron</option>

<option value="microwave">Microwave</option>

<option value="kettle">Kettle</option>

<option value="tv">TV</option>

<option value="clockradio">Clock Radio</option>

<option value="phone">Phone</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="brand" id="brand" data-native-menu="false">

<option>Brand</option>

<option value="kambrookki785">Iron – KAMBROOK KI785</option>

<option value="samsungblack">Microwave – SAMSUNG BLACK</option>

<option value="neroexpressblack">Kettle – NERO EXPRESS BLACK</option>

<option value="samsung43">TV – SAMSUNG 43”</option>

<option value="philips40">TV - PHILIPS 40”</option>

<option value="philips">Clock Radio – PHILIPS</option> <option value="ihome">Clock Radio – IHOME</option><option value="blacktel">Phone – BLACK TEL</option>

<option value="other">OTHER</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="quality" id="quality" data-native-menu="false">

<option>Quality</option>

<option value="poor">Poor</option>

<option value="verybad">Very Bad</option>

<option value="bad">Bad</option>

<option value="average">Average</option>

<option value="good">Good</option>

<option value="verygood">Very Good</option> <option value="excellent">Excellent</option>

</select>

</div>

<div class="ui-body ui-body-b">

<fieldset class="ui-grid-a">

<div class="ui-block-a"><button type="reset" id="reset" value="Reset" data-theme="d">Cancel</button></div>

<div class="ui-block-b"><button type="submit" id="submit" value="submit" data-theme="a">Submit</button></div>

    </fieldset>

</div>

</form>

</div>

</div>

</body>

</html>

<?php

if(isset($_POST['submit'])){

//echo '<script type="text/javascript">alert("Insert Clicked")</script>';

@$floor=$_POST['floor'];

@$room=$_POST['room'];

@$item=$_POST['item'];

@$brand=$_POST['brand'];

@$quality=$_POST['quality'];

if($floor=="" || $room=="" || $item=="" || $brand=="" || $quality=="")

{

echo '<script type="text/javascript">alert("Insert values in all fields")</script>';

}

else{

$query = "insert into itemdatabase values($floor,$room,$item,$brand,$quality)";

$query_run=mysqli_query($con,$query);

if($query_run)

{

echo '<script type="text/javascript">alert("Values inserted successfully")</script>';

}

else{

echo '<script type="text/javascript">alert("Values Not inserted")</script>';

}

}

}

?>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 06, 2018 0
LEGEND ,
Oct 07, 2018

Copy link to clipboard

Copied

You're trying to mix PDO and mysqli functions which isnt going to work and you have no name tag associated with any of your form inputs which php needs to suck out the information from the form fields.

There's plenty wrong with the code you have posted. Have a look at the working code below which uses mysqli. Your database table (itemdatabase) needs to have the columns: floor, room, item, brand, quality set as varchar(100) plus an id column set as INT(11) and should be the primary auto-increment identifier.

Obviously you need to replace YOUR-PASSWORD in the database connection string:

<?php $conn = new mysqli('localhost' , 'root' , 'YOUR-PASWORD' , 'travelodgehotel');

//make sure special characters output correctly

mysqli_query($conn, "SET NAMES 'UTF8'") or die("ERROR: ". mysqli_error($conn));

?>

<?php

if(isset($_POST['submit'])) {

$floor = $conn->real_escape_string($_POST['floor']);

if(empty($floor)) {

$error['floor'] = "Please provide floor information";

}

$room = $conn->real_escape_string($_POST['room']);

if(empty($room)) {

$error['room'] = "Please provide room information";

}

$item = $conn->real_escape_string($_POST['item']);

if(empty($item)) {

$error['item'] = "Please provide item information";

}

$brand = $conn->real_escape_string($_POST['brand']);

if(empty($brand)) {

$error['brand'] = "Please provide brand information";

}

$quality = $conn->real_escape_string($_POST['quality']);

if(empty($quality)) {

$error['quality'] = "Please provide quality information";

}

if(!$error) {

$conn->query("INSERT INTO itemdatabase

(floor,

room,

item,

brand,

quality

)

VALUES

('$floor',

'$room',

'$item',

'$brand',

'$quality')");

echo "<h5>Successfully Inserted</h5>";

}

else {

echo "<ul>";

foreach($error as $error) {

echo "<li>$error</li>";

}

echo "</ul>";

}

}

?>

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

<title>jQuery Mobile: Theme Download</title>

</head>

<body>

<div data-role="page" data-theme="a">

<div data-role="header" data-position="inline">

<h1><img src="themes/images/TravelodgeHotelLogo.png" alt="" style="width:123.5px;height:26.25px;"></h1>

<div data-role="navbar">

<ul>

<li><a href="index.html" data-icon="home" class="ui-btn-active">Home</a></li>

<li><a href="spreadsheet.html" data-icon="grid">Spreadsheet</a></li>

<li><a href="information.html" data-icon="info">Information</a></li>

<li><a href="settings.html" data-icon="gear">Settings</a></li>

</ul>

</div>

</div>

<div data-role="content" data-theme="a">

<form action="index.php" method="post">

<div data-role="fieldcontain">

<select name="floor"  name="floor" id="floor" data-native-menu="false">

<option value="<?php

if(!isset($error['floor'])) {

echo $floor; } ?>" selected><?php if($_POST['floor'] == "") {

echo "Floor"; } else { echo $floor; }?></option>

<option value="Floor 1">Floor 1</option>

<option value="Floor 2">Floor 2</option>

<option value="Floor 3">Floor 3</option>

<option value="Floor 4">Floor 4</option>

<option value="Floor 5">Floor 5</option>

<option value="Floor 6">Floor 6</option>

<option value="Floor 7">Floor 7</option>

<option value="Floor 8">Floor 8</option>

<option value="Floor 9">Floor 9</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="room" name="room" id="room" data-native-menu="false">

<option value="<?php

if(!isset($error['room'])) {

echo $room; } ?>" selected><?php if($_POST['room'] == "") {

echo "Room"; } else { echo $room; }?></option>

<option value="Room 1">Room 1</option>

<option value="Room 2">Room 2</option>

<option value="Room 3">Room 3</option>

<option value="Room 4">Room 4</option>

<option value="Room 5">Room 5</option>

<option value="Room 6">Room 6</option>

<option value="Room 7">Room 7</option>

<option value="Room 8">Room 8</option>

<option value="Room 9">Room 9</option>

<option value="Room 10">Room 10</option>

<option value="Room 11">Room 11</option>

<option value="Room 12">Room 12</option>

<option value="Room 13">Room 13</option>

<option value="Room 14">Room 14</option>

<option value="Room 15">Room 15</option>

<option value="Room 16">Room 16</option>

<option value="Room 17">Room 17</option>

<option value="Room 18">Room 18</option>

<option value="Room 19">Room 19</option>

<option value="Room 20">Room 20</option>

<option value="Room 21">Room 21</option>

<option value="Room 22">Room 22</option>

<option value="Room 23">Room 23</option>

<option value="Room 24">Room 24</option>

<option value="Room 25">Room 25</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="item" name="item" id="item" data-native-menu="false">

<option value="<?php

if(!isset($error['item'])) {

echo $item; } ?>" selected><?php if($_POST['item'] == "") {

echo "Item"; } else { echo $item; }?></option>

<option value="Iron">Iron</option>

<option value="Microwave">Microwave</option>

<option value="Kettle">Kettle</option>

<option value="TV">TV</option>

<option value="Clock Radio">Clock Radio</option>

<option value="Phone">Phone</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="brand" name="brand" id="brand" data-native-menu="false">

<option value="<?php

if(!isset($error['brand'])) {

echo $brand; } ?>" selected><?php if($_POST['brand'] == "") {

echo "Brand"; } else { echo $brand; }?></option>

<option value="Iron KAMBROOK KI785">Iron - KAMBROOK KI785</option>

<option value="Microwave SAMSUNG BLACK">Microwave - SAMSUNG BLACK</option>

<option value="Kettle NERO EXPRESS BLACK">Kettle - NERO EXPRESS BLACK</option>

<option value="TV SAMSUNG 43"">TV - SAMSUNG 43"</option>

<option value="TV PHILIPS 40"">TV - PHILIPS 40"</option>

<option value="Clock Radio PHILIPS">Clock Radio - PHILIPS</option>

<option value="Clock Radio - IHOME">Clock Radio - IHOME</option>

<option value="Phone - BLACK TE">Phone - BLACK TEL</option>

<option value="OTHER">OTHER</option>

</select>

</div>

<div data-role="fieldcontain">

<select name="quality" name="quality" id="quality" data-native-menu="false">

<option value="<?php

if(!isset($error['quality'])) {

echo $quality; } ?>" selected><?php if($_POST['quality'] == "") {

echo "Quality"; } else { echo $quality; }?></option>

<option value="Poor">Poor</option>

<option value="Very Bad">Very Bad</option>

<option value="Bad">Bad</option>

<option value="Average">Average</option>

<option value="Good">Good</option>

<option value="Very Good">Very Good</option>

<option value="Excellent">Excellent</option>

</select>

</div>

<div class="ui-body ui-body-b">

<fieldset class="ui-grid-a">

<div class="ui-block-a"><input type="reset" id="reset" value="Reset" data-theme="d" value="Cancel"></div>

<div class="ui-block-b"><input type="submit" name="submit" id="submit" value="submit" data-theme="a" value="Submit"></div>

    </fieldset>

</div>

</form>

</div>

</div>

</body>

</html>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 07, 2018 0