I am new to php and sqlite and wanted to make a form that inserts everything there into the database.
This is my contact.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>G6 Mall | Contact</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
<script type="text/javascript" src="js/jquery-1.5.2.js" ></script>
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/cufon-replace.js"></script>
<script type="text/javascript" src="js/Terminal_Dosis_300.font.js"></script>
<script type="text/javascript" src="js/atooltip.jquery.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<!--[if lt IE 9]>
<script type="text/javascript" src="js/html5.js"></script>
<style type="text/css">.bg {behavior:url("js/PIE.htc")}</style>
<![endif]-->
</head>
<body id="page6">
<div class="body1">
<div class="body2">
<div class="body3">
<div class="main">
<!-- header -->
<header>
<div class="wrapper">
<h1></h1>
<form id="search" action="#" method="post">
<div>
<input type="submit" class="submit" value="">
<input class="input" type="text" value="Site Search" onBlur="if(this.value=='') this.value='Site Search'" onFocus="if(this.value =='Site Search' ) this.value=''">
</div>
</form>
<nav>
<ul id="menu">
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Directory</li>
<li>News</li>
<li id="active" class="end">Contact</li>
</ul>
</nav>
</div>
</header>
<!-- / header-->
<!-- content -->
<section id="content">
<div class="wrapper">
<h2>General Enquiry Form</h2>
<form id="FeedbackForm" action="post.php" method="post">
<div>
<div class="wrapper"> <span>Name:</span>
<input type="text" class="input" name="NAME">
</div>
<div class="wrapper"> <span>Contact:</span>
<input type="text" class="input" name="CONTACT">
</div>
<div class="wrapper"> <span>E-mail:</span>
<input type="text" class="input" name="EMAIL">
</div>
<div class="textarea_box"> <span>Message: (50char)</span>
<textarea name="COMMENT" cols="1" rows="1"></textarea>
</div>
<input type="submit" name="update" value="update">
<!--<span> </span> Clear Send </div>-->
</form>
</div>
</section>
</div>
</div>
</div>
</div>
<div class="body4">
<div class="main">
<section id="content2">
<div class="wrapper">
<div style="text-align: center;">
<h2>Where are we located at? </h2>
<strong>Lot-6 G6 Street, Wollongong, 6666 NSW</strong>
<p><!--spacing between the headers-->
</div>
<div class="line3 wrapper">
<article class="col2">
<h2>G6 Card privileges+ </h2>
<div class="pad"> <span class="col3"> <strong>
Telephone:<br>
Email: </strong> </span>
+614 1234 6666<br>
g6card#g6.com </div>
</article>
<article class="col2">
<h2>Customer Service Centre </h2>
<div class="pad"> <span class="col3"> <strong>
Telephone:<br>
Email: </strong> </span>
+614 1234 5555<br>
custserv#g6.com </div>
</article>
<article class="col2">
<h2>Advertisement & Promotion</h2>
<div class="pad"> <span class="col3"> <strong>
Telephone:<br>
Fax No:<br>
Email: </strong> </span>
+614 1234 7777<br>
+614 1234 1212<br>
adsPromo#g6.com </div>
</article>
<article class="col2">
<h2>Leasing</h2>
<div class="pad"> <span class="col3"> <strong>
Telephone:<br>
Fax No:<br>
Email: </strong> </span>
+614 7728 8878<br>
+614 7726 8869<br>
leasing#g6.com </div>
</article></div>
</div>
</section>
</div>
</div>
<!-- / content -->
<div class="main">
<!-- footer -->
<footer>
<div class="wrapper"> <span class="left"> Copyright © G6. All Rights Reserved<br>
Design by LM-02</a><br>
</span>
<ul id="icons">
Connect with us: <br>
<li><img src="images/icon1.png" alt=""></li>
<li><img src="images/icon4.png" alt=""></li>
</ul>
</div>
<!-- {%FOOTER_LINK} -->
</footer>
<!-- / footer -->
</div>
</body>
</html>
Then i made a post.php and put this code down
<?php
$NAME = sqlite_escape_string($_POST['NAME']);
$CONTACT = sqlite_escape_string($_POST['CONTACT']);
$EMAIL = sqlite_escape_string($_POST['EMAIL']);
$COMMENT = sqlite_escape_string($_POST['COMMENT']);
class MyDB extends SQLite3
{
function __construct()
{
$this->open('final_mall_management_system.db');
}
}
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
} else {
echo "Opened database successfully\n";
}
$sql =<<<EOF
INSERT INTO Enquiry (Name,Contact,Email,Comment)
VALUES ( '$NAME', '$CONTACT', '$EMAIL', '$COMMENT' );
EOF;
$ret = $db->exec($sql);
if(!$ret){
echo $db->lastErrorMsg();
} else {
echo "Records created successfully\n";
}
$db->close();
?>
When I entered the data in the form and click the submit it doesn't work I get this instead
open('final_mall_management_system.db'); } } $db = new MyDB(); if(!$db){ echo $db->lastErrorMsg(); } else { echo "Opened database successfully\n"; } $sql =<<exec($sql); if(!$ret){ echo $db->lastErrorMsg(); } else { echo "Records created successfully\n"; } $db->close(); ?>
I have no idea what I'm doing wrong. Could anyone please help me?
<section id="content">
<div class="wrapper">
<h2>General Enquiry Form</h2>
<form id="FeedbackForm" action="post.php" method="post">
<div>
<div class="wrapper"> <span>Name:</span>
<input type="text" class="input" name="NAME">
</div>
<div class="wrapper"> <span>Contact:</span>
<input type="text" class="input" name="CONTACT">
</div>
<div class="wrapper"> <span>E-mail:</span>
<input type="text" class="input" name="EMAIL">
</div>
<div class="textarea_box"> <span>Message: (50char)</span>
<textarea name="COMMENT" cols="1" rows="1"></textarea>
</div>
<input type="submit" name="update" value="update">
<!--<span> </span> Clear Send </div>-->
</form>
</div>
</section>
Is the main section of the "form" html code from the whole code (content.html) that i showed above.
Change remove EOF thing and use double quotes for your sql, I think that's the problem.
$sql ="INSERT INTO Enquiry (Name,Contact,Email,Comment)
VALUES ( '$NAME', '$CONTACT', '$EMAIL', '$COMMENT' )";
most likely you redefined constructor to SQLite3 class itself.
http://www.php.net/manual/en/language.oop5.decon.php
try changing
function __construct() {
$this->open('final_mall_management_system.db');
}
to
function __construct() {
parent::__construct();
$this->open('final_mall_management_system.db');
}
Related
I just uploaded a website on live before that I test on PHP local host and it's perfectly fine no errors at all. But when I upload it live the insert statements are not working. But other SQL is perfectly fine like retrieve select statements all others are perfectly fine. I'm already connected to the database.
<?php
session_start();
error_reporting(0);
include('includes/dbconnection.php');
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$email=$_POST['email'];
$services=$_POST['services'];
$adate=$_POST['adate'];
$atime=$_POST['atime'];
$phone=$_POST['phone'];
$aptnumber = mt_rand(100000000, 999999999);
$sqlinsert = "INSERT INTO `tblappointment` (`AptNumber`, `Name`, `Email`, `PhoneNumber`, `AptDate`, `AptTime` ,`Services`) VALUES ('$aptnumber','$name','$email','$phone','$adate','$atime','$services')";
if (!mysqli_query($con, $sqlinsert)) {
die('error inserting new record');
}
$newrecord = "1 new record added to the database";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>teethenjoy Dental Clinic Official Website</title>
<link href="https://fonts.googleapis.com/css?family=Work+Sans:100,200,300,400,500,600,700,800,900" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Playfair+Display:400,400i,700,700i,900,900i" rel="stylesheet">
<link rel="stylesheet" href="css/open-iconic-bootstrap.min.css">
<link rel="stylesheet" href="css/animate.css">
<link rel="stylesheet" href="css/owl.carousel.min.css">
<link rel="stylesheet" href="css/owl.theme.default.min.css">
<link rel="stylesheet" href="css/magnific-popup.css">
<link rel="stylesheet" href="css/aos.css">
<link rel="stylesheet" href="css/ionicons.min.css">
<link rel="stylesheet" href="css/bootstrap-datepicker.css">
<link rel="stylesheet" href="css/jquery.timepicker.css">
<link rel="stylesheet" href="css/flaticon.css">
<link rel="stylesheet" href="css/icomoon.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php include_once('includes/header.php');?>
<!-- END nav -->
<section id="home-section" class="hero" style="background-image: url(images/8.jpg);" data-stellar-background-ratio="0.5">
<div class="home-slider owl-carousel">
<div class="slider-item js-fullheight">
<div class="overlay"></div>
<div class="container-fluid p-0">
<div class="row d-md-flex no-gutters slider-text align-items-end justify-content-end" data-scrollax-parent="true">
<!--<img class="one-third align-self-end order-md-last img-fluid" src="images/1.png" alt=""> -->
<div class="one-forth d-flex align-items-center ftco-animate" data-scrollax=" properties: { translateY: '70%' }">
<div class="text mt-5">
<span class="subheading">teethenjoy Dental Clinic</span>
<h1 class="mb-4">Get Pretty Smile</h1>
<h2 class="mb-4">A SMILE is the PRETTIEST THING YOU'LL ever wear</h2>
</div>
</div>
</div>
</div>
</div>
<div class="slider-item js-fullheight">
<div class="overlay"></div>
<div class="container-fluid p-0">
<div class="row d-flex no-gutters slider-text align-items-center justify-content-end" data-scrollax-parent="true">
<!-- <img class="one-third align-self-end order-md-last img-fluid" src="images/2.png" alt=""> -->
<div class="one-forth d-flex align-items-center ftco-animate" data-scrollax=" properties: { translateY: '70%' }">
<div class="text mt-5">
<span class="subheading">teethenjoy Dental Clinic</span>
<h1 class="mb-4">Get a Confidence </h1>
<h2 class="mb-4">A warm smile is the universal language of kindness</h2>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<br>
<section class="ftco-section ftco-no-pt ftco-booking">
<div class="container-fluid px-0">
<div class="row no-gutters d-md-flex justify-content-end">
<div class="one-forth d-flex align-items-end">
<div class="text">
<div class="overlay"></div>
<div class="appointment-wrap">
<span class="subheading">Reservation</span>
<h3 class="mb-2">Make an Appointment</h3>
<form action="#" method="post" class="appointment-form">
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<input type="text" class="form-control" id="name" placeholder="Name" name="name" required="true">
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<input type="email" class="form-control" id="appointment_email" placeholder="Email" name="email" required="true">
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<div class="select-wrap">
<div class="icon"><span class="ion-ios-arrow-down"></span></div>
<select name="services" id="services" required="true" class="form-control">
<option value="">Select Services</option>
<?php $query=mysqli_query($con,"select * from tblservices");
while($row=mysqli_fetch_array($query))
{
?>
<option value="<?php echo $row['ServiceName'];?>"><?php echo $row['ServiceName'];?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<input type="text" class="form-control appointment_date" placeholder="Date" name="adate" id='adate' required="true">
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<input type="text" class="form-control appointment_time" placeholder="Time" name="atime" id='atime' required="true">
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<input type="text" class="form-control" id="phone" name="phone" placeholder="Phone" required="true" maxlength="10" pattern="[0-9]+">
</div>
</div>
</div>
<div class="form-group">
<input type="submit" name="submit" value="Book an Appointment" class="btn btn-primary">
</div>
</form>
</div>
</div>
</div>
<div class="one-third">
<div class="img" style="background-image: url(images/9.jpg);">
</div>
</div>
</div>
</div>
</section>
<br>
<?php include_once('includes/footer.php');?>
<!-- loader -->
<div id="ftco-loader" class="show fullscreen"><svg class="circular" width="48px" height="48px"><circle class="path-bg" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke="#eeeeee"/><circle class="path" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke-miterlimit="10" stroke="#F96D00"/></svg></div>
<script src="js/jquery.min.js"></script>
<script src="js/jquery-migrate-3.0.1.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src="js/jquery.waypoints.min.js"></script>
<script src="js/jquery.stellar.min.js"></script>
<script src="js/owl.carousel.min.js"></script>
<script src="js/jquery.magnific-popup.min.js"></script>
<script src="js/aos.js"></script>
<script src="js/jquery.animateNumber.min.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script src="js/jquery.timepicker.min.js"></script>
<script src="js/scrollax.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBVWaKrjvy3MaE7SQ74_uJiULgl1JY0H2s&sensor=false"></script>
<script src="js/google-map.js"></script>
<script src="js/main.js"></script>
</body>
</html>
I'm fairly new and was wondering if anyone could help. I've just uploaded all website files via filezilla to a web hosting company and the contact form isn't working. I've tried looking into this but I can seem to find out why. Are you able to have a look at my code and see if I'm perhaps missing something.
The Contact Form
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="description" content="Contact Protekt Insurance Brokers. For more information and questions you have">
<meta name="keywords" content="insurance companies, cheap car insurance, insurance brokers, insurance, personal insurance, business insurance, home insurance, life insurance, insurance agency, car insurance, insurance quotes, cheap insurance, liability insurance">
<meta name="author" content="Vaughan Testa">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css" integrity="sha256-h20CPZ0QyXlBuAw7A+KluUYx/3pK+c7lYEpqLTlxjYQ=" crossorigin="anonymous" />
<link rel="stylesheet" href="css/utilities.css" />
<link rel="stylesheet" href="css/style.css" />
<title>Contact Protekt | Protekt Insurance Brokers</title>
</head>
<body id="home">
<header class="hero blog">
<div id="navbar" class="navbar top">
<h1 class="logo">
<span class="text-primary">Protekt </span>Insurance Brokers</h1>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Documentation</li>
<li>Contact</li>
</ul>
</nav>
</div>
<div class="content">
<h1 class="text-primary">Contact Us By Email</h1>
</div>
</header>
<main>
<section id="contact" class="contact flex-columns">
<div class="row">
<div class="column">
<div class="column-1">
<img src="images/blogger-336371_1920.jpg" alt="" />
</div>
</div>
<div class="column">
<div class="column-2 bg-light">
<h2>Contact Us By Email</h2>
<form action="process.php" method="POST" id="contact_form" class="callback-form">
<div class="form-control">
<label for="name"></label>
<input type="text" name="name" id="name" placeholder="Enter name" />
</div>
<div class="form-control">
<label for="email"></label>
<input type="email" name="email" id="email" placeholder="Enter email" />
</div>
<div class="form-control">
<label for="phone"></label>
<input type="text" name="phone" id="phone" placeholder="Enter phone" />
</div>
<input type="submit" value="Send" id="submit" class="btn" />
</form>
</div>
</div>
</div>
</section>
<section id="about" class="icons bg-primary">
<h2 class="about-h2">Contact Details</h2>
<div class="flex-items">
<div class="flex-item1">
<i class="fas fa-phone fa-2x"></i>
<div>
<h3>Contact Info</h3>
<p>
Telephone: (09) 475 6602 <br>International Callers: +649 475 6602
</p>
</div>
</div>
<div class="flex-item2">
<i class=" fas fa-envelope fa-2x "></i>
<div>
<h3>Email Info</h3>
<p>
E-mail: enquiry#protekt.co.nz
</p>
</div>
</div>
<div class="flex-item3">
<i class="fas fa-address-card fa-2x"></i>
<div>
<h3>Office Location</h3>
<p>
103 Glenvar Road, <br>Torbay, Auckland 0630 <br>New Zealand <br><br>Postal Address<br>PO Box 35962 <br>Browns Bay <br>Auckland 0753 <br>New Zealand
</p>
</div>
</div>
</div>
</section>
<section id="boxes">
<div class="container-boxes">
<div class="box">
<img src="images/steadfast.gif" alt="">
</div>
<div class="box">
<img src="images/ANZ.gif" alt="">
</div>
<div class="box">
<img src="images/IBANZ.gif" alt="">
</div>
</div>
</section>
</main>
<footer class="footer bg-dark">
<div class="social">
<i class="fab fa-facebook fa-2x"></i>
<i class="fab fa-twitter fa-2x"></i>
<i class="fab fa-linkedin fa-2x"></i>
</div>
<p>Copyright © 2020 - Designed By: Vaughan Testa</p>
</footer>
<script>
const navbar = document.getElementById('navbar');
let scrolled = false;
window.onscroll = function() {
if (window.pageYOffset > 100) {
navbar.classList.remove('top');
if (!scrolled) {
navbar.style.transform = 'translateY(-70px)';
}
setTimeout(function() {
navbar.style.transform = 'translateY(0)';
scrolled = true;
}, 200);
} else {
navbar.classList.add('top');
scrolled = false;
}
};
</script>
</body>
</html>
My PHP Code
<?php
if(!$_POST) exit;
$email = $_POST['email'];
error_reporting(error_reporting() & ~E_DEPRECATED);
//$error[] = preg_match('/\b[A-Z0-9._%-]+#[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."#"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ('name','email','message');
$required = array('name','email','message');
$your_email = "enquiry#protekt.co.nz";
$email_subject = "New Message: ".$_POST['subject'];
$email_content = "new message:\n";
foreach($values as $key => $value){
if(in_array($value,$required)){
if ($key != 'subject' && $key != 'company') {
if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
}
$email_content .= $value.': '.$_POST[$value]."\n";
}
}
if(#mail($your_email,$email_subject,$email_content)) {
echo 'Message sent!';
} else {
echo 'ERROR!';
}
}
?>
I am getting an HTTP Error 500 on my website. The PHP code checker doesn't see anything suspicious.
I think it's caused by PDO but I'm not sure because when I remove all the PHP code it still gives me the same error.
Here's my code:
Index.php:
<?php
include_once('includes/db_connect.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable="no>
<!-- Custom CSS -->
<link rel="stylesheet" href="css/custom.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css" />
<!-- Optional theme (flatly) -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootswatch/latest/flatly/bootstrap.min.css" />
<!-- Font awesome -->
<link href="//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css" rel="stylesheet" />
<link rel="stylesheet" href="css/contact.css" rel="stylesheet">
<!-- jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="js/contact.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="//netdna.bootstrapcdn.com/bootstrap/latest/js/bootstrap.min.js"></script>
<title><?php
foreach($dbh->query('SELECT * FROM page_info') as $row) {
echo $row['title'];
}
?></title>
</head>
<body>
<div class="banner">
<div class="name"><?php
foreach ($dbh->query('SELECT * FROM page_info') as $row) {
echo $row[“name”];
}
?></div>
</div>
<div class="about">
<div class="about-container">
<div class="about-main-text">
<h1>About me:</h1>
<?php
foreach ($dbh->query('SELECT * FROM about') as $row) {
echo '
<span>'.$row["text"].'</span>
';
}
?>
</div>
</div>
</div>
<div class="projects">
<div class="projects-container">
<div class="projects-main-text">
<h1>My projects:</h1>
</div>
<div class="row">
<?php
foreach($dbh->query('SELECT * FROM projects') as $row) {
echo '
<div class="col-md-4 nopadding">
<div class="project-box">
<img src="data:image/jpeg;base64,'.base64_encode( $row['image'] ).'" alt="Project Image">
<h1>'.$row["name"].'</h1>
<p>'.$row["desc"].'</p>
</div>
</div>
';
}
?>
</div>
</div>
</div>
<div class="contact">
<div class="contact-container">
<div class="contact-main-text">
<h1>Contact me:</h1>
</div>
<div class="row">
<form action="contact/send.php" method="post" style="float: left;">
<div class="field name-box">
<input type="text" id="name" name="name" placeholder="Who Are You?"/>
<label for="name">Name</label>
<span class="ss-icon">check</span>
</div>
<div class="field email-box">
<input type="text" id="email" name="email" placeholder="name#email.com"/>
<label for="email">Email</label>
<span class="ss-icon">check</span>
</div>
<div class="field msg-box">
<textarea id="msg" rows="4" placeholder="Your message goes here..."/></textarea>
<label for="msg">Msg</label>
<span class="ss-icon">check</span>
</div>
<input class="button" type="submit" value="Send" />
</form>
</div>
</div>
</div>
<div class="footer">
<span class="copyright">
© <?php
foreach ($dbh->query('SELECT * FROM page_info') as $row) {
echo $row['copyright'];
}
echo ' ' . date("Y");
?> - All rights reserved
</span>
</div>
</body>
</html>
And here is db_connect.php:
<?php
$uname = ‘rik_root’;
$upass = ‘*********’;
$dbh = new PDO('mysql:host=localhost;dbname=nijdeken’, $uname, $upass);
?>
I hope someone can help me. Thanks in advance!
Don't use a word processor to edit your code:
$uname = ‘rik_root’;
^--------^
those are not valid php quote characters, and are probably killing your code with a fatal parse error:
$dbh = new PDO('mysql:host=localhost;dbname=nijdeken’, $uname, $upass);
^--start of string ^--NOT an end-of-string
I am having trouble connecting a database i have created in phpMyAdmin to my web page using PHP. I am pretty sure my code is correct in both the html and php files and my DB and table names are correct, but when i try to use the registration form, it does nothing. I am using jQuery mobile, so have tried it with and without the data-ajax="false" attribute to no avail. What am i missing here? Thanks for any answers :) I have included the relevant html and php code below, it is the register form in the register page I am trying to connect to the DB.
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1; minimum-scale=1;">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<link href="/projects/ibill_v3/css/mainstyles.css" rel="StyleSheet"/>
<link href="/projects/ibill_v3/css/register.css" rel="StyleSheet"/>
<link href="/projects/ibill_v3/css/login.css" rel="StyleSheet"/>
<link href="/projects/ibill_v3/css/home.css" rel="StyleSheet"/>
<link href="/projects/ibill_v3/css/record_session.css" rel="StyleSheet"/>
<link href="/projects/ibill_v3/css/viewsessions.css" rel="StyleSheet"/>
<link href="/projects/ibill_v3/css/email.css" rel="StyleSheet"/>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script src="script.js"></script>
<script type='text/javascript' src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script type='text/javascript'>
$(document).on('pageinit', function(){
$('#registerForm').validate({ // initialize the plugin
// rules & options
});
});
</script>
<script type='text/javascript'>
$(document).on('pageinit', function(){
$('.loginform').validate({ // initialize the plugin
// rules & options
});
});
</script>
</head>
<body>
<!--********************************REGISTER PAGE**********************************************-->
<!--****************************************************************************************-->
<!--********************************HEADER**********************************************-->
<div data-role="page" id="register">
<div data-role="header" data-id="foo1" data-position="fixed">
<div class='cssmenu'>
<ul>
<li class='active'><a href='#home'>Home</a></li>
<li><a href='#sessionrecord'>Record a Session</a></li>
<li><a href='#viewsessions'>View Sessions</a></li>
<li><a href='#email'>E-mail an Invoice</a></li>
</ul>
</div>
</div>
<!--********************************HEADER**********************************************-->
<!--********************************MAIN**********************************************-->
<div data-role="main" class="ui-content">
<img class="mainlogo" src="/projects/ibill_v3/img/ibill logo.png" alt="iBill Logo" width="250" height="190">
<section class="registerform">
<h1>The iBill Invoicing App for Activity Instructors</h1>
<p>Register below</p>
<form data-ajax="false" method="POST" action="register.php" >
<ul>
<li>
<label for="username">Username</label>
<input type="text" name="username" id="username" class="required" minlength="5" placeholder="enter username (min-5 characters)">
</li>
<li>
<label for="firstname">Firstname</label>
<input type="text" name="firstname" id="firstname" class="required" minlength="5" placeholder="enter firstname">
</li>
<li>
<label for="username">Surname</label>
<input type="text" name="surname" id="surname" class="required" minlength="5" placeholder="enter surname">
</li>
<li>
<label for="email">Email</label>
<input type="email" name="email" id="email" class="required email" placeholder="yourname#email.com">
</li>
<li>
<label for="password">Password</label>
<input type="password" name="password" id="password" class="required" minlength="6" placeholder="enter password">
</li>
<li>
<label for="confirmpassword">Confirm Password</label>
<input type="password" name="confirmpassword" id="confirmpassword" class="required" minlength="6" placeholder="re-enter password">
</li>
<div id="registerbutton">
<input type="submit" value="Register">
</div>
</ul>
</form>
</section>
</div>
<!--********************************MAIN**********************************************-->
<!--********************************FOOTER**********************************************-->
<div data-role="footer">
<footer class="footer">
<p>awilliams©</p>
</footer>
</div>
</div>
<!--********************************REGISTER PAGE**********************************************-->
<!--****************************************************************************************-->
<!--********************************LOGIN PAGE**********************************************-->
<!--****************************************************************************************-->
<!--********************************HEADER**********************************************-->
<div data-role="page" id="login">
<div data-role="header" data-id="foo1" data-position="fixed">
<div class='cssmenu'>
<ul>
<li class='active'><a href='#home'>Home</a></li>
<li><a href='#sessionrecord'>Record a Session</a></li>
<li><a href='#viewsessions'>View Sessions</a></li>
<li><a href='#email'>E-mail an Invoice</a></li>
</ul>
</div>
</div>
<!--********************************HEADER**********************************************-->
<!--********************************MAIN**********************************************-->
<div data-role="main" class="ui-content">
<img class="mainlogo" src="/projects/ibill_v3/img/ibill logo.png" alt="iBill Logo" width="250" height="190">
<section class="loginform">
<form action="form.php" method="post">
<ul>
<li><label for="usermail">Email</label>
<input type="email" name="usermail" placeholder="yourname#email.com" class="required"></li>
<li><label for="password">Password</label>
<input type="password" name="password" placeholder="enter password" minlength="6"></li>
<li>
<div id="loginbutton">
<input type="submit" value="Login"></li>
</div>
<div id="registerbutton">
<input type="submit" value="Register"></li>
</div>
</ul>
</form>
</section>
</div>
<!--********************************MAIN**********************************************-->
<!--********************************FOOTER**********************************************-->
<div data-role="footer">
<footer class="footer">
<p>awilliams©</p>
</footer>
</div>
</div>
<!--********************************LOGIN PAGE**********************************************-->
<!--****************************************************************************************-->
<!--********************************HOME PAGE**********************************************-->
<!--***************************************************************************************-->
<!--********************************HEADER**********************************************-->
<div data-role="page" id="home">
<div data-role="header" data-id="foo1" data-position="fixed">
<div class='cssmenu'>
<ul>
<li class='active'><a href='#home'>Home</a></li>
<li><a href='#sessionrecord'>Record a Session</a></li>
<li><a href='#viewsessions'>View Sessions</a></li>
<li><a href='#email'>E-mail an Invoice</a></li>
</ul>
</div>
</div><!-- /header -->
<!--********************************HEADER**********************************************-->
<!--********************************MAIN**********************************************-->
<div data-role="main" class="ui-content">
<img class="mainlogo" src="/projects/ibill_v3/img/ibill logo.png" alt="iBill Logo" width="250" height="190">
<section class="maincontent">
<h1>The iBill Invoicing App for Activity Instructors</h1>
<p>iBill is a cross-platform app that allows you track and manage activity sessions on the go.</p>
<br>
<p>Record an activity session to get started!</p>
<div style="text-align:center">
Record a Session
</div>
</section>
</div>
<!--********************************MAIN**********************************************-->
<!--********************************FOOTER**********************************************-->
<div data-role="footer">
<footer class="footer">
<p>awilliams©</p>
</footer>
</div>
</div>
<!--********************************FOOTER**********************************************-->
<!--********************************HOME PAGE**********************************************-->
<!--***************************************************************************************-->
<!--********************************RECORD SESSION PAGE************************************-->
<!--***************************************************************************************-->
<!--********************************HEADER**********************************************-->
<div data-role="page" id="sessionrecord">
<div data-role="header" data-id="foo1" data-position="fixed">
<div class='cssmenu'>
<ul>
<li class='active'><a href='#home'>Home</a></li>
<li><a href='#sessionrecord'>Record a Session</a></li>
<li><a href='#viewsessions'>View Sessions</a></li>
<li><a href='#email'>E-mail an Invoice</a></li>
</ul>
</div>
</div><!-- /header -->
<!--********************************HEADER**********************************************-->
<!--********************************MAIN**********************************************-->
<div data-role="main" class="ui-content">
<img class="mainlogo" src="/projects/ibill_v3/img/ibill logo.png" alt="iBill Logo" width="250" height="190">
<section class="maincontent">
<h1>Record a session using the form below</h1>
<form method="post" action="" id="sessionRecord">
<fieldset>
<select name="typeofactivity" id="typeofactivity" data-native-menu="false">
<option>Type of Session</option>
<option value="surf">Surf</option>
<option value="coast">Coasteer</option>
<option value="bodyboard">Bodyboard</option>
<option value="climbing">Cornish Challenge</option>
</select>
</fieldset>
<fieldset>
<select name="employer" id="employer" data-native-menu="false">
<option>Employer</option>
<option value="nac">Newquay Activity Centre</option>
<option value="coastline">Coastline Coasteer</option>
</select>
</fieldset>
<form method="post" action="PHP HERE!">
<label for="datetime">Date and Time of Session</label>
<input type="datetime-local" data-clear-btn="false" name="datetime" id="datetime" value="">
</form>
<form method="post" action="PHP HERE!">
<label for="amount">Amount (GBP)</label>
<input type="number" data-clear-btn="true" name="amount" id="amount" value="">
</form>
<div id="submitbutton">
<input type="submit" value="Submit">
</div>
</form>
</section>
</div>
<!--********************************MAIN**********************************************-->
<!--********************************FOOTER**********************************************-->
<div data-role="footer">
<footer class="footer">
<p>awilliams©</p>
</footer>
</div>
</div>
<!--********************************FOOTER**********************************************-->
<!--********************************RECORD SESSION PAGE************************************-->
<!--***************************************************************************************-->
<!--********************************VIEW SESSIONS PAGE************************************-->
<!--***************************************************************************************-->
<!--********************************HEADER**********************************************-->
<div data-role="page" id="viewsessions">
<div data-role="header" data-id="foo1" data-position="fixed">
<div class='cssmenu'>
<ul>
<li class='active'><a href='#home'>Home</a></li>
<li><a href='#sessionrecord'>Record a Session</a></li>
<li><a href='#viewsessions'>View Sessions</a></li>
<li><a href='#email'>E-mail an Invoice</a></li>
</ul>
</div>
</div><!-- /header -->
<!--********************************HEADER**********************************************-->
<!--********************************MAIN**********************************************-->
<div data-role="main" class="ui-content">
<img class="mainlogo" src="/projects/ibill_v3/img/ibill logo.png" alt="iBill Logo" width="250" height="190">
<section class="maincontent">
<!--MAIN CONTENT GOES HERE-->
</section>
</div>
<!--********************************MAIN**********************************************-->
<!--********************************FOOTER**********************************************-->
<div data-role="footer">
<footer class="footer">
<p>awilliams©</p>
</footer>
</div>
</div>
<!--********************************FOOTER**********************************************-->
<!--********************************VIEW SESSIONS PAGE************************************-->
<!--***************************************************************************************-->
<!--********************************EMAIL AN INVOICE PAGE************************************-->
<!--***************************************************************************************-->
<!--********************************HEADER**********************************************-->
<div data-role="page" id="email">
<div data-role="header" data-id="foo1" data-position="fixed">
<div class='cssmenu'>
<ul>
<li class='active'><a href='#home'>Home</a></li>
<li><a href='#sessionrecord'>Record a Session</a></li>
<li><a href='#viewsessions'>View Sessions</a></li>
<li><a href='#email'>E-mail an Invoice</a></li>
</ul>
</div>
</div><!-- /header -->
<!--********************************HEADER**********************************************-->
<!--********************************MAIN**********************************************-->
<div data-role="main" class="ui-content">
<img class="mainlogo" src="/projects/ibill_v3/img/ibill logo.png" alt="iBill Logo" width="250" height="190">
<section class="maincontent">
<!--MAIN CONTENT GOES HERE-->
</section>
</div>
<!--********************************MAIN**********************************************-->
<!--********************************FOOTER**********************************************-->
<div data-role="footer">
<footer class="footer">
<p>awilliams©</p>
</footer>
</div>
</div>
<!--********************************FOOTER**********************************************-->
<!--********************************EMAIL AN INVOICE PAGE************************************-->
<!--***************************************************************************************-->
</body>
<?php
$servername = "localhost";
$username = "root";
$password = "cornwall";
$con=mysqli_connect('localhost','root','cornwall','ibill');
// This code creates a connec'tion to the MySQL database in PHPMyAdmin named 'ibill':
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// The connection is then checked, if it fails, an echo is sent back to the page stating a connection error.
$username = $_POST['username'];
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$emailaddress = $_POST['emailaddress'];
$password = $_POST['password'];
$confirmpassword = $_POST['confirmpassword'];
//These are the different PHP variables that store my posted data.
$register="INSERT INTO user_details (username, firstname, surname, emailaddress, password,) VALUES ('$username', '$firstname', '$surname', '$emailaddress', '$password')";
echo $register;
$result=mysqli_query($con, $register);
//This is the query that will be sent to the MySQL server.
header('Location: http://localhost/projects/ibill_v3/html/main.html#login');
exit();
//This directs the user to the relevant page after successful registration.
?>
First of all, read this article about SQL injection: How can I prevent SQL injection in PHP?.
There is an error in you SQL query. In your PHP file, replace this line:
$result=mysqli_query($con, $register);
with this:
if(mysqli_query($con,$register) === FALSE){
echo mysqli_error($con);
}
To display errors in PHP code, add these lines:
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
Ref: How do I get PHP errors to display?
Hi there I'm trying to get a user who comments and is logged in to their account for their 'Login Name' to display when they comment currenlty when a user wants to comment it asks for their name and their comment. Is it possible to display their name getting it from the session to display it? Thanks!
http://puu.sh/cByNU/697e58cdf6.jpg http://puu.sh/cByNU/697e58cdf6.jpg
On the image I'm logged in as 'Testing' is it possible to remove the field 'Name' and when they post a comment it will get their name where the search box is (testing).
Thanks!
My CODE:
<?php
session_start();
include "../includes/config.php";
include "function.php";
include ('../includes/header.php');
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Honda</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href='http://fonts.googleapis.com/css?family=Julius+Sans+One' rel='stylesheet' type='text/css'>
<link href="../css/style.css" rel="stylesheet" type="text/css" media="all" />
<!--start lightbox -->
<link rel="stylesheet" type="text/css" href="../css/jquery.lightbox.css">
<script src="../js/jquery.min.js"></script>
<script src="../js/jquery.lightbox.js"></script>
<script>
// Initiate Lightbox
$(function() {
$('.gallery1 a').lightbox();
});
</script>
</head>
<body>
<!--start header-->
<div class="h_bg">
<div class="wrap">
<div class="wrapper">
<div class="header">
<div class="logo">
<img src="../images/logo.png">
</div>
<div class="cssmenu">
<ul>
<li><span>Home</span></li>
<li><span>About</span></li>
<li class="active" class="has-sub"><span>Gallery</span>
</li>
<li class="last"><span>Contact</span></li>
<div class="clear"></div>
<form action="search.php" method="GET">
<div class="search">
<h2>search</h2>
<form>
<input type="text" name="query" placeholder="Enter Your search..." />
<input type="submit" value="">
</form>
</div>
</form>
<div class="search1">
<form action="" method="POST">
<br>
<h2>Welcome, <?=$_SESSION['sess_user'];?>!</h2><br><br>
<div class="pw">
<h3>Change details</h3>
</div>
<br><br>
<h2>Logout</h2>
</form>
</div>
</div>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<!-- start content -->
<div class="content_bg">
<div class="wrap">
<div class="wrapper">
<div class="main">
<div class="ser-main">
<h2 class="style">Gallery of honda</h2>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic1.jpg" alt="">
</div>
</div>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic2.jpg" alt="">
</div>
</div>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic3.jpg" alt="">
</div>
</div>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic4.jpg" alt="">
</div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<div class="footer_bg">
<div class="wrap">
<div class="wrapper">
<div class="footer">
<div class="search69">
<?php
if(isset($_POST['submit'])
&& !empty($_POST['name'])
&& !empty($_POST['comment']) ){
$name=$_POST['name'];
$comment=$_POST['comment'];
$submit=$_POST['submit'];
$insert=mysql_query("INSERT INTO comment (name,comment) VALUES ('$name','$comment') ");
echo "<meta HTTP-EQUIV='REFRESH' content='0; url=service.php'>";
}
else
{
echo "";
}
?>
<form class="comments" action="service.php" method="POST">
<h2>Name: </h2><br><input type="text" name="name" required/><br><br>
<h2>Comment:</h2><textarea name="comment" rows="10" cols="50" required></textarea><br><br><br>
<input type="submit" name="submit" value="Comment">
</form>
<?php
$getquery=mysql_query("SELECT * FROM comment ORDER BY id DESC");
while($rows=mysql_fetch_assoc($getquery))
{
$id=$rows['id'];
$date=$rows['date'];
$name=$rows['name'];
$comment=$rows['comment'];
echo '<h2><hr size="1"/><br><font color="green">' . $name . '</font><h2><br/>' . '<br/>' . $comment . '<br/><br><font color="red">' . $date. '</font><br/>' . '<hr size="1"/>'
;}
?>
</div>
<div class="copy">
<p class="w3-link">2014 </p>
Privacy & Policy
</div>
<div class="f_nav">
<ul>
<li>Skype</li>
<li>Linked in</li>
<li>Twitter</li>
<li>Facebook</li>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</body>
</html>
(ALL MY CODE ON THAT PAGE)
UPDATE:
The guys here will kill me, because now i am just edited your code, and not rewrite to mysqli or PDO, but as i saw, you stuck, so i've just updated, bacause i do not want to confuse with that too. I do some modifications, check my comments about that. (Moved the block of insertion to the top of file, add an error message, remove unnecesarry variables, rename the rows variable to row, etc...)
<?php
session_start();
include "../includes/config.php";
include "function.php";
include ('../includes/header.php');
//Set an empty errorMsg because later we will check it.
$errorMsg = '';
//If everything is set, or the SESSION["sess_user"] not empty.
//I moved this whole thing here, because if there are no output, we can
//redirect user from PHP, and do not need to use META REFREHS...
if (isset($_POST['submit']) && !empty($_POST['comment']) && (!empty($_POST["name"]) || !empty($_SESSION["sess_user"]))) {
if (!empty($_SESSION["sess_user"])) {
$name = $_SESSION["sess_user"];
} else {
$name = $_POST["name"];
}
//$comment = $_POST['comment']; //Use $_POST["comment"] directly
//$submit = $_POST['submit']; //Do not use it anywhere
$insert = mysql_query("INSERT INTO comment (name,comment) VALUES ('" . mysql_real_escape_string($name) . "','" . mysql_real_escape_string($_POST["comment"]) . "')");
Header("Location: service.php");
} else {
$errorMsg = "You need to fill all the fields.";
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Honda</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href='http://fonts.googleapis.com/css?family=Julius+Sans+One' rel='stylesheet' type='text/css'>
<link href="../css/style.css" rel="stylesheet" type="text/css" media="all" />
<!--start lightbox -->
<link rel="stylesheet" type="text/css" href="../css/jquery.lightbox.css">
<script src="../js/jquery.min.js"></script>
<script src="../js/jquery.lightbox.js"></script>
<script>
// Initiate Lightbox
$(function() {
$('.gallery1 a').lightbox();
});
</script>
</head>
<body>
<!--start header-->
<div class="h_bg">
<div class="wrap">
<div class="wrapper">
<div class="header">
<div class="logo">
<img src="../images/logo.png">
</div>
<div class="cssmenu">
<ul>
<li><span>Home</span></li>
<li><span>About</span></li>
<li class="active" class="has-sub"><span>Gallery</span>
</li>
<li class="last"><span>Contact</span></li>
<div class="clear"></div>
<form action="search.php" method="GET">
<div class="search">
<h2>search</h2>
<form>
<input type="text" name="query" placeholder="Enter Your search..." />
<input type="submit" value="">
</form>
</div>
</form>
<div class="search1">
<form action="" method="POST">
<br>
<h2>Welcome, <?= $_SESSION['sess_user']; ?>!</h2><br><br>
<div class="pw">
<h3>Change details</h3>
</div>
<br><br>
<h2>Logout</h2>
</form>
</div>
</div>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<!-- start content -->
<div class="content_bg">
<div class="wrap">
<div class="wrapper">
<div class="main">
<div class="ser-main">
<h2 class="style">Gallery of honda</h2>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic1.jpg" alt="">
</div>
</div>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic2.jpg" alt="">
</div>
</div>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic3.jpg" alt="">
</div>
</div>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic4.jpg" alt="">
</div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<div class="footer_bg">
<div class="wrap">
<div class="wrapper">
<div class="footer">
<div class="search69">
<?php
//Added here the errorMsg
if (!empty($errorMsg)) {
?>
<div class="error"><?php echo $errorMsg; ?></div>
<?php
}
?>
<form class="comments" action="service.php" method="POST">
<?php
if (!empty($_SESSION['sess_user'])) {
//If user logged in, use the name of it
?>
<h2>Name: </h2><br><?php echo $_SESSION['sess_user']; ?>
<br><br>
<?php
} else {
//Else, ask it
?>
<h2>Name: </h2><br><input type="text" name="name" required/><br><br>
<?php
}
?>
<h2>Comment:</h2><textarea name="comment" rows="10" cols="50" required></textarea><br><br><br>
<input type="submit" name="submit" value="Comment">
</form>
<?php
$getquery = mysql_query("SELECT * FROM comment ORDER BY id DESC");
//This is one row, not rows
while ($row = mysql_fetch_assoc($getquery)) {
/*
* These are not necessary
$id = $rows['id'];
$date = $rows['date'];
$name = $rows['name'];
$comment = $rows['comment'];
*/
echo '<h2><hr size="1"/><br><font color="green">' . $row['name'] . '</font><h2><br/>' . '<br/>' . $row['comment'] . '<br/><br><font color="red">' . $row['date'] . '</font><br/>' . '<hr size="1"/>'
;
}
?>
</div>
<div class="copy">
<p class="w3-link">2014 </p>
Privacy & Policy
</div>
<div class="f_nav">
<ul>
<li>Skype</li>
<li>Linked in</li>
<li>Twitter</li>
<li>Facebook</li>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</body>
</html>
NOTE: Do not use mysql functions since they are deprecated. use mysqli or PDO functions instead.
Acoid for sql injections, so escape your data!
If i got it well, you want the form to automatically gets the name of a logged user. You should:
<?php $username = isset($_SESSION['sess_user']) ? $_SESSION['sess_user'] : "";?>
To store the username or "" into $username, depending on whether user is authentified or not. Then in your input line within the form:
<h2>Name: </h2><br><input type="text" name="name" value="<?php echo $username; ?>" required/><br><br>