<body onload="myUploadFunction()">
<!-- Primary Page Layout
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<div class="container">
<div class="row">
<div class="one column" style="margin-top: 2%">
<?php
if(isset($_POST['add'])) {
require '*********.php';
if(! get_magic_quotes_gpc() ) {
$PTitle = addslashes ($_POST['PTitle']);
$PContent = addslashes ($_POST['PContent']);
}else {
$PTitle = $_POST['$PTitle'];
$PContent = $_POST['PContent'];
}
$PType = $_POST['PType'];
$PDisplay = $_POST['PDisplay'];
$POrder = $_POST['POrder'];
mysql_select_db('**************');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
}else {
?>
<form method = "post" action = "dor.php">
<fieldset>
<legend>Create A Page</legend>
Title: <input type="text" name="PTitle"> Page Type: <select name="PType">
<option value="home">Home</option>
<option value="event">Event</option>
<option value="vehicle">Vehicle</option>
<option value="testimonial">Testimonial</option>
<option value="special">Special</option>
<option value="about">About</option>
<option value="quote">Quote</option>
</select> Page Order: <input type="text" name="POrder">
<textarea id="PContent">Please enter text and images only. Images will automatically be formatted based on the number of images included.
</textarea>
<br>
<select name="PDisplay">
<option value="False">Hide</option>
<option value="True">Show</option>
</select><input type="submit" id="add" value="Save">
</fieldset>
Upload New Image:
<input type="file" id="myFile" multiple size="50" onchange="myUploadFunction()">
<p id="demo"></p>
<script>
function myUploadFunction(){
var x = document.getElementById("myFile");
var txt = "";
if ('files' in x) {
if (x.files.length == 0) {
txt = "Select one or more files.";
} else {
for (var i = 0; i < x.files.length; i++) {
txt += "<br><strong>" + (i+1) + ". file</strong><br>";
var file = x.files[i];
if ('name' in file) {
txt += "name: " + file.name + "<br>";
}
if ('size' in file) {
txt += "size: " + file.size + " bytes <br>";
}
}
}
}
else {
if (x.value == "") {
txt += "Select one or more files.";
} else {
txt += "The files property is not supported by your browser!";
txt += "<br>The path of the selected file: " + x.value; // If the browser does not support the files property, it will return the path of the selected file instead.
}
}
document.getElementById("demo").innerHTML = txt;
}
</script>
<p><strong>Tip:</strong> Use the Control or the Shift key to select multiple files.</p>
Set Page Image:
Image: <input type="text" name="ImageLink">
</form>
<?php
}
?>
</div>
</div>
</div>
<!-- End Document
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
</body>
</html>
<?php
$mysqli = new mysqli('localhost', '*****', '**********', '********');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
} else {
echo "Have a good night!";
}
error_reporting(E_ALL);
?>
<?php
$conn = new mysqli('localhost', '********', '***********', '*********');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
} else {
echo "Have a good night!";
}
error_reporting(E_ALL);
$query = "SELECT id AS txt FROM `Pages`";
$result = $conn->query($query);
if($result === false) {
trigger_error('Wrong SQL: ' . $query . ' Error: ' . $conn->error, E_USER_ERROR);
} else {
$result->data_seek(0);
while($row = $result->fetch_assoc()){
echo $row['txt'] . '<br>';
}
}
$result->free();
$conn->close();
?>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
mysqli_report(MYSQLI_REPORT_STRICT);
$hostname = 'localhost';
$username = 'username';
$password = 'password';
$database = "dbName";
try {
$db = new mysqli($hostname, $username, $password, $database);
} catch (Exception $e ) {
echo "DB Error: " . $e->getMessage();
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Chris Stanyon</title>
</head>
<body>
<h1>Connected</h1>
</body>
</html>
Try this code and don't move on to the next step until you know this is working. If it fails, you'll get an error. If it works, you'll see 'Connected'
Failed to connect to MySQL: (1045) Access denied for user 'nnn'@'localhost' (using password: YES)If you're using a shared hosting service, the service probably has a customer support organization. They have been through this part of the issue before, and probably have canned instructions to help you get over this particular hump. Databases have users, and users have username, password, permissions. All of these have to line up correctly before you can run a query. MySQL and MySQLi are notoriously bad about their error messages, giving ambiguous and confusing responses, so don't feel bad if this is not working yet -- we all go through this stuff at some point. I would ask the hosting company for help, then come back once you're able to connect and run a basic query like SELECT 2+2.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Basic Page Needs
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta charset="utf-8">
<title>Your page title here :)</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Mobile Specific Metas
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- FONT
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<script src='//cdn.tinymce.com/4/tinymce.min.js'></script>
<script>
tinymce.init({
selector: '#PContent',
theme: 'modern',
width: 600,
height: 300,
plugins: [
'advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker',
'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking',
'save table contextmenu directionality emoticons template paste textcolor'
],
content_css: 'css/content.css',
toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons'
});
</script>
<!-- Favicon
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="icon" type="image/png" href="images/favicon.png">
</head>
<body onload="myUploadFunction()">
<!-- Primary Page Layout
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<div class="container">
<div class="row">
<div class="one column" style="margin-top: 2%">
<?php
// STEP 1. Get the connection
require 'dor.php';
// STEP 0. Are we getting form submission or should we show the form's field for filling?
if(isset($_POST['add'])) {
// STEP 2. Validate user's input
// $PType = $_POST['PType'];
// $PDisplay = $_POST['PDisplay'];
// $POrder = $_POST['POrder'];
// STEP 3. Properly encode user input for SQL
// STEP 4. Construct the SQL query
$sql = $mysqli->prepare("INSERT INTO Pages(ID,PTitle,
PType,PContent,PDisplay,POrder) VALUES (?, ?, ?, ?, ?, ?)");
$sql->bind_param('sssdi', $_POST['ID'],
$_POST['PTitle'],
$_POST['PType'],
$_POST['PContent'],
$_POST['PDisplay']);
$_POST['POrder']);
$sql->execute();
$newId = $stmt->insert_id;
$sql->close();
//$retval = mysql_query( $sql, $mysqli ); // procedural version
$retval = $mysqli->query($sql);
// STEP 5. Execute the SQL query
if(! $retval ) {
// STEP 5.1 Deal with insuccess
die('Could not enter data: ' . $mysqli->error);
}
// STEP 5.2 Deal with success
echo "Entered data successfully\n";
// STEP 6. We're done, close the connection
//mysqli_close($mysqli);
$mysqli->close();
}
// user is editing stuff:
elseif(isset($_POST['edit']))
{
$sql = $mysqli->prepare("Update Pages(ID,PTitle,
PType,PContent,PDisplay,POrder) VALUES (?, ?, ?, ?, ?, ?)");
$sql->bind_param('sssdi', $_POST['ID'],
$_POST['PTitle'],
$_POST['PType'],
$_POST['PContent'],
$_POST['PDisplay']);
$_POST['POrder']);
$sql->execute();
$newId = $stmt->update_id;
$sql->close();
//$retval = mysql_query( $sql, $mysqli ); // procedural version
$retval = $mysqli->query($sql);
// STEP 5. Execute the SQL query
if(! $retval ) {
// STEP 5.1 Deal with insuccess
die('Could not enter data: ' . $mysqli->error);
}
// STEP 5.2 Deal with success
echo "Entered data successfully\n";
// STEP 6. We're done, close the connection
//mysqli_close($mysqli);
$mysqli->close();
$display_button_valu = "delete";
$display_button_name = "delete";
// 4: set a confirmation message:
$msg = "Your stuff has been EDITED";
}
// user is deleting stuff:
elseif(isset($_POST['delete']))
{
$sql = "DELETE FROM Pages WHERE id=$_POST['ID']";
$display_button_valu = "add";
$display_button_name = "add";
// 4: set a confirmation message:
$msg = "Your stuff has been DELETED";
}
// user is doing nothing, it's his/her first time (ooer)
else
{
// 1: set variable that displays "add" button:
// STEP 2. Validate user's input
// $PType = $_POST['PType'];
// $PDisplay = $_POST['PDisplay'];
// $POrder = $_POST['POrder'];
//
// STEP 3. Properly encode user input for SQL
// STEP 4. Construct the SQL query
//$sql = $mysqli->prepare("INSERT INTO Pages(ID,PTitle,
PType,PContent,PDisplay,POrder) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->bind_param('sssdi', $_POST['ID'],
$_POST['PTitle'],
$_POST['PType'],
$_POST['PContent'],
$_POST['PDisplay']);
$_POST['POrder']);
$stmt->execute();
$newId = $stmt->insert_id;
$stmt->close();
//$retval = mysql_query( $sql, $mysqli ); // procedural version
$retval = $mysqli->query($sql);
// STEP 5. Execute the SQL query
if(! $retval ) {
// STEP 5.1 Deal with insuccess
die('Could not enter data: ' . $mysqli->error);
}
// STEP 5.2 Deal with success
echo "Entered data successfully\n";
// STEP 6. We're done, close the connection
//mysqli_close($mysqli);
$mysqli->close();
//$display_button_valu = "add";//
//$display_button_name = "add";//
// 2: set a welcome message:
$msg = "Welcome. Please add some stuff in the form below";
}
?>
<!-- display your message here -->
<p><?=$msg?></p>
//<form method = "post" action = "adm.php">
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<!-- create your form here -->
<fieldset>
<legend>Create A Page</legend>
Title: <input type="text" name="PTitle">
Page Type: <select name="PType">
<option value="Home">Home</option>
<option value="Event">Event</option>
<option value="Vehicle">Vehicle</option>
<option value="Testimonial">Testimonial</option>
<option value="Special">Special</option>
<option value="About">About</option>
<option value="Quote">Quote</option>
</select> Page Order: <input type="text" name="POrder">
<textarea id="PContent">Please enter text and images only. Images will automatically be formatted based on the number of images included.
</textarea>
<br>
<select name="PDisplay">
<option value="False">Hide</option>
<option value="True">Show</option>
</select><input type="submit" id="add" value="Save">
</fieldset>
Upload New Image:
<input type="file" id="myFile" multiple size="50" onchange="myUploadFunction()">
<p id="demo"></p>
<script>
function myUploadFunction(){
var x = document.getElementById("myFile");
var txt = "";
if ('files' in x) {
if (x.files.length == 0) {
txt = "Select one or more files.";
} else {
for (var i = 0; i < x.files.length; i++) {
txt += "<br><strong>" + (i+1) + ". file</strong><br>";
var file = x.files[i];
if ('name' in file) {
txt += "name: " + file.name + "<br>";
}
if ('size' in file) {
txt += "size: " + file.size + " bytes <br>";
}
}
}
}
else {
if (x.value == "") {
txt += "Select one or more files.";
} else {
txt += "The files property is not supported by your browser!";
txt += "<br>The path of the selected file: " + x.value; // If the browser does not support the files property, it will return the path of the selected file instead.
}
}
document.getElementById("demo").innerHTML = txt;
}
</script>
<p><strong>Tip:</strong> Use the Control or the Shift key to select multiple files.</p>
Set Page Image:
Image: <input type="text" name="ImageLink">
<!-- display your button here -->
<input type="submit" name="<?=$display_button_name?>" value="<?=$display_button_valu?>" />
</form>
?>
</div>
</div>
</div>
<!-- End Document
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Basic Page Needs
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta charset="utf-8">
<title>Your page title here :)</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Mobile Specific Metas
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- FONT
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<script src='//cdn.tinymce.com/4/tinymce.min.js'></script>
<script>
tinymce.init({
selector: '#PContent',
theme: 'modern',
height: 300,
plugins: [
'advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker',
'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking',
'save table contextmenu directionality emoticons template paste textcolor'
],
content_css: 'css/content.css',
toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons'
});
</script>
<!-- Favicon
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="icon" type="image/png" href="images/favicon.png">
</head>
<body onload="myUploadFunction()">
<!-- Primary Page Layout
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<div class="container">
<div class="row">
<div class="one-half column" style="margin-top: 2%">
<?php
// STEP 0. Are we getting form submission or should we show the form's field for filling?
if(isset($_POST['add'])) {
// STEP 1. Get the connection
require 'dor.php';
// STEP 2. Validate user's input
$PTitle = $_POST['PTitle'];
$PType = $_POST['PType'];
$POrder = $_POST['POrder'];
$PContent = $_POST['PContent'];
$PDisplay = $_POST['PDisplay'];
// STEP 3. Properly encode user input for SQL
// STEP 4. Construct the SQL query
$sql = "INSERT INTO Pages ( PTitle, PType, POrder, PContent, PDisplay)
VALUES ('".$_POST["PTitle"]."','".$_POST["PType"]."','".$_POST["POrder"]."','".$_POST["PContent"]."','".$_POST["PDisplay"]."')";
//$retval = mysql_query( $sql, $mysqli ); // procedural version
$retval = $mysqli->query($sql);
// STEP 5. Execute the SQL query
if(! $retval ) {
// STEP 5.1 Deal with insuccess
die('Could not enter data: ' . $mysqli->error);
}
// STEP 5.2 Deal with success
echo "Entered data successfully\n";
// STEP 6. We're done, close the connection
//mysqli_close($mysqli);
$mysqli->close();
}else {
?>
<form method = "post" action = "adm.php">
<fieldset>
<legend>Create A Page</legend>
Title: <input type="text" name="PTitle">
Page Type: <select name="PType">
<option value="Home">Home</option>
<option value="Event">Event</option>
<option value="Vehicle">Vehicle</option>
<option value="Testimonial">Testimonial</option>
<option value="Special">Special</option>
<option value="About">About</option>
<option value="Quote">Quote</option>
</select> Page Order: <input type="text" name="POrder">
<textarea id="PContent">Please enter text and images only. Images will automatically be formatted based on the number of images included.
</textarea>
<br>
<select name="PDisplay">
<option value="False">Hide</option>
<option value="True">Show</option>
</select><input type="submit" name="add" id="add" value="Save">
</fieldset>
Upload New Image:
<input type="file" id="myFile" multiple size="50" onchange="myUploadFunction()">
<p id="demo"></p>
<script>
function myUploadFunction(){
var x = document.getElementById("myFile");
var txt = "";
if ('files' in x) {
if (x.files.length == 0) {
txt = "Select one or more files.";
} else {
for (var i = 0; i < x.files.length; i++) {
txt += "<br><strong>" + (i+1) + ". file</strong><br>";
var file = x.files[i];
if ('name' in file) {
txt += "name: " + file.name + "<br>";
}
if ('size' in file) {
txt += "size: " + file.size + " bytes <br>";
}
}
}
}
else {
if (x.value == "") {
txt += "Select one or more files.";
} else {
txt += "The files property is not supported by your browser!";
txt += "<br>The path of the selected file: " + x.value; // If the browser does not support the files property, it will return the path of the selected file instead.
}
}
document.getElementById("demo").innerHTML = txt;
}
</script>
<p><strong>Tip:</strong> Use the Control or the Shift key to select multiple files.</p>
Set Page Image:
Image: <input type="text" name="ImageLink">
</form></div>
<div class="one-half column" style="margin-top: 2%">test
<?php
$sqli = "SELECT ID, PTitle, PType FROM Pages";
$resulti = $mysqli->query($sqli);
if ($resulti->num_rows > 0) {
// output data of each row
while($row = $resulti->fetch_assoc()) {
echo "id: " . $row["ID"]. " - Name: " . $row["PTitle"]. " " . $row["PType"]. "<br>";
}
} else {
echo "0 results";
}
?>
</div>
<?php
}
?>
</div>
</div>
<!-- End Document
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
</body>
</html>
Presumably require php gas the global $conn set to the connection.
See if you move the require directive above the check for form add.
The posted data does not seem to have an early exit but include a close connection directive.
When executing you are not checking their status which could help when outputting errors when encountered, I.e. On the mysql_select_db an error that a connection is not present ..... Etc.