create zip from mysql to all files using php - php

hi guys i want to create a zip from the hole files names into my database in my code i can just download just one file but i want to get the hole files from my database into a zip
<html>
<title>Files | github</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.4.1/font/bootstrap-icons.css">
<link href="globe.png" rel="shortcut icon">
<?php
date_default_timezone_set("Asia/Calcutta");
//echo date_default_timezone_get();
?>
<?php
$conn=new PDO('mysql:host=localhost; dbname=github', 'root', '') or die(mysqli_error($conn));
if(isset($_POST['submit'])!=""){
$name=$_FILES['photo']['name'];
$size=$_FILES['photo']['size'];
$type=$_FILES['photo']['type'];
$temp=$_FILES['photo']['tmp_name'];
$date = date('Y-m-d H:i:s');
$caption1=$_POST['caption'];
$link=$_POST['link'];
move_uploaded_file($temp,"files/".$name);
$query=$conn->query("INSERT INTO upload (name,date) VALUES ('$name','$date')");
if($query){
header("location:index.php");
}
else{
die(mysqli_error($conn));
}
}
?>
<html>
<body>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="screen">
<link rel="stylesheet" type="text/css" href="css/DT_bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/font-awesome.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css"/>
<style>
body{
background-color:#24292f;
}
</style>
</head>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/bootstrap.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" language="javascript" src="js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" language="javascript" src="js/DT_bootstrap.js"></script>
<?php include('dbcon.php'); ?>
<style>
.table tr th{
border:#eee 1px solid;
position:relative;
#font-family:"Times New Roman", Times, serif;
font-size:12px;
text-transform:uppercase;
}
table tr td{
border:#eee 1px solid;
color:#000;
position:relative;
#font-family:"Times New Roman", Times, serif;
font-size:12px;
text-transform:uppercase;
}
#wb_Form1
{
background-color: #00BFFF;
border: 0px #000 solid;
}
#photo
{
border: 1px #A9A9A9 solid;
background-color: #00BFFF;
color: #fff;
font-family:Arial;
font-size: 20px;
}
</style>
<div class="alert alert-info">
</div>
<!--<table cellpadding="0" cellspacing="0" border="0" class="table table-bordered">
<tr><td><form enctype="multipart/form-data" action="" id="wb_Form1" name="form" method="post">
<input type="file" name="photo" id="photo" required="required"></td>
<td><input type="submit" class="btn btn-danger" value="SUBMIT" name="submit">
</form> <strong>SUBMIT HERE</strong></tr></td></table>
<div class="col-md-18">-->
<div class="container-fluid" style="margin-top:0px;">
<div class = "row">
<div class="panel panel-default">
<div class="panel-body">
<div class="table-responsive">
<form method="post" action="delete.php" >
<table cellpadding="0" cellspacing="0" border="0" class="table table-condensed" id="example">
<thead>
<tr>
<th>ID</th>
<th>FILE NAME</th>
<th>Date</th>
<th>Download</th>
<th>code editor</th>
</tr>
</thead>
<tbody>
<?php
session_start();
$user = $_SESSION["username"];
$project= $_GET['project'];
echo $project;
$query=mysqli_query($conn,"SELECT * FROM project S WHERE date=( SELECT MAX(date) FROM project WHERE pointedname = S.pointedname) and (user='$user' and directoryName ='$project')")or die(mysqli_error($conn));
while($row=mysqli_fetch_array($query)){
$id=$row['user'];
$name=$row['pointedname'];
$date=$row['date'];
$filpath=$row["path"];
?>
<tr>
<td><?php echo $row['user'] ?></td>
<td><?php echo $row['pointedname']; ?></td>
<td><?php echo $row['date'] ?></td>
<td>
<span class="glyphicon glyphicon-paperclip" style="font-size:20px; color:blue"></span>
</td>
<td>
<?php
echo "<a href='../repositories/codeEditorGit/index.php?project=".$row["path"]."'><i class='bi bi-code-slash'></i> ".$row["pointedname"]."</a>";
echo "<a href='zip.php?project=".$row["path"]."'><i class='bi bi-code-slash'></i> ".$row["pointedname"]."</a>"; ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
i tried this code but it didnt work for me
<?php
$conn=new PDO('mysql:host=localhost; dbname=github', 'root', '') or die(mysqli_error($conn));
function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
$zip = new ZipArchive();
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>\n");
}
foreach($file_names as $files)
{
$zip->addFile($file_path.$files,$files);
//echo $file_path.$files,$files."<br />";
}
$zip->close();
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
exit;
}
session_start();
$user=$_SESSION["username"];
$project = $_GET["project"];
$cqurfetch=mysql_query("SELECT * FROM project where user='$user' and accept='1'");
while($row = mysql_fetch_array($cqurfetch))
{
$file_names[] = $row['user_album_images'];
}
$archive_file_name=time().'.gallery.zip';
$file_path="/uploads/";
zipFilesAndDownload($file_names,$archive_file_name,$file_path);
echo '^^^^^^Zip ended^^^^^^';
?>
also i want to check if the user exist by email but i got an error that when i execute the code he escape the if statment and he go throw executing the insert even the email exist
if(mysqli_num_rows($check_email) > 0){
echo('Email Already exists');
}
code :
$textarea = $_POST["textarea"];
$email = $_POST["email"];
$name = $_POST["name"];
$pswd = $_POST["password"];
$check_email = mysqli_query($conn, "SELECT * FROM sign where email = '$email' ");
if(mysqli_num_rows($check_email) > 0){
echo('Email Already exists');
}
else{
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$result = $sql = "INSERT INTO sign
VALUES ('$email', '$name', '$password','$textarea');
INSERT INTO connected
VALUES ('$email', '')
";
$conn->exec($result);
header("Location: ../image-upload-php-and-mysql-main/index.php");
}
echo('Record Entered Successfully');
}

Related

Can someone explain why my MySQL table data is not being displayed?

I'm new to PHP and MySQL. I have an HTML table and form that submits the entered data to MySQL, but doesn't display the MySQL data in my HTML table. Here is an image for reference: https://i.imgur.com/OEDd6Px.png. I want the submitted data to display upon submission if possible but am unable to find a solution. Thanks in advance.
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "test";
$conn = mysqli_connect($host, $user, $pass, $db);
if (!$conn) {
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
if(isset($_POST["asin"]))
{
$asin = $_POST["asin"];
$category = $_POST["category"];
$submit = "INSERT INTO `user_input`(`id`, `asin`, `category`, `date`) VALUES (NULL, '$asin', '$category', CURRENT_DATE())";
$sql = mysqli_query($conn, $submit);
if (!$sql) {
die ('SQL Error: ' . mysqli_error($conn));
}
$display = "SELECT * FROM user_input";
$result = mysqli_query($conn, $display);
if (!$result) {
die ('SQL Error: ' . mysqli_error($conn));
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>testEnv</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<style>
form {
padding-bottom: 10px;
padding-top: 10px;
}
table, thead, tbody, th, td {
padding: 4px;
border-collapse: collapse;
border: 1px solid black;
}
form {
font-size: 13px;
}
th, td {
width: auto;
text-align: center;
font-size: 13px;
}
</style>
</head>
<body>
<div class="container-fluid">
<form id="form" method="post">
<div>
<label id="asinLabel" for="asin">ASIN:</label>
<input id="asinInput" type="text" name="asin"></input>
<label id="categoryLabel" for="category">Category:</label>
<input id="categoryInput" type="text" name="category"></input>
<input id="submit" type="submit" value="Submit"></input>
</div>
</form>
</div>
<div class="container-fluid">
<table class="container-fluid">
<thead>
<tr>
<th>ID</th>
<th>ASIN</th>
<th>Category</th>
<th>Date</th>
<th>6:00 AM</th>
<th>8:00 AM</th>
<th>10:00 AM</th>
<th>12:00 PM</th>
</tr>
</thead>
<tbody id="tableBody">
<?php
while($row = mysqli_fetch_array($result));
{
echo '<tr>
<td>'.$row['id'].'</td>
<td>'.$row['asin'].'</td>
<td>'.$row['category'].'</td>
<td>'. date('m d, Y', strtotime($row['date'])) .'</td>
<td>'.$row['6am'].'</td>
<td>'.$row['8am'].'</td>
<td>'.$row['10am'].'</td>
<td>'.$row['12pm'].'</td>
</tr>';
}
mysqli_close($conn);
?>
</tbody>
</table>
</div>
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script rel="script" type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script rel="script" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.js"></script>
<script rel="script" type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.js"></script>
</body>
</html>
Try to write
$display = "SELECT * FROM user_input";
$result = mysqli_query($conn, $display);
if (!$result) {
die ('SQL Error: ' . mysqli_error($conn));
}
block out side of the condition.

global variable doesnot work in another function why

MY dbMySql.PHP FILE CODING
<?php
define('DB_SERVER','localhost');
define('DB_USER','root');
define('DB_PASS' ,'');
define('DB_NAME', 'dbtuts');
class DB_con
{
function __construct()
{
global $conn;
$conn = mysql_connect(DB_SERVER,DB_USER,DB_PASS) or die('localhost connection problem'.mysql_error());
mysql_select_db(DB_NAME);
}
public function insert($fname,$lname,$city)
{
$sql = "INSERT users(first_name,last_name,user_city)VALUES('$fname','$lname','$city')";
$res = mysql_query($sql);
return $res;
}
public function select()
{
// $db=new DB_con();
// $db->__construct();
$sql = "SELECT * FROM users";
$res=mysql_query($sql);
// return $conn;
return $res;
}
}
?>
MY index.php FILE
<?php
include_once 'dbMySql.php';
$con = new DB_con();
$table = "users";
$res=$con->select($table);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>
<div id="header">
<div id="content">
<label></label>
</div>
</div>
<div id="body">
<div id="content">
<table align="center">
<tr>
<th colspan="3">ADD</th>
</tr>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>City</th>
</tr>
<?php
while($row=mysql_fetch_row($res))
{
?>
<tr>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<div id="footer">
<div id="content">
<hr /><br/>
<label>Appxone Private Limited</label>
</div>
</div>
</center>
</body>
</html>
MY add_data.php FILE CODING
<?php
include_once 'dbMySql.php';
$con = new DB_con();
// data insert code starts here.
if(isset($_POST['btn-save']))
{
$fname = $_POST['first_name'];
$lname = $_POST['last_name'];
$city = $_POST['city_name'];
$res=$con->insert($fname,$lname,$city);
if($res)
{
?>
<script>
alert('Record inserted...');
window.location='index.php'
</script>
<?php
}
else
{
?>
<script>
alert('error inserting record...');
window.location='index.php'
</script>
<?php
}
}
// data insert code ends here.
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP Data Insert and Select Data Using OOP - By Cleartuts</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>
<div id="header">
<div id="content">
<label>PHP Data Insert and Select Data Using OOP - By Cleartuts</label>
</div>
</div>
<div id="body">
<div id="content">
<form method="post">
<table align="center">
<tr>
<td><input type="text" name="first_name" placeholder="First Name" required /></td>
</tr>
<tr>
<td><input type="text" name="last_name" placeholder="Last Name" required /></td>
</tr>
<tr>
<td><input type="text" name="city_name" placeholder="City" required /></td>
</tr>
<tr>
<td>
<button type="submit" name="btn-save"><strong>SAVE</strong></button></td>
</tr>
</table>
</form>
</div>
</div>
</center>
</body>
</html>
MY style.css Coding is
#charset "utf-8";
/* CSS Document */
*
{
margin:0;
padding:0;
}
#header
{
width:100%;
height:50px;
background:#00a2d1;
color:#f9f9f9;
font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size:35px;
text-align:center;
}
#header a
{
color:#fff;
text-decoration:blink;
}
#body
{
margin-top:50px;
}
table
{
width:40%;
font-family:Tahoma, Geneva, sans-serif;
font-weight:bolder;
color:#999;
margin-bottom:80px;
}
table a
{
text-decoration:none;
color:#00a2d1;
}
table,td,th
{
border-collapse:collapse;
border:solid #d0d0d0 1px;
padding:20px;
}
table td input
{
width:97%;
height:35px;
border:dashed #00a2d1 1px;
padding-left:15px;
font-family:Verdana, Geneva, sans-serif;
box-shadow:0px 0px 0px rgba(1,0,0,0.2);
outline:none;
}
table td input:focus
{
box-shadow:inset 1px 1px 1px rgba(1,0,0,0.2);
outline:none;
}
table td button
{
border:solid #f9f9f9 0px;
box-shadow:1px 1px 1px rgba(1,0,0,0.2);
outline:none;
background:#00a2d1;
padding:9px 15px 9px 15px;
color:#f9f9f9;
font-family:Arial, Helvetica, sans-serif;
font-weight:bolder;
border-radius:3px;
width:100%;
}
table td button:active
{
position:relative;
top:1px;
}
#footer
{
margin-top:50px;
position:relative;
bottom:30px;
font-family:Verdana, Geneva, sans-serif;
}
all code is working and data insert successfully and show but if you see above first file i am using mysql,i want to use mysqli but issue is that when show $conn as a global variable (because mysqli needed 2 parameters) and use in mysqli($sql,$conn),error show undefined variable $conn why?
Use $this for access variables in your class
define('DB_SERVER','localhost');
define('DB_USER','root');
define('DB_PASS' ,'');
define('DB_NAME', 'dbtuts');
class DB_con {
private $conn;
function __construct() {
$this->conn = mysqli_connect(DB_SERVER,DB_USER,DB_PASS) or die('localhost connection problem'.mysql_error());
mysqli_select_db($this->conn, DB_NAME);
}
public function insert($fname,$lname,$city) {
$sql = "INSERT users(first_name,last_name,user_city)VALUES('$fname','$lname','$city')";
$res = mysqli_query($this->conn, $sql);
return $res;
}
public function select() {
// $db=new DB_con();
// $db->__construct();
$sql = "SELECT * FROM users";
$res = mysqli_query($this->conn, $sql);
// return $conn;
return $res;
}
}

Making a Table in PHP

basic question is im trying to make a table similar to this
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_caption_test
for my webpage: http://lamp.cse.fau.edu/~mcuervo5/p6/
in my php file for "name" & "votes"
by making the table for my boy table and girl table all border up and separated neatly
but it my first time using margin and padding to make the space neat & been having a lot of trial and error here & cant seem to solve the problem
tried to replace this:
$myTable = "<table>
with this:
$myTable = "<table style="margin: 5px; border: 1px; border-color: black;">
but got error code :(.
You can right click "inspect" the page or take it from here from my php code so far. Thanks guys if you can help me with this
<?php
require_once './php/db_connect.php'; // Will call this php file
?>
<!DOCTYPE html>
<html lang="en">
<head>
Just added this to make the border line
<style>
table, th, td
{
border: 2px solid black;
}</style>
End new edit
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Maundy | Comming Soon Page</title>
<meta name="description" content="Free Bootstrap Theme by BootstrapMade.com">
<meta name="keywords" content="free website templates, free bootstrap themes, free template, free bootstrap, free website template">
<link href='https://fonts.googleapis.com/css?family=Lobster|Open+Sans:400,400italic,300italic,300|Raleway:300,400,600' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/animate.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.countdown.min.js"></script>
<script src="js/wow.js"></script>
<script src="js/custom.js"></script>
<script src="contactform/contactform.js"></script>
<body>
<div class="col-lg-12">
<form method="post" action="index.php">
<label>Enter Name for Baby:</label>
<input type="text" name="baby_name" />
<label>Select Gender:</label>
<select name="gender">
<option value="B">Boy</option>
<option value="G">Girl</option>
</select>
<input type="submit" value="Sumbit!" />
</form>
</div>
<?php
if (isset($_POST['gender'])&& isset($_POST['baby_name']) )
{
$gender = $_POST['gender'];
$val_input = $_POST['baby_name'];
// Add two rows to the table
$selectStmt = 'SELECT `Votes`
FROM `Free_Names`
WHERE `Gender` = \''.$gender.'\' AND `Name` = \''.$val_input.'\';';
$result = $db->query($selectStmt); //query the "select" statement and update the result
if($result->num_rows > 0) { //if has a results
while($row = $result->fetch_assoc()) { //updates the statments
$UpdateStmt = 'UPDATE `Free_Names`
SET `Votes` = '.($row["Votes"] +1).'
WHERE `Gender` = \''.$gender.'\' AND `Name` = \''.$val_input.'\';';
$db->query($UpdateStmt); //this will run, but wont work
}
}
else
{
$insertStmt = 'INSERT INTO `Free_Names` (`Name`, `Gender`, `Votes` )' . PHP_EOL
. ' VALUES (\''.$val_input.'\',\''.$gender.'\',1);';
$db->query($insertStmt); //
}
}
?>
<?php
// Get the rows from the table, and \\ for single quote to show up
$selectStmt = 'SELECT `Name` , `Votes`
FROM `Free_Names`
WHERE `Gender` = \'B\'
ORDER BY `Votes` DESC
LIMIT 5';
?>
<div class="col-md-6">
<div class="mx-auto" style="width: 200px;">
It around here is the table for the names
BOY NAMES
</div>
<?php
$result = $db->query($selectStmt); //query the "select" statement and store the result
if($result->num_rows > 0) {
$myTable = "<table>
<thead>
<tr><th>Name</th>
<th>votes</th></tr>
</thead><tbody>";
while($row = $result->fetch_assoc()) {
$myTable.= "<tr>
<td>".$row["Name"]."</td>
<td>".$row["Votes"]."</td>
</tr>";
}
$myTable.= "</tbody></table>";
echo $myTable;
} else {
echo ' <div class="alert alert-success">No Results</div>' . PHP_EOL;
}
?>
</div>
<?php
// Get the rows from the table, and \\ for single quote to show up
$selectStmt = 'SELECT `Name` , `Votes`
FROM `Free_Names`
WHERE `Gender` = \'G\'
ORDER BY `Votes` DESC
LIMIT 5';
?>
<div class="col-md-6">
<div class="mx-auto" style="width: 200px;">
GIRL NAMES
</div>
<?php
$result = $db->query($selectStmt); //query the "select" statement and store the result
if($result->num_rows > 0) {
$myTable = " <table>
<thead>
<tr >
<th>Name</th>
<th>votes</th>
</tr>
</thead><tbody>";
while($row = $result->fetch_assoc()) {
$myTable.= "<tr>
<td>".$row["Name"]."</td>
<td>".$row["Votes"]."</td>
</tr>";
}
$myTable.= "</tbody></table>";
echo $myTable;
} else {
echo ' <div class="alert alert-success">No Results</div>' . PHP_EOL;
}
?>
</div>
</body>
</html>
I'll just use the W3Schools example. When it comes to cellpadding, add the style to <td> . When it comes to cell margins, add the style to <table> using border-spacing :
td{
padding: 12px 6px;
}
table{
border-spacing: 10px;
}
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
td{
padding: 12px 6px;
}
table{
border-spacing: 10px;
}
</style>
</head>
<body>
<table>
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
</body>
</html>

query is not running in php

Hi there i am trying to create a screen in php.
in which i select scenario and the screen displayed accordingly.
but i am stuck in a simple problem that my simple select query is not working
which is
$deptQuery = "Select * from mcb_department";
echo mysql_real_escape_string($deptQuery);
mysql_query($deptQuery) or die("adfasdf");
in same code if change the table name it just work fine, also this table is created in the db as well with the same name i have shared.
here is my complete code.
<?php
include "include/conn.php";
include "include/session.php";
if(isset($_SESSION['logged_user']) && $_SESSION['logged_user'] != '99999'){
header('location: login.php');
}
$query = mysql_query("select curdate() as todayDate");
$show = mysql_fetch_array($query);
if(isset($show)){
$todayDate= $show['todayDate'];
}
$group[] = array();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta Content="no-cache, no-store, must-revalidate" http-Equiv="Cache-Control" />
<meta Content="no-cache" http-Equiv="Pragma" />
<meta Content="0" http-Equiv="Expires" />
<link href="styles/style.css" type="text/css" rel="stylesheet" />
<link href="styles/popupstyle.css" type="text/css" rel="stylesheet" />
<link href="styles/ts.css" type="text/css" rel="stylesheet" />
<link href="styles/calendar.css" type="text/css" rel="stylesheet" />
<style>
table {
font-family: arial;
border-collapse: collapse;
width: 100%;
font-size: 11px;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 3px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body >
</body>
<select id='select_opt'>
<option> Select Assigment </option>
<option value="1"> assign quiz to all Employees </option>
<option value="2"> assign quiz to Sapcific Group </option>
<option value="3"> assign quiz to Sapcific Department </option>
<option value="4"> assign quiz to Sapcific Employee </option>
</select>
<!-- all Users -->
<div id='allUsers' style='margin-left:20px; margin-top: 20px; width: 50%; height:100px; display: none;' >
<form action="" mathod="post">
<select>
<option value=""> select Quiz</option>
</select>
<input type="submit" >
</form>
</div>
<!-- group -->
<div id='group' style='margin-left:20px; margin-top: 20px; width: 50%; height:100px; display: none;' >
<form action='group_assigment.php' mathod="post">
<table>
<tr>
<th>All <input type="checkbox"> </th>
<th>Group Name</th>
<th>Group Code</th>
</tr>
<?php
$group[] = array();
$groupQuery = "Select * from mcb_groups";
$query = mysql_query($groupQuery);
?>
<tr>
<?php if($query){
while($group = mysql_fetch_array($query)){
?>
<td><input type="checkbox" value="<?php echo $group['group_name']; ?>"></td>
<td><?php echo $group['group_name']; ?></td>
<td><?php echo $group['group_code']; ?></td>
</tr>
<?php }
} else{ echo "";} ?>
</table>
</form>
</div>
<!--
####################################
department
####################################
-->
<div id='Department' style='margin-left:20px; margin-top: 20px; width: 50%; height:100px; display: none;' >
<form action='group_assigment.php' mathod="post">
<table>
<tr>
<th>all <input type="checkbox"> </th>
<th>name</th>
<th>code</th>
<th>group</th>
</tr>
<tr>
<?php
$deptQuery = "Select * from mcb_department";
echo mysql_real_escape_string($deptQuery);
mysql_query($deptQuery);
?>
<td><input type="checkbox"></td>
<td>code</td>
<td>name</td>
<td>group</td>
</tr>
</table>
<input type="submit" >
</form>
</div>
<!--
####################################
Employee
####################################
-->
<div id='employee' style='margin-left:20px; margin-top: 20px; width: 50%; height:100px; display: none;' >
<form action="" mathod="post">
<label>employee id : </label><input type="text" >
<input type="submit" >
</form>
</div>
<script language="javascript" type="text/javascript">
var elem = document.getElementById("select_opt");
elem.onchange = function(){
console.log("yes i am running");
if( document.getElementById("select_opt").value == "1" ){
document.getElementById("allUsers").style.display = "Block";
document.getElementById("group").style.display = "none";
document.getElementById("Department").style.display = "none";
document.getElementById("employee").style.display = "none";
}
else if( document.getElementById("select_opt").value == "2" ){
document.getElementById("group").style.display = "Block";
document.getElementById("allUsers").style.display = "none";
document.getElementById("Department").style.display = "none";
document.getElementById("employee").style.display = "none";
}
else if( document.getElementById("select_opt").value == "3" ){
document.getElementById("Department").style.display = "block";
document.getElementById("group").style.display = "none";
document.getElementById("allUsers").style.display = "none";
document.getElementById("employee").style.display = "none";
}
else if( document.getElementById("select_opt").value == "4" ){
document.getElementById("employee").style.display = "block";
document.getElementById("Department").style.display = "none";
document.getElementById("group").style.display = "none";
document.getElementById("allUsers").style.display = "none";
}
else{
}
};
</script>
</
html>
regard,
Shafee jan
in same code if change the table name it just work fine
Then I would make sure you're connected to the right database. It's surprisingly common for developers to have multiple versions of their database, either on different MySQL instances or else on the same instance under a different schema name. Then they get mixed up, connecting to one database with MySQL Workbench while their app is connecting to a different database.
I would advise that you temporarily add a query to your page to run SHOW TABLES and then dump the result of that query to the log, to confirm that the mcb_department table is present in the database that your PHP script is connected to.
$deptQuery = "Select * from mcb_department";
echo mysql_real_escape_string($deptQuery);
mysql_query($deptQuery);
Where's your error checking? You need to check the return value of mysql_query() every time you run a query, so if there's a problem, you output the error message to your log. Only this way can you start to solve some of these problems.
$result = mysql_query($deptQuery);
if (!$result) {
trigger_error("Error in file " . __FILE__ . " near line " . __LINE__
. " for query $deptQuery: " . mysql_error());
die("Database error");
}
PS: The advice of some commenters that mysql_* functions are deprecated is true, but probably irrelevant to your question. Folks who focus on the API, when you have said the API is working, are just being pedantic.

PHP Pass variable to next page not working

I want to pass a variable to next page but i doesn't seem to work as expected. I have done samething on a different page but now it dosen't work.
This is the metod im using to pass the variables (email.php):
<div class='alternativ'> <td width="50%" style=" padding:5px;"> <form method='GET' action='excelimport.php'> <input type='hidden' name='pidnew3' value='$pidnew2'> <input type="submit" name="submit"> </form></td> </div>
and in excelimport.php i have this:$pidnew4 = $_POST['pidnew3'];
Im getting 2 error in excelimport.php:
Notice: Undefined index: pidnew3 in D:\home\site\wwwroot\devlopment\excelimport.php on line 77
its reffering to this: $pidnew4 = $_POST['pidnew3'];
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\home\site\wwwroot\devlopment\excelimport.php on line 102
and this is reffering to this: $recResult = mysql_fetch_array($sql);
I have this php (email.php) page that i want to pass to another.:
<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions2.php';
include_once 'includes/config.php';
error_reporting(-1); ini_set( 'display_errors', 1 );
//Start av sessions
sec_session_start();
if (login_check($mysqli) == true) {
$logged = 'Inloggad';
} else {
$logged = 'utloggad';
}
$uploadedStatus = 0;
if ( isset($_POST["submit"]) ) {
if ( isset($_FILES["file"])) {
//if there was an error uploading the file
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else {
if (file_exists($_FILES["file"]["name"])) {
unlink($_FILES["file"]["name"]);
}
$storagename = "discussdesk.xlsx";
move_uploaded_file($_FILES["file"]["tmp_name"], $storagename);
$uploadedStatus = 1;
}
} else {
echo "Ingen fil vald <br />";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Kandidater</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=0.709">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- jQuery library -->
<script src="js/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="main.css">
<link rel="shortcut icon" href="logo/wfmini.png">
<script type="text/javascript" language="javascript">
function checkedbox(element) {
var checkboxes = document.getElementsByTagName('input');
if (element.checked) {
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].type == 'checkbox') {
checkboxes[i].checked = true;
}
}
} else {
for (var i = 0; i < checkboxes.length; i++) {
console.log(i)
if (checkboxes[i].type == 'checkbox') {
checkboxes[i].checked = false;
}
}
}
}
</script>
<script src="js/tinymce/js/tinymce/tinymce.min.js"></script>
<script>tinymce.init({selector:'textarea'});</script>
</head>
<body class="dashboardadmin">
<ss="container-fluid" style="width:50%;">
<br>
<center><h3>Skicka email till kandidater</h3></center>
<br>
<p>Välj kandidater</p>
<form method="post" action="">
<?php
$pidnew2 = $_GET['pidnew'];
// Retrieve Email from Database
$getemail = mysql_query("SELECT * FROM Email_Users WHERE pid='".$pidnew2."'");
if (!$getemail) die('MySQL Error: ' . mysql_error());
echo '<table class="table table-bordered">';
echo "<thead>
<tr>
<th><input type='checkbox' onchange='checkedbox(this)' name='chk'/></th>
<th>Förnamn</th>
<th>Efternamn</th>
<th>Email</th>
</tr>
</thead>";
if (mysql_num_rows($getemail) == 0) {
echo "<tbody><tr><td colspan='3'>No Data Avaialble</td></tr></tbody>";
}
while ($row = mysql_fetch_assoc($getemail)) {
echo "<tbody><tr><td><input value='".$row['Email']."' type='checkbox' name='check[]'/></td>";
echo "<td >".$row['fornamn']."</td>";
echo "<td >".$row['efternamn']."</td>";
echo "<td >".$row['Email']."</td></tr></tbody>";
}
echo "</table>";
?>
</form>
</center>
<br>
</div>
<table width="600" style="margin:115px auto; background:#f8f8f8; border:1px solid #eee; padding:10px;">
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" enctype="multipart/form-data">
<tr><td colspan="2" style="font:bold 15px arial; text-align:center; padding:0 0 5px 0;">Ladda upp kandidater</td></tr>
<tr>
<td width="50%" style="font:bold 12px tahoma, arial, sans-serif; text-align:right; border-bottom:1px solid #eee; padding:5px 10px 5px 0px; border-right:1px solid #eee;">Välj fil</td>
<td width="50%" style="border-bottom:1px solid #eee; padding:5px;"><input type="file" name="file" id="file" /></td>
</tr>
<tr>
<td style="font:bold 12px tahoma, arial, sans-serif; text-align:right; padding:5px 10px 5px 0px; border-right:1px solid #eee;">Send</td>
<div class='alternativ'>
<td width="50%" style=" padding:5px;">
<form method='GET' action='excelimport.php'>
<input type='hidden' name='pidnew3' value='$pidnew2'>
<input type="submit" name="submit">
</form></td>
</div>
</tr>
</table>
<?php if($uploadedStatus==1){
header('Location: excelimport.php');
}?>
</form>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-38304687-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>
And here's the other one (excelimport.php):
<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions2.php';
include_once 'includes/config.php';
error_reporting(-1); ini_set( 'display_errors', 1 );
//Start av sessions
sec_session_start();
if (login_check($mysqli) == true) {
$logged = 'Inloggad';
} else {
$logged = 'utloggad';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="main.css">
<link rel="shortcut icon" href="logo/wfmini.png">
</head>
<body class="dashboardadmin">
<div class="innehall">
</div>
<p>
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
include 'PHPExcel/IOFactory.php';
$pidnew4 = $_POST['pidnew3'];
$inputFileName = 'discussdesk.xlsx';
try {
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} catch(Exception $e) {
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}
$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
$arrayCount = count($allDataInSheet); // Here get total count of row in that Excel sheet
for($i=2;$i<=$arrayCount;$i++){
$userfName = trim($allDataInSheet[$i]["A"]);
$usereName = trim($allDataInSheet[$i]["B"]);
$userMobile = trim($allDataInSheet[$i]["C"]);
$query = "SELECT name FROM Email_Users WHERE fornamn = '".$userfName."' and efternamn '".$usereName."' and email = '".$userMobile."' and pid = '".$pidnew4."'";
$sql = mysql_query($query);
$recResult = mysql_fetch_array($sql);
$existName = $recResult["fornamn"];
if($existName=="") {
$insertTable= mysql_query("insert into Email_Users (fornamn, efternamn, email, pid) values('".$userfName."', '".$usereName."', '".$userMobile."', '".$pidnew4."');");
$msg = 'Record has been added. <div style="Padding:20px 0 0 0;">Go Back to tutorial</div>';
} else {
$msg = 'Record already exist. <div style="Padding:20px 0 0 0;">Go Back to tutorial</div>';
}
}
echo "<div style='font: bold 18px arial,verdana;padding: 45px 0 0 500px;'>".$msg."</div>";
?>
</body>
</html>
<form method='GET' action='excelimport.php'>
<input type='hidden' name='pidnew3' value='$pidnew2'>
<input type="submit" name="submit">
</form>
In this form, you mentioned GET method and you are passing variable using GET method in your another page.
You can not get pidnew3 variable to another page because you are using POST method to get pidnew3 variable.
You just need to change the below line from
$pidnew4 = $_POST['pidnew3'];
to
$pidnew4 = $_GET['pidnew3'];
I just realised what can be wrong, you didn't display the $pidnew2 value here
<form method='GET' action='excelimport.php'>
<input type='hidden' name='pidnew3' value='$pidnew2'>
<input type="submit" name="submit">
</form>
You should replace that block with
<form method='GET' action='excelimport.php'>
<input type='hidden' name='pidnew3' value='<?php echo $pidnew2; ?>'>
<input type="submit" name="submit">
</form>
Then you get the value of the variable $pidnew2 and not the string '$pidnew2'
You should change the method in the form by POST, as you are trying to get a variable passed through 'GET'. Or as below you can get the variable using the 'GET' method.
$pidnew4 = $_GET['pidnew3'];

Categories