Related
Hello i'm having trouble with the install script for my system.
Currectly i try to solve some issues, but now it left me to skip this part and make installation correctly. Can someone help me to solve the code to be correct way.
So i'm struggling in this zone: if ($action == 'result') {
So i skip check the website adress and so one and go directly to install.
But after i enter dbname, host, user, pass, admin, password it does not install the .sql file and gives me error "Database Credential is Not Valid"
<?php
$itemName = 'playlab';
error_reporting(0);
$action = isset($_GET['action']) ? $_GET['action'] : '';
function appUrl()
{
$current = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$exp = explode('?action', $current);
$url = str_replace('index.php', '', $exp[0]);
$url = substr($url, 0, -8);
return $url;
}
if ($action == 'requirements') {
$passed = [];
$failed = [];
$requiredPHP = 8.1;
$currentPHP = explode('.', PHP_VERSION)[0] . '.' . explode('.', PHP_VERSION)[1];
if ($requiredPHP == $currentPHP) {
$passed[] = 'PHP version 8.1 is required';
} else {
$failed[] = 'PHP version 8.1 is required. Your current PHP version is ' . $currentPHP;
}
$extensions = ['BCMath', 'Ctype', 'cURL', 'DOM', 'Fileinfo', 'GD', 'JSON', 'Mbstring', 'OpenSSL', 'PCRE', 'PDO', 'pdo_mysql', 'Tokenizer', 'XML'];
foreach ($extensions as $extension) {
if (extension_loaded($extension)) {
$passed[] = strtoupper($extension) . ' PHP Extension is required';
} else {
$failed[] = strtoupper($extension) . ' PHP Extension is required';
}
}
if (function_exists('curl_version')) {
$passed[] = 'Curl via PHP is required';
} else {
$failed[] = 'Curl via PHP is required';
}
if (file_get_contents(__FILE__)) {
$passed[] = 'file_get_contents() is required';
} else {
$failed[] = 'file_get_contents() is required';
}
if (ini_get('allow_url_fopen')) {
$passed[] = 'allow_url_fopen() is required';
} else {
$failed[] = 'allow_url_fopen() is required';
}
$dirs = ['../core/bootstrap/cache/', '../core/storage/', '../core/storage/app/', '../core/storage/framework/', '../core/storage/logs/'];
foreach ($dirs as $dir) {
$perm = substr(sprintf('%o', fileperms($dir)), -4);
if ($perm >= '0775') {
$passed[] = str_replace("../", "", $dir) . ' is required 0775 permission';
} else {
$failed[] = str_replace("../", "", $dir) . ' is required 0775 permission. Current Permisiion is ' . $perm;
}
}
if (file_exists('database.sql')) {
$passed[] = 'database.sql should be available';
} else {
$failed[] = 'database.sql should be available';
}
if (file_exists('../.htaccess')) {
$passed[] = '".htaccess" should be available in root directory';
} else {
$failed[] = '".htaccess" should be available in root directory';
}
}
if ($action == 'result') {
$url = 'https://license.viserlab.com/';
$params = $_POST;
$params['product'] = $itemName;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result, true);
$response = array('error' => 'ok', 'message' => 'Valid license!');
if (#$response['error'] == 'ok') {
try {
$db = new PDO("mysql:host=$_POST[db_host];dbname=$_POST[db_name]", $_POST['db_user'], $_POST['db_pass']);
$dbinfo = $db->query('SELECT VERSION()')->fetchColumn();
$engine = #explode('-', $dbinfo)[1];
$version = #explode('.', $dbinfo)[0] . '.' . #explode('.', $dbinfo)[1];
if (strtolower($engine) == 'mariadb') {
if ($version < 10.3) {
$response['error'] = 'error';
$response['message'] = 'MariaDB 10.3+ Or MySQL 5.7+ Required. <br> Your current PHP version is MariaDB ' . $version;
}
} else {
if ($version < 5.7) {
$response['error'] = 'error';
$response['message'] = 'MariaDB 10.3+ Or MySQL 5.7+ Required. <br> Your current PHP version is MySQL ' . $version;
}
}
} catch (Exception $e) {
$response['error'] = 'error';
$response['message'] = 'Database Credential is Not Valid';
}
}
if (#$response['error'] == 'ok') {
try {
$query = file_get_contents("database.sql");
$stmt = $db->prepare($query);
$stmt->execute();
$stmt->closeCursor();
} catch (Exception $e) {
$response['error'] = 'error';
$response['message'] = 'Problem Occurred When Importing Database!<br>Please Make Sure The Database is Empty.';
}
}
if (#$response['error'] == 'ok') {
try {
$db_name = $_POST['db_name'];
$db_host = $_POST['db_host'];
$db_user = $_POST['db_user'];
$db_pass = $_POST['db_pass'];
$email = $_POST['email'];
$siteurl = appUrl();
$app_key = base64_encode(random_bytes(32));
$envcontent = "
APP_NAME=Laravel
APP_ENV=production
APP_KEY=base64:$app_key
APP_DEBUG=false
APP_URL=$siteurl
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=$db_host
DB_PORT=3306
DB_DATABASE=$db_name
DB_USERNAME=$db_user
DB_PASSWORD=$db_pass
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME='${APP_NAME}'
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY='${PUSHER_APP_KEY}'
MIX_PUSHER_APP_CLUSTER='${PUSHER_APP_CLUSTER}'
";
$envpath = dirname(__DIR__, 1) . '\core\.env';
file_put_contents($envpath, $envcontent);
} catch (Exception $e) {
$response['error'] = 'error';
$response['message'] = 'Problem Occurred When Writing Environment File.';
}
}
if (#$response['error'] == 'ok') {
try {
$db->query("UPDATE admins SET email='" . $_POST['email'] . "', username='" . $_POST['admin_user'] . "', password='" . password_hash($_POST['admin_pass'], PASSWORD_DEFAULT) . "' WHERE username='admin'");
} catch (Exception $e) {
$response['message'] = 'EasyInstaller was unable to set the credentials of admin.';
}
}
}
$sectionTitle = empty($action) ? 'Terms of Use' : $action;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Easy Installer by ViserLab</title>
<link rel="stylesheet" href="../assets/global/css/bootstrap.min.css">
<link rel="stylesheet" href="../assets/global/css/all.min.css">
<link rel="stylesheet" href="../assets/global/css/installer.css">
<link rel="shortcut icon" href="https://license.viserlab.com/external/favicon.png" type="image/x-icon">
</head>
<body>
<header class="py-3 border-bottom border-primary bg--dark">
<div class="container">
<div class="d-flex align-items-center justify-content-between header gap-3">
<img class="logo" src="https://license.viserlab.com/external/logo.png" alt="ViserLab">
<h3 class="title">Easy Installer</h3>
</div>
</div>
</header>
<div class="installation-section padding-bottom padding-top">
<div class="container">
<div class="installation-wrapper">
<div class="install-content-area">
<div class="install-item">
<h3 class="title text-center"><?php echo $sectionTitle; ?></h3>
<div class="box-item">
<?php
if ($action == 'result') {
echo '<div class="success-area text-center">';
if (#$response['error'] == 'ok') {
echo '<h2 class="text-success text-uppercase mb-3">Your system has been installed successfully!</h2>';
if (#$response['message']) {
echo '<h5 class="text-warning mb-3">' . $response['message'] . '</h5>';
}
echo '<p class="text-danger lead my-5">Please delete the "install" folder from the server.</p>';
echo '<div class="warning">Go to website and Activate</div>';
} else {
if (#$response['message']) {
echo '<h3 class="text-danger mb-3">' . $response['message'] . '</h3>';
} else {
echo '<h3 class="text-danger mb-3">Your Server is not Capable to Handle the Request.</h3>';
}
echo '<div class="warning mt-2"><h5 class="mb-4 fw-normal">You can ask for support by creating a support ticket.</h5>create ticket</div>';
}
echo '</div>';
} elseif ($action == 'information') {
?>
<form action="?action=result" method="post" class="information-form-area mb--20">
<div class="info-item">
<h5 class="font-weight-normal mb-2">Website URL</h5>
<div class="row">
<div class="information-form-group col-12">
<input name="url" value="<?php echo appUrl(); ?>" type="text" required>
</div>
</div>
</div>
<div class="info-item">
<h5 class="font-weight-normal mb-2">Database Details</h5>
<div class="row">
<div class="information-form-group col-sm-6">
<input type="text" name="db_name" placeholder="Database Name" required>
</div>
<div class="information-form-group col-sm-6">
<input type="text" name="db_host" placeholder="Database Host" required>
</div>
<div class="information-form-group col-sm-6">
<input type="text" name="db_user" placeholder="Database User" required>
</div>
<div class="information-form-group col-sm-6">
<input type="text" name="db_pass" placeholder="Database Password">
</div>
</div>
</div>
<div class="info-item">
<h5 class="font-weight-normal mb-3">Admin Credential</h5>
<div class="row">
<div class="information-form-group col-lg-3 col-sm-6">
<label>Username</label>
<input name="admin_user" type="text" placeholder="Admin Username" required>
</div>
<div class="information-form-group col-lg-3 col-sm-6">
<label>Password</label>
<input name="admin_pass" type="text" placeholder="Admin Password" required>
</div>
<div class="information-form-group col-lg-6">
<label>Email Address</label>
<input name="email" placeholder="Your Email address" type="email" required>
</div>
</div>
</div>
<div class="info-item">
<div class="information-form-group text-end">
<button type="submit" class="theme-button choto">Install Now</button>
</div>
</div>
</form>
<?php
} elseif ($action == 'requirements') {
$btnText = 'View Detailed Check Result';
if (count($failed)) {
$btnText = 'View Passed Check';
echo '<div class="item table-area"><table class="requirment-table">';
foreach ($failed as $fail) {
echo "<tr><td>$fail</td><td><i class='fas fa-times'></i></td></tr>";
}
echo '</table></div>';
}
if (!count($failed)) {
echo '<div class="text-center"><i class="far fa-check-circle success-icon text-success"></i><h5 class="my-3">Requirements Check Passed!</h5></div>';
}
if (count($passed)) {
echo '<div class="text-center my-3"><button class="btn passed-btn" type="button" data-bs-toggle="collapse" data-bs-target="#collapsePassed" aria-expanded="false" aria-controls="collapsePassed">' . $btnText . '</button></div>';
echo '<div class="collapse mb-4" id="collapsePassed"><div class="item table-area"><table class="requirment-table">';
foreach ($passed as $pass) {
echo "<tr><td>$pass</td><td><i class='fas fa-check'></i></td></tr>";
}
echo '</table></div></div>';
}
echo '<div class="item text-end mt-3">';
if (count($failed)) {
echo '<a class="theme-button btn-warning choto" href="?action=requirements">ReCheck <i class="fa fa-sync-alt"></i></a>';
} else {
echo '<a class="theme-button choto" href="?action=information">Next Step <i class="fa fa-angle-double-right"></i></a>';
}
echo '</div>';
} else {
?>
<div class="item">
<h4 class="subtitle">License to be used on one(1) domain(website) only!</h4>
<p> The Regular license is for one website or domain only. If you want to use it on multiple websites or domains you have to purchase more licenses (1 website = 1 license). The Regular License grants you an ongoing, non-exclusive, worldwide license to make use of the item.</p>
</div>
<div class="item">
<h5 class="subtitle font-weight-bold">You Can:</h5>
<ul class="check-list">
<li> Use on one(1) domain only. </li>
<li> Modify or edit as you want. </li>
<li> Translate to your choice of language(s).</li>
</ul>
<span class="text-warning"><i class="fas fa-exclamation-triangle"></i> If any issue or error occurred for your modification on our code/database, we will not be responsible for that. </span>
</div>
<div class="item">
<h5 class="subtitle font-weight-bold">You Cannot: </h5>
<ul class="check-list">
<li class="no"> Resell, distribute, give away, or trade by any means to any third party or individual. </li>
<li class="no"> Include this product into other products sold on any market or affiliate websites. </li>
<li class="no"> Use on more than one(1) domain. </li>
</ul>
</div>
<div class="item">
<p class="info">For more information, Please Check The License FAQ</p>
</div>
<div class="item text-end">
I Agree, Next Step
</div>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
<footer class="py-3 text-center bg--dark border-top border-primary">
<div class="container">
<p class="m-0 font-weight-bold">©<?php echo Date('Y') ?> - All Right Reserved by ViserLab</p>
</div>
</footer>
<script src="../assets/global/js/bootstrap.bundle.min.js"></script>
</body>
</html>
hi i need help i have problem in my code and i can't figure the solutions please help me .
this is the dashboard:
image dashboard
and this is problem after click on delete:
delete problem
and this is my code php of posts file:
<?php
/*
===========================================================
=== Manage Members Page ===
=== You can add | edit | delete Members from here ===
===========================================================
*/
session_start();
if (isset($_SESSION['Username'])) {
include 'init.php';
$pageTitle = 'Posts';
$do = isset($_GET['do']) ? $_GET['do'] : 'Manage' ;
//Start Manage Page
if ($do == 'Manage'){ // Manage Members Page
$sort = 'ASC';
$sort_arry = array('ASC', 'DESC');
if(isset($_GET['sort']) && in_array($_GET['sort'], $sort_arry)) {
$sort = $_GET['sort'];
}
$stmt2 = $con->prepare("SELECT * FROM posts ORDER BY Ordering $sort");
$stmt2->execute();
$rows = $stmt2->fetchAll();
?>
<h1 class="text-center"> Manage Posts </h1>
<div class="container categories">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-edit"></i> Manage Posts
<div class="ordering pull-right">
<i class="fa fa-sort"> </i>Ordering: [
<a class="<?php if ($sort == 'ASC') { echo 'active'; } ?>" href="?sort=ASC">Asc </a> |
<a class="<?php if ($sort == 'DESC') { echo 'active'; } ?>" href="?sort=DESC">Desc </a>
]
</div>
</div>
<div class="row">
<?php
foreach ($rows as $image) {
echo '<div class="col-md-3 col-sm-4 "><div class="thumbnail">';
echo '<h2 class="h4">'.$image['Name']. '</h2><div class="main">';
echo '<img src="data:image;base64,'.$image['Image'].' " alt="image name" title="image title" width="255" heigth="255">';
echo '</div>';
echo '<table class="table table-bordered">';
echo '<tr>';
echo '<td>' . "<a href='posts.php?do=Edit&id=". $image['ID'] ."' class='btn btn-xs btn-primary'><i class='fa fa-edit'></i> edit</a>" . '</td>';
echo '<td>' . "<a href='posts.php?do=Delete&id=". $image['ID'] ."' class='btn btn-xs btn-danger'><i class='fa fa-close'></i> Delete</a>" . '</td>';
echo '</tr>';
echo '</table>';
echo '</div>';
echo '</div>';
}
?>
</div>
<?php } elseif ($do == 'Add') { //add Member page ?>
<h1 class="text-center"> ajouter un nouveau post </h1>
<div class="container">
<form class="form-horizontal" enctype="multipart/form-data" action="?do=Insert" method="POST">
<!-- start Username fieled -->
<div class="form-group">
<label class="col-sm-2 control-label">Titre</label>
<div class="col-sm-10 col-md-8">
<input type="text" name="image-name" class="form-control" autocomplete="off" placeholder="username pour se connecter dans le site Web" required />
</div>
</div>
<!-- end Username fieled -->
<!-- start Password fieled -->
<div class="form-group">
<label class="col-sm-2 control-label">Image</label>
<div class="col-sm-10 col-md-8">
<input type="file" name="image" class="form-control" placeholder="mot de passe doit être difficile et complexe" required/>
</div>
</div>
<!-- end Password fieled -->
<!-- start Full name fieled -->
<div class="form-group">
<label class="col-sm-2" for="categorie">Categories:</label>
<div class="col-sm-10 col-md-8">
<select class="form-control" name="categorie">
<?php
$stmt = $con->prepare("SELECT * FROM `categories`");
// Execute the Statments
$stmt->execute();
// Assign to variable
$rows = $stmt->fetchAll();
?>
<?php
foreach ($rows as $cat) {
echo "<option value='" . $cat['ID'] . "'>". $cat['Name'] . "</option>";
}
?>
</select>
</div>
</div>
<!-- end Full name fieled -->
<!-- start submit fieled -->
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" value="Ajouter" class="btn btn-primary" />
</div>
</div>
<!-- end submit fieled -->
</form>
</div>
<?php
} elseif ($do == 'Insert') {
//insert Members Page
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo "<h1 class='text-center'> insert an post </h1>";
echo "<div class='container'>";
// Get variable from the form
$name = $_POST['image-name'];
$image= addslashes($_FILES['image']['tmp_name']);
$image= file_get_contents($image);
$image= base64_encode($image);
$cat = $_POST['categorie'];
//validate the form
$formErrors = array();
if (strlen($name) < 4) {
$formErrors[] = "title name cant be less then <strong> 4 caracter</strong>";
}
if (strlen($name) > 20) {
$formErrors[] = "title name cant be More then <strong> 20 caracter</strong>";
}
if (empty($name)) {
$formErrors[] = "Username Cant Be <strong>Empty</strong>";
}
// loop into eroos array and echo it
foreach ($formErrors as $Error) {
echo "<div class='alert alert-danger'>" . $Error . "</div>";
}
// check if There is no error procced the operations
if (empty($formErrors)) {
// check if user exist in database
$check = checkItem("Username", "users", $user);
if ($check == 1) {
$theMsg = "<div class='alert alert-danger'> Sorry this user is exist </div>";
redirectHome($theMsg, 'back');
} else {
// Insert User info into database
$stmt = $con->prepare("INSERT INTO posts(Name, Image, Cat_id)
VALUES (:name, :image, :cat)");
$stmt->execute(array(
'name' => $name,
'image' => $image,
'cat' => $cat,
));
// echo success message
$theMsg = "<div class='alert alert-success'>" . $stmt->rowCount() . ' Record Inserted </div> ';
redirectHome($theMsg, 'back', 5);
}
}
} else {
echo "<div class='container'>";
$theMsg = '<div class="alert alert-danger"> Sorry you cant browse this page directely </div>';
redirectHome($theMsg, 'back', 5); // 6 is secend of redirect to page in function
echo "</div>";
}
echo "</div>";
} elseif ($do == 'Edit') { // Edit Page
//check if GET request userid Is numeric & Get The integer value of it
$post = isset($_GET['id']) && is_numeric($_GET['id']) ? intval($_GET['id']) : 0;
//sellect All Data Depend On This ID
$stmt = $con->prepare("SELECT * FROM posts WHERE ID = ? LIMIT 1");
// execute Query
$stmt->execute(array($post));
//fetch the Data
$row = $stmt->fetch();
// The row count
$count = $stmt->rowCount();
// If Ther's Such Id show The Form
if ($count > 0) { ?>
<h1 class="text-center"> Modifier Post </h1>
<div class="container">
<form class="form-horizontal" enctype="multipart/form-data" action="?do=Update" method="POST">
<div class="col-md-6 col-md-offset-3 panel">
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>
<!-- start title fieled -->
<div class="form-group">
<label class="col-sm-2 control-label">Titre</label>
<div class="col-sm-10 col-md-8">
<input type="text" name="name" class="form-control" autocomplete="off" required value="<?php echo $row['Name']; ?>" >
</div>
</div>
<!-- end title field -->
<!-- start image filed -->
<div class="form-group">
<label class="col-sm-2 control-label">image</label>
<div class="col-sm-10 col-md-8">
<input type="file" name="image" class="form-control" />
</div>
</div>
<!-- end image filed -->
<!-- start Categories filed -->
<div class="form-group">
<label class="col-sm-2" for="categorie">Categories:</label>
<div class="col-sm-10 col-md-8">
<select class="form-control" name="categorie">
<?php
$stmt = $con->prepare("SELECT * FROM `categories`");
// Execute the Statments
$stmt->execute();
// Assign to variable
$rows = $stmt->fetchAll();
?>
<?php
foreach ($rows as $cat) {
echo "<option value='" . $cat['ID'] . "'>". $cat['Name'] . "</option>";
}
?>
</select>
</div>
</div>
<!-- Categories end-->
<!-- start submit fieled -->
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" value="sauvegarder" class="btn btn-primary" />
</div>
</div>
<!-- end submit fieled -->
</div>
</form>
</div>
<?php
// if there's No Such id Show Error Message
} else {
echo "<div class='container'>";
$theMsg = "<div class='alert alert-danger'>Theres is no such Id</div>";
redirectHome($theMsg);
echo "</div>";
}
} elseif ($do == 'Update') {
echo "<h1 class='text-center'> mis a jour Membre </h1>";
echo "<div class='container'>";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Get variable from the form
$id = $_POST['id'];
$name = $_POST['name'];
$image = addslashes($_FILES['image']['tmp_name']);
$image = file_get_contents($image);
$image = base64_encode($image);
$cat = $_POST['categorie'];
//validate the form
$formErrors = array();
if (empty($name)) {
$formErrors[] = "<div class='alert alert-danger'>Username Cant Be <strong>Empty</strong> </div>";
}
if (empty($image)) {
$formErrors[] = "<div class='alert alert-danger'>FullName Cant Be <strong>Empty</strong></div>";
}
if (empty($cat)) {
$formErrors[] = "<div class='alert alert-danger'>Email Cant Be <strong>Empty</strong></div>";
}
// loop into eroos array and echo it
foreach ($formErrors as $Error) {
echo $Error;
}
// check if There is no error procced the operations
if (empty($formErrors)) {
// Update The Database With This Info
$stmt = $con->prepare("UPDATE posts SET Name = ? , Image = ? , Cat_id = ? WHERE ID = ?");
$stmt->execute(array($name, $image, $cat, $id));
// echo success message
$theMsg = "<div class='alert alert-success'>" . $stmt->rowCount() . ' Record Updated </div> ';
redirectHome($theMsg, 'back');
}
} else {
$theMsg = '<div class="alert alert-danger">Sorry you cant browse this page directely </div>';
redirectHome($theMsg);
}
echo "</div>";
}
elseif ($do == 'Delete') { // Delete Member Page
echo "<h1 class='text-center'> Delete Membre </h1>";
echo "<div class='container'>";
//check if GET request userid Is numeric & Get The integer value of it
$id = isset($_GET['id']) && is_numeric($_GET['id']) ? intval($_GET['id']) : 0;
//sellect All Data Depend On This ID
$check = checkItem('id', 'posts', $id);
// If Ther's Such Id show The Form
if ($check > 0) {
$stmt = $con->prepare("DELETE FROM users WHERE ID = :id");
$stmt->bindParam(":id", $id);
$stmt->execute();
$theMsg = "<div class='alert alert-success'>" . $stmt->rowCount() . ' Record Deleted </div> ';
redirectHome($theMsg);
} else {
$theMsg = "<div class='alert alert-danger'>This id not exist</div>";
redirectHome($theMsg);
}
echo "</div>";
}
include $tpl . 'footer.php';
} else {
header('Location: index.php') ;
exit();
}
from the error, id is the problem.
isset($_GET['id']) && is_numeric($_GET['id'])
i think what u want is
(isset($_GET['id']) && is_numeric($_GET['id']) )//close parantheses in wrong position
I am using PhpExcel to download reports as excel in my codeigniter application. When I try to download my report its showing some characters on the browser instead of downloading the file. This has worked fine in localhost but not working in the server. I dont know whats the problem. Here is my code:
View
<div class="box-content">
<div class="row">
<div class="col-lg-12">
<p class="introtext"><?= lang('customize_report'); ?></p>
<div id="form">
<?php echo form_open("reports/getSalesaccReport"); ?>
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label class="control-label" for="reference_no"><?= lang("reference_no"); ?></label>
<?php echo form_input('reference_no', (isset($_POST['reference_no']) ? $_POST['reference_no'] : ""), 'class="form-control tip" id="reference_no"'); ?>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label class="control-label" for="user"><?= lang("created_by"); ?></label>
<?php
$us[""] = "";
foreach ($users as $user) {
$us[$user->id] = $user->first_name . " " . $user->last_name;
}
echo form_dropdown('user', $us, (isset($_POST['user']) ? $_POST['user'] : ""), 'class="form-control" id="user" data-placeholder="' . $this->lang->line("select") . " " . $this->lang->line("user") . '"');
?>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label class="control-label" for="customer"><?= lang("customer"); ?></label>
<?php echo form_input('customer', (isset($_POST['customer']) ? $_POST['customer'] : ""), 'class="form-control" id="customer" data-placeholder="' . $this->lang->line("select") . " " . $this->lang->line("customer") . '"'); ?>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label class="control-label" for="biller"><?= lang("biller"); ?></label>
<?php
$bl[""] = "";
foreach ($billers as $biller) {
$bl[$biller->id] = $biller->company != '-' ? $biller->company : $biller->name;
}
echo form_dropdown('biller', $bl, (isset($_POST['biller']) ? $_POST['biller'] : ""), 'class="form-control" id="biller" data-placeholder="' . $this->lang->line("select") . " " . $this->lang->line("biller") . '"');
?>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label class="control-label" for="warehouse"><?= lang("warehouse"); ?></label>
<?php
$wh[""] = "";
foreach ($warehouses as $warehouse) {
$wh[$warehouse->id] = $warehouse->name;
}
echo form_dropdown('warehouse', $wh, (isset($_POST['warehouse']) ? $_POST['warehouse'] : ""), 'class="form-control" id="warehouse" data-placeholder="' . $this->lang->line("select") . " " . $this->lang->line("warehouse") . '"');
?>
</div>
</div>
<?php if($this->Settings->product_serial) { ?>
<div class="col-sm-4">
<div class="form-group">
<?= lang('serial_no', 'serial'); ?>
<?= form_input('serial', '', 'class="form-control tip" id="serial"'); ?>
</div>
</div>
<?php } ?>
<div class="col-sm-4">
<div class="form-group">
<?= lang("start_date", "start_date"); ?>
<?php echo form_input('start_date', (isset($_POST['start_date']) ? $_POST['start_date'] : ""), 'class="form-control datetime" id="start_date"'); ?>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<?= lang("end_date", "end_date"); ?>
<?php echo form_input('end_date', (isset($_POST['end_date']) ? $_POST['end_date'] : ""), 'class="form-control datetime" id="end_date"'); ?>
</div>
</div>
</div>
<div class="form-group">
<div
class="controls"> <?php echo form_submit('submit_report', $this->lang->line("submit"), 'class="btn btn-primary"'); ?> </div>
</div>
<?php echo form_close(); ?>
</div>
Controller
function getSalesaccReport()
{
if ($this->input->post('customer')) {
$customerid = $this->input->post('customer');
} else {
$customerid = NULL;
}
echo $customerid;
if ($this->input->post('biller')) {
$biller = $this->input->post('biller');
} else {
$biller = NULL;
}
if ($this->input->post('warehouse')) {
$warehouse = $this->input->post('warehouse');
} else {
$warehouse = NULL;
}
if ($this->input->post('start_date')) {
$start_date = $this->input->post('start_date');
} else {
$start_date = NULL;
} echo $start_date;
if ($this->input->post('end_date')) {
$end_date = $this->input->post('end_date');
} else {
$end_date = NULL;
} echo $end_date;
if ($start_date) {
$start_date = $this->sma->fld($start_date);
$end_date = $this->sma->fld($end_date);
}
if (!$this->Owner && !$this->Admin) {
$user = $this->session->userdata('user_id');
}
$dateTmp = "DATE_FORMAT(".$this->db->dbprefix('sales').".date,'%m/%Y')";
$condition = "if(".$this->db->dbprefix('sales').".biller_id = 5, 'A', if(".$this->db->dbprefix('sales').".biller_id = 6, 'B',if(".$this->db-> dbprefix('sales').".biller_id = 7,'C','D' )))";
$this->db
->select("date, ".$this->db->dbprefix('warehouses').".name,
CONCAT(".$this->db->dbprefix('warehouses').".name,'-',".$dateTmp.",'-', ".$condition.",".$this->db->dbprefix('sales').".invoice_no) as month," ." biller, customer,
scan_no,unit_price,tin,cin,cst,total_discount, item_tax, shipping,subtotal,payment_status,sales.id as saleid,total_items,total,biller_id,tax_rate_id,grand_total,quantity", FALSE)
->from('sales')
->join('sale_items', 'sale_items.sale_id=sales.id', 'left')
->join('companies','companies.id=sales.customer_id', 'left')
->join('warehouses', 'warehouses.id=sales.warehouse_id', 'left')
->group_by('sales.id')
->order_by('sales.date desc');
if ($biller) {
$this->db->where('sales.biller_id', $biller);
}
if ($customerid) {
$this->db->where('sales.customer_id', $customerid);
}
if ($warehouse) {
$this->db->where('sales.warehouse_id', $warehouse);
}
if (($start_date) && ($end_date)) {
$this->db->where($this->db->dbprefix('sales').'.date BETWEEN "' . $start_date . '" and "' . $end_date . '"');
}
/* if ($start_date) {
$this->db->where($this->db->dbprefix('sales').'.date LIKE "' . $start_date . '"');
}
if ($end_date) {
$this->db->where($this->db->dbprefix('sales').'.date LIKE "' . $end_date . '"');
} */
$q = $this->db->get();
if ($q->num_rows() > 0) {
foreach (($q->result()) as $row) {
$data[] = $row;
}
} else {
$data = NULL;
}
if (!empty($data))
{
$this->load->library('excel');
$this->excel->setActiveSheetIndex(0);
$this->excel->getActiveSheet()->setTitle(lang('sales_report'));
$this->excel->getActiveSheet()->SetCellValue('A1', lang('date'));
$this->excel->getActiveSheet()->SetCellValue('B1', lang('branch'));
$this->excel->getActiveSheet()->SetCellValue('C1', lang('Vch_No.'));
$this->excel->getActiveSheet()->SetCellValue('D1', lang('Voucher_Type'));
$this->excel->getActiveSheet()->SetCellValue('E1', lang('Particulars'));
$this->excel->getActiveSheet()->SetCellValue('F1', lang('TIN_No.'));
$this->excel->getActiveSheet()->SetCellValue('G1', lang('CIN'));
$this->excel->getActiveSheet()->SetCellValue('H1', lang('CST_No.'));
$this->excel->getActiveSheet()->SetCellValue('I1', lang('Scan_No'));
$this->excel->getActiveSheet()->SetCellValue('J1', lang('Product'));
$this->excel->getActiveSheet()->SetCellValue('K1', lang('quantity'));
$this->excel->getActiveSheet()->SetCellValue('L1', lang('Rate'));
$this->excel->getActiveSheet()->SetCellValue('M1', lang('Sales_#__5%'));
$this->excel->getActiveSheet()->SetCellValue('N1', lang('Output_Vat_#_5%'));
$this->excel->getActiveSheet()->SetCellValue('O1', lang('Sales_#_14.5%'));
$this->excel->getActiveSheet()->SetCellValue('P1', lang('Output_Vat_#_14.5%'));
$this->excel->getActiveSheet()->SetCellValue('Q1', lang('Sales_#_0%'));
$this->excel->getActiveSheet()->SetCellValue('R1', lang('Scanning_charge'));
$this->excel->getActiveSheet()->SetCellValue('S1', lang('Scanning_Discount'));
$this->excel->getActiveSheet()->SetCellValue('T1', lang('Shipping'));
$this->excel->getActiveSheet()->SetCellValue('U1', lang('Gross_Total'));
$row = 2;
$total = 0;
$paid = 0;
$balance = 0;
$quantity= 0;
$prdt_price = 0;
$sale5=0.00;
$output5=0.00;
$sale145=0.00;
$output145=0.00;
$sale0=0.00;
$discount=0;
foreach ($data as $data_row)
{
$saleid=$data_row->saleid;
$billerid=$data_row->biller_id;
$gross_total= $data_row->grand_total + shipping;
if($billerid==7)
{
$sale0=0;
$discount=$data_row->total_discount;
/*$scanqty=$data_row->quantity;
if($scanqty==0.5)
{
$scanning_charge+=500;
}
else if($scanqty==1)
{
$scanning_charge+=1000;
}*/
$this->db->select("sum(`quantity`*1000) as scanning_charge", FALSE);
$this->db->where('sale_id',$saleid);
$queryres = $this->db->get('sale_items');
if($queryres->num_rows() > 0)
{
foreach($queryres->result() as $queryres1)
{
$scanning_charge=$queryres1->scanning_charge;
}
}
else
{
}
}
else
{
$scanning_charge=0;
$discount=0;
}
if(($billerid==5) || ($billerid==6))
{
$this->db->select("sum( case when tax_rate_id = 1 then `net_unit_price`*`quantity` else 0 end) as sale0", FALSE);
$this->db->where('sale_id',$saleid);
$res1=$this->db->get('sale_items');
if($res1->num_rows() > 0)
{
echo $billerid;
foreach ($res1->result() as $row31)
{
$sale0=$row31->sale0;
}
}
else
{
}
}
$total0=$data_row->total;
$this->db->select("GROUP_CONCAT(DISTINCT product_name) as products,SUM(quantity)as prdtqty")
->from('sale_items')
->where('sale_id',$saleid);
$q1 = $this->db->get();
if ($q1->num_rows() > 0)
{
foreach (($q1->result()) as $row1)
{
$products = $row1->products;
$prdtqty = $row1->prdtqty;
}
}
else
{
$products="";
}
$sql="select sum( case when tax_rate_id = 2 then net_unit_price*quantity else 0 end) as sale5,
sum( case when tax_rate_id = 3 then net_unit_price*quantity else 0 end) as sale145,
sum( case when tax_rate_id = 2 then item_tax else 0 end) as output5,
sum( case when tax_rate_id = 3 then item_tax else 0 end) as output145
from sma_sale_items
where sale_id=".$saleid;
$res=$this->db->query($sql);
if($res->num_rows() > 0)
{
foreach ($res->result() as $row3)
{
$sale5=$row3->sale5;
$output5=$row3->output5;
$sale145=$row3->sale145;
$output145=$row3->output145;
}
}
$this->excel->getActiveSheet()->SetCellValue('A' . $row, $this->sma->hrld($data_row->date));
$this->excel->getActiveSheet()->SetCellValue('B' . $row, $data_row->name);
$this->excel->getActiveSheet()->SetCellValue('C' . $row, $data_row->month);
$this->excel->getActiveSheet()->SetCellValue('D' . $row, $data_row->biller);
$this->excel->getActiveSheet()->SetCellValue('E' . $row, $data_row->customer);
$this->excel->getActiveSheet()->SetCellValue('F' . $row, $data_row->tin);
$this->excel->getActiveSheet()->SetCellValue('G' . $row, $data_row->cin);
$this->excel->getActiveSheet()->SetCellValue('H' . $row, $data_row->cst);
$this->excel->getActiveSheet()->SetCellValue('I' . $row, $data_row->scan_no);
$this->excel->getActiveSheet()->SetCellValue('J' . $row, $products);
$this->excel->getActiveSheet()->SetCellValue('K' . $row, $prdtqty);
$this->excel->getActiveSheet()->SetCellValue('L' . $row, $data_row->total);
$this->excel->getActiveSheet()->SetCellValue('M' . $row, $sale5);
$this->excel->getActiveSheet()->SetCellValue('N' . $row, $output5);
$this->excel->getActiveSheet()->SetCellValue('O' . $row, $sale145);
$this->excel->getActiveSheet()->SetCellValue('P' . $row, $output145);
$this->excel->getActiveSheet()->SetCellValue('Q' . $row, $sale0);
$this->excel->getActiveSheet()->SetCellValue('R' . $row, $scanning_charge);
$this->excel->getActiveSheet()->SetCellValue('S' . $row, $discount);
$this->excel->getActiveSheet()->SetCellValue('T' . $row, $data_row->shipping);
$this->excel->getActiveSheet()->SetCellValue('U' . $row, $gross_total);
$total += $data_row->subtotal;
$paid += $data_row->item_tax;
$row++;
}
$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(18);
$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(8);
$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(10);
$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(10);
$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(12);
$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(30);
$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(10);
$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(11);
$this->excel->getActiveSheet()->getColumnDimension('M')->setWidth(13);
$this->excel->getActiveSheet()->getColumnDimension('N')->setWidth(17);
$this->excel->getActiveSheet()->getColumnDimension('O')->setWidth(14);
$this->excel->getActiveSheet()->getColumnDimension('P')->setWidth(20);
$this->excel->getActiveSheet()->getColumnDimension('Q')->setWidth(12);
$this->excel->getActiveSheet()->getColumnDimension('R')->setWidth(18);
$this->excel->getActiveSheet()->getColumnDimension('S')->setWidth(20);
$this->excel->getActiveSheet()->getColumnDimension('T')->setWidth(12);
$this->excel->getActiveSheet()->getColumnDimension('U')->setWidth(14);
$filename = 'sales_report';
$this->excel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$this->excel->getActiveSheet()->getStyle('E2:E' . $row)->getAlignment()->setWrapText(true);
ob_clean();
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $filename . '.xls"');
header('Cache-Control: max-age=0');
ob_clean();
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
$objWriter->save('php://output');
exit();
}
else{
$this->session->set_flashdata('error', lang('nothing_found'));
redirect('reports/sales_accounts');
}
}
Here is my browser view:
Can anyone please help me to fix this.. I am really in need of this.. Thanks in advance.
Try this
ob_clean();
ob_start(); # added
header('Content-type: application/vnd.ms-excel; charset=UTF-8" ); # Improved with UTF charset
header('Content-Disposition: attachment;filename="' . $filename . '.xls"');
header('Cache-Control: max-age=0');
ob_clean(); # remove this
if you want download this with 2003 and 2007 there are few changes to be done
2007 - file format xlsx
2003 - file format xls
I have made a html form where the user can enter his name/email/phone etc. and also select quantity of the listed products.
Here is the product code and I'm wondering how do I do to include in the email message I get from the form to include how many of what product the user wants.
This is the form code:
<div class="col-sm-6 col-md-6 bottom-padding">
<?php
process_si_contact_form();
if (isset($_SESSION['ctform']['error']) && $_SESSION['ctform']['error'] == true):
?>
<div class="alert alert-danger">
<strong>Oops!</strong> Something went wrong.
</div>
<?php
elseif (isset($_SESSION['ctform']['success']) && $_SESSION['ctform']['success'] == true):
?>
<div class="alert alert-success">
<strong>Message sent!</strong> We'll get in touch asap.
</div>
<?php
endif;
?>
<form class="form-box register-form contact-form" method="POST" id="contact_form">
<input type="hidden" name="do" value="contact" />
<h3 class="title">Form</h3>
<label>Name: <span class="required">*</span></label>
<?php echo #$_SESSION['ctform']['f_name_error'] ?>
<input class="form-control" type="text" name="ct_f_name" value="<?php echo htmlspecialchars(#$_SESSION['ctform']['ct_f_name']) ?>">
<label>E-mail: <span class="required">*</span></label>
<?php echo #$_SESSION['ctform']['f_email_error'] ?>
<input class="form-control" type="email" name="ct_f_email" value="<?php echo htmlspecialchars(#$_SESSION['ctform']['ct_f_email']) ?>">
<label>Phone: <span class="required">*</span></label>
<?php echo #$_SESSION['ctform']['f_tel_error'] ?>
<input class="form-control" type="text" name="ct_f_tel" value="<?php echo htmlspecialchars(#$_SESSION['ctform']['ct_f_tel']) ?>">
<div class="panel-group" id="accordion">
<div class="panel panel-info">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" class="collapsed">
Hardware
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse" style="height: 0px;">
<div class="panel-body">
<ul class="list-group checked-list-box">
<?php
$my_products = array(
'1' => 'Product 1',
'2' => 'Product 2',
'3' => 'Product 3'
);
foreach ($my_products as $key => $value) {
echo "<div class=\"col-xs-6\" style=\"margin: 10px 0 5px 0;\">";
echo "<li class=\"list-group-item\" data-style=\"button\">";
echo $value;
echo "<select class=\"form-control\" name=\"quantity[$key]>\"";
for ($i = 0; $i <= 10; $i++) echo "<option value=\"$i\">$i</option>";
echo "</select>";
echo "</li>";
echo "</div>";
}
?>
</ul>
</div>
</div>
</div>
<div class="panel panel-info">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" class="collapsed">
Software
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body">
Empty.
</div>
</div>
</div>
</div>
<label>Message: <span class="required">*</span></label>
<?php echo #$_SESSION['ctform']['message_error'] ?>
<textarea class="form-control" name="ct_message"><?php echo htmlspecialchars(#$_SESSION['ctform']['ct_message']) ?></textarea>
<div class="clearfix"></div>
<div class="buttons-box clearfix">
<input type="submit" class="btn btn-default" value="Send">
<span class="required"><b>*</b> Required fields</span>
</div>
</form>
</div>
Anything else I need to post? I don't know if this is the best way coded but it does the work. Now it won't let me save this question because it's much code included in this post so I'm writing to be able to save it lol.
EDIT: ADDING PHP FORM CODE.
<?php
function process_si_contact_form() {
$_SESSION['ctform'] = array();
if ($_SERVER['REQUEST_METHOD'] == 'POST' && #$_POST['do'] == 'contact') {
foreach($_POST as $key => $value) {
if (!is_array($key)) {
if ($key != 'ct_message') $value = strip_tags($value);
$_POST[$key] = htmlspecialchars(stripslashes(trim($value)));
}
}
$f_name = #$_POST['ct_f_name'];
$f_tel = #$_POST['ct_f_tel'];
$f_email = #$_POST['ct_f_email'];
$message = #$_POST['ct_message'];
$f_name = substr($f_name, 0, 64);
$errors = array();
if (isset($GLOBALS['DEBUG_MODE']) && $GLOBALS['DEBUG_MODE'] == false) {
if (strlen($f_name) < 3) {
$errors['f_name_error'] = 'Your name please.';
}
if (strlen($f_tel) < 10) {
$errors['f_tel_error'] = 'Your phone please.';
} else if (!preg_match('/^([-+0-9()]+)$/', $f_tel)) {
$errors['f_tel_error'] = 'Thats not a phone number!';
}
if (strlen($f_email) == 0) {
$errors['f_email_error'] = 'Your e-mail please.';
} else if (!preg_match('/^(?:[\w\d]+\.?)+#(?:(?:[\w\d]\-?)+\.)+\w{2,4}$/i', $f_email)) {
$errors['f_email_error'] = 'Thats not an e-mail!';
}
if (strlen($message) < 10) {
$errors['message_error'] = 'Your message must contain atleast 10 characters.';
}
}
if (sizeof($errors) == 0) {
$time = date('r');
$message = "<strong>Name:</strong><br /><em>$f_name</em><br />"
. "<br />"
. "<strong>E-mail:</strong><br /><em>$f_email</em><br />"
. "<br />"
. "<strong>Phone:</strong><br /><em>$f_tel</em>"
. "<br /><br /><br />"
. "<strong>Message:</strong><br />"
. "<pre>$message</pre>"
. "<br /><br />"
. "<strong>IP:</strong><br /><em>{$_SERVER['REMOTE_ADDR']}</em><br />"
. "<br />"
. "<strong>Time:</strong><br /><em>$time</em><br />"
. "<br />"
. "<strong>Browser:</strong><br /><em>{$_SERVER['HTTP_USER_AGENT']}</em>";
$message = wordwrap($message, 70);
if (isset($GLOBALS['DEBUG_MODE']) && $GLOBALS['DEBUG_MODE'] == false) {
mail($GLOBALS['ct_recipient'], $GLOBALS['ct_msg_subject'], $message, "From: {$GLOBALS['ct_recipient_no_reply']}\r\nReply-To: {$f_email}\r\nContent-type: text/html; charset=utf8\r\nMIME-Version: 1.0");
}
$_SESSION['ctform']['error'] = false;
$_SESSION['ctform']['success'] = true;
} else {
$_SESSION['ctform']['ct_f_name'] = $f_name;
$_SESSION['ctform']['ct_f_tel'] = $f_tel;
$_SESSION['ctform']['ct_f_email'] = $f_email;
$_SESSION['ctform']['ct_message'] = $message;
foreach($errors as $key => $error) {
$_SESSION['ctform'][$key] = "<span class=\"error\" style=\"float: right; color: 00ff00;\">$error</span>";
}
$_SESSION['ctform']['error'] = true;
}
}
}
$_SESSION['ctform']['success'] = false;
?>
EDIT 2: ADDING NEW PHP MAIL CODE.
<?php
function process_si_contact_form() {
$_SESSION['ctform'] = array();
if ($_SERVER['REQUEST_METHOD'] == 'POST' && #$_POST['do'] == 'contact') {
foreach($_POST as $key => $value) {
if (!is_array($key)) {
if ($key != 'ct_message') $value = strip_tags($value);
$_POST[$key] = htmlspecialchars(stripslashes(trim($value)));
}
}
$f_name = #$_POST['ct_f_name'];
$f_tel = #$_POST['ct_f_tel'];
$f_email = #$_POST['ct_f_email'];
$message = #$_POST['ct_message'];
$f_name = substr($f_name, 0, 64);
$products = array(
#$_POST['quantity[1]'],
#$_POST['quantity[2]'],
#$_POST['quantity[3]'],
#$_POST['quantity[4]'],
#$_POST['quantity[5]'],
#$_POST['quantity[6]'],
#$_POST['quantity[7]'],
#$_POST['quantity[8]'],
#$_POST['quantity[9]'],
#$_POST['quantity[10]']);
$errors = array();
if (isset($GLOBALS['DEBUG_MODE']) && $GLOBALS['DEBUG_MODE'] == false) {
if (strlen($f_name) < 3) {
$errors['f_name_error'] = 'Fyll i ditt namn';
}
if (strlen($f_tel) < 10) {
$errors['f_tel_error'] = 'Fyll i ditt tel.nr';
} else if (!preg_match('/^([-+0-9()]+)$/', $f_tel)) {
$errors['f_tel_error'] = 'Felaktigt tel.nr';
}
if (strlen($f_email) == 0) {
$errors['f_email_error'] = 'Fyll i din e-postadress';
} else if (!preg_match('/^(?:[\w\d]+\.?)+#(?:(?:[\w\d]\-?)+\.)+\w{2,4}$/i', $f_email)) {
$errors['f_email_error'] = 'Felaktig e-postadress';
}
if (strlen($message) < 10) {
$errors['message_error'] = 'Ditt meddelande måste bestå av minst 10 tecken';
}
}
if (sizeof($errors) == 0) {
$time = date('r');
$message = "<strong>Namn:</strong><br /><em>$f_name</em><br />"
. "<br />"
. "<strong>E-postadress:</strong><br /><em>$f_email</em><br />"
. "<br />"
. "<strong>Telefon:</strong><br /><em>$f_tel</em>"
. "<br /><br /><br />"
. "<strong>Meddelande:</strong><br />"
. "<pre>$message</pre>"
. "<br />"
. "<strong>IP:</strong><br /><em>{$_SERVER['REMOTE_ADDR']}</em><br />"
. "<br /><strong>".$products[1]." - Ingenico IPP350</strong>"
. "<br /><strong>".$products[2]." - Ingenico ICT250</strong>"
. "<br /><strong>".$products[3]." - Yomani</strong>"
. "<br /><strong>".$products[4]." - Ingenico IWL250 GPRS</strong>"
. "<br /><strong>".$products[5]." - PosBank® AnyShop II</strong>"
. "<br /><strong>".$products[6]." - Ingenico IWL250 Wifi</strong>"
. "<br /><strong>".$products[7]." - Ingenico IWL250 BT</strong>"
. "<br /><strong>".$products[8]." - PosBank® AnyShop e2</strong>"
. "<br /><strong>".$products[9]." - Ingenico IWL285 3G</strong>"
. "<br /><strong>".$products[10]." - Ingenico iCMP</strong>"
. "<br /><br /><strong>Tid:</strong><br /><em>$time</em><br />"
. "<br />"
. "<strong>Webbläsare:</strong><br /><em>{$_SERVER['HTTP_USER_AGENT']}</em>";
$message = wordwrap($message, 70);
if (isset($GLOBALS['DEBUG_MODE']) && $GLOBALS['DEBUG_MODE'] == false) {
mail($GLOBALS['ct_recipient'], $GLOBALS['ct_msg_subject'], $message, "From: {$GLOBALS['ct_recipient_no_reply']}\r\nReply-To: {$f_email}\r\nContent-type: text/html; charset=utf8\r\nMIME-Version: 1.0");
}
$_SESSION['ctform']['error'] = false;
$_SESSION['ctform']['success'] = true;
} else {
$_SESSION['ctform']['ct_f_name'] = $f_name;
$_SESSION['ctform']['ct_f_tel'] = $f_tel;
$_SESSION['ctform']['ct_f_email'] = $f_email;
$_SESSION['ctform']['ct_message'] = $message;
foreach($errors as $key => $error) {
$_SESSION['ctform'][$key] = "<span class=\"error\" style=\"float: right; color: 00ff00;\">$error</span>";
}
$_SESSION['ctform']['error'] = true;
}
}
}
$_SESSION['ctform']['success'] = false;
?>
The name of these elements would be: quantity[0], quantity[1], and quantity[2] which contains the value gave for each product. Notice if you want a quantity[0] you need to include that in the $my_products array. The value for Product 1 would be in quantity[1]. The information is from this code here:
$my_products = array(
'0' => 'Product 0', /* Added Product 0 */
'1' => 'Product 1',
'2' => 'Product 2'
);
foreach ($my_products as $key => $value) {
...
// $key is 0,1,2 through the loop so the name would be
// quantity[0] quantity[1], and quantity[2]
echo "<select class=\"form-control\" name=\"quantity[$key]>\"";
for ($i = 0; $i <= 10; $i++) echo "<option value=\"$i\">$i</option>";
echo "</select>";
...
}
So you would just get name in the same way you got your other POST data in your PHP form code:
$products = array(
#$_POST['quantity[0]'],
#$_POST['quantity[1]'],
#$_POST['quantity[2]'] );
Now just include those values in your $message:
$message =
/* Your normal message content here from the code */
. "<strong>Product0:</strong><br /><em>".$products[0]."</em><br />"
. "<br />"
. "<strong>Product1:</strong><br /><em>".$products[1]".</em><br />"
. "<br />"
. "<strong>Product2:</strong><br /><em>".$products[2]."</em><br />"
. "<br />";
I've got a problem with a contact form on my webpage.
When someone fills it in, i always got the error message that something isn't filled in right.
It seems to be the telephone number.
The link to the webpage is http://www.tiggelovend-kok.nl/index.php/contact/
<?php
/*
Template Name: Contact
*/
?>
<?php get_header(); ?>
<div class="wider_blog">
<div class="_blog">
<div class="topbar"><div class="row">
<?php
echo beopen_main_title();
if (beopen_get_option('show_breadcrumbs') == '2') {
echo beopen_breadcrumb();
}
?>
</div></div>
<?php
if (beopen_get_option('show_map') != 1) {
?>
<div id="map_canvas_shadow"></div>
<div id="map_canvas"></div>
<?php
}
?>
<div class="row">
<!-- Row for main content area -->
<div id="content" class="eight columns rightfade" role="main">
<div class="post-box">
<article class="contact">
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php if (beopen_get_option('show_contact_form') == 2) { ?>
<?php echo beopen_get_option('contact_form_text'); ?>
<form class="beopen-contact-form" action="<?php echo get_permalink(); ?>" method="post">
<?php
require_once(THEME_LIBRARY . '/recaptchalib.php');
$error_contact_name = '';
$error_contact_email = '';
$error_contact_phone = '';
$error_contact_company = '';
$error_contact_message = '';
$contact_name = '';
$contact_email = '';
$contact_company = '';
$contact_phone = '';
$contact_message = '';
$publickey = beopen_get_option('recaptcha_public_key');
$privatekey = beopen_get_option('recaptcha_private_key');
if (isset($_POST['beopen_form'])) {
foreach ($_POST as $key => $val) {
$GLOBALS[$key] = wp_filter_kses($val);
}
$send = 0;
if (beopen_get_option('show_recaptcha') == 2) {
$recaptcha_challenge_field = '';
if (isset($_POST["recaptcha_challenge_field"])) {
$recaptcha_challenge_field = $_POST["recaptcha_challenge_field"];
}
$recaptcha_response_field = '';
if (isset($_POST["recaptcha_response_field"])) {
$recaptcha_response_field = $_POST["recaptcha_response_field"];
}
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $recaptcha_challenge_field, $recaptcha_response_field);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
echo '<div class="alert-box alert">';
echo (__("The reCAPTCHA wasn't entered correctly. Go back and try it again.", 'beopen') .
"(" . __('reCAPTCHA said:', 'beopen') . " " . $resp->error . ")");
echo '</div>';
} else {
// Your code here to handle a successful verification
$send = 1;
}
} else {
$send = 1;
}
if (!(isset($_POST['contact_name']) && ($_POST['contact_name']) != '')) {
$error_contact_name = 'error';
$send = 2;
}
if (!(isset($_POST['contact_message']) && ($_POST['contact_message']) != '')) {
$error_contact_message = 'error';
$send = 2;
}
if ($send == 2) {
echo '<div class="alert-box alert">';
_e('U bent een veld vergeten in te vullen!', 'beopen');
echo '</div>';
} else
if ($send == 1) {
$mail_content = __('Name:', 'beopen') . PHP_EOL . $_POST['contact_name'] . PHP_EOL . PHP_EOL .
__('E-mail:', 'beopen') . PHP_EOL . $_POST['contact_email'] . PHP_EOL . PHP_EOL .
__('Company:', 'beopen') . PHP_EOL . $_POST['contact_company'] . PHP_EOL . PHP_EOL .
__('Phone:', 'beopen') . PHP_EOL . $_POST['contact_phone'] . PHP_EOL . PHP_EOL .
__('Message:', 'beopen') . PHP_EOL . $_POST['contact_message'] . PHP_EOL;
if ($_POST['contact_email'] == '') {
$mail_headers = 'From: ' . beopen_get_option('contact_email_from') . PHP_EOL .
'Reply-To: ' . beopen_get_option('contact_email_from');
} else {
$mail_headers = 'From: ' . $_POST['contact_email'] . PHP_EOL .
'Reply-To: ' . $_POST['contact_email'];
}
if (mail(beopen_get_option('contact_email_to'), beopen_get_option('contact_email_subject'), $mail_content, $mail_headers)) {
echo '<div class="alert-box success">';
_e('Bericht verzonden!', 'beopen');
echo '</div>';
} else {
echo '<div class="alert-box alert">';
_e('Voer de juiste gegevens in!', 'beopen');
echo '</div>';
}
}
}
?>
<div class="row">
<div class="six columns">
<div class="beopen-wrap author-icon <?php echo $error_contact_name; ?>">
<input type="text" name="contact_name" value="<?php echo $contact_name; ?>" placeholder="<?php _e('Uw naam', 'beopen'); ?>" />
</div>
</div>
<div class="six columns">
<div class="beopen-wrap email-icon <?php echo $error_contact_email; ?>">
<input type="text" name="contact_email" value="<?php echo $contact_email; ?>" placeholder="<?php _e('Uw e-mail', 'beopen'); ?>" />
</div>
</div>
</div>
<div class="row">
<div class="six columns">
<div class="beopen-wrap company-icon <?php echo $error_contact_company; ?>">
<input type="text" name="contact_company" value="<?php echo $contact_company; ?>" placeholder="<?php _e('Uw organisatie', 'beopen'); ?>" />
</div>
</div>
<div class="six columns">
<div class="beopen-wrap phone-icon <?php echo $error_contact_phone; ?>">
<input type="text" name="contact_phone" value="<?php echo $contact_phone; ?>" placeholder="<?php _e('Uw telefoonnummer', 'beopen'); ?>" />
</div>
</div>
</div>
<textarea name="contact_message" placeholder="<?php _e('Voer hier uw bericht in', 'beopen'); ?>" <?php if ($error_contact_message) { echo 'class="' . $error_contact_message . '"'; } ?>><?php echo $contact_message; ?></textarea>
<div id="recaptcha_div"></div>
<input type="hidden" name="beopen_form" value="1" />
<button class="button send-message" type="submit"><span class="send-message"></span><?php _e('Verzenden', 'beopen'); ?></button>
</form>
<?php } ?>
</article>
</div>
</div><!-- End Content row -->
<div class="four columns">
<div class="contact-sidebar">
<?php echo wpautop(beopen_get_option('map_address')); ?>
</div>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>