Making a Table in PHP - 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>

Related

create zip from mysql to all files using 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');
}

The datatable can't display the searching and sorting, may I know why?

The datatable cant display the searching and sorting, may I know why?
The problem is, the searching, sorting didn't display. But when I use HTML code 100% then it will display, but when I use data that fetch from MySQL, it didn't display the searching and sorting but it displays the table. I'm new to this and still a student. This is where the js and css link I take
datatable
Table for datatype:
<!DOCTYPE html>
<html lang="en">
<head>
<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="">
<meta name="author" content="">
<title>Content filter for IHSR</title>
<!--Link from datatable for sort,paging,search-->
<link href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
</head>
<body >
<?php
include('connection.php');
// select column from table ihsr_facebook_content
$query = "SELECT * FROM customer ORDER BY Customer_Name ASC";//later change to DESC
// get results from database
$result = mysqli_query($connect, $query);
// display data in table
if(mysqli_num_rows($result)>0)
{
$output = '<div>
<table id="example" class="display" style="width:100%">
<thead class="table-dark">
<tr>
<th style="padding-left: 10px; padding-right: 20px;" >No.</th>
<th style="padding-left: 10px; padding-right: 20px;" colspan="2">Name</th>
<th style="padding-left: 10px; padding-right: 20px;" >Email</th>
<th style="padding-left: 10px; padding-right: 20px;" >Contact</th>
<th style="padding-left: 10px; padding-right: 20px;" >Address</th>
<th width="7%">Edit</th>
<th width="9%">Delete</th>
</tr>
</thead>
<tbody>';
$num = mysqli_num_rows($result);
$count= 1 ;
// loop through results of database query, displaying them in the table
while($row = mysqli_fetch_array( $result )) {
$Customer_ID = $row['Customer_Id'];
$Customer_Name = $row['Customer_Name'];
$Customer_Email = $row['Customer_Email'];
$Customer_Contact = $row['Customer_Contact'];
$Customer_Address = $row['Customer_Address'];
// echo out the contents of each row into a table
$output.='<tr>
<td>'.$count.'</td>
<td colspan="2">'.$Customer_Name.'</td>
<td>'.$Customer_Email.'</td>
<td>'.$Customer_Contact.'</td>
<td>'.$Customer_Address.'</td>
<td><a class="btn-1" href="product_edit.php?GetEdit='.$Customer_ID.'" id="myBtn">Edit</a></td>
<td><button type="button" class="delButton btn-1" data-toggle="modal" id="'.$Customer_ID.'" data-target="#myModal" >Delete</button></td>
</tr>';
$count++;
}
}
// close table>
echo $output.'</tbody></table></div>';
?>
<script>
$(document).ready(function() {
$('#example').DataTable();
} );
</script>
</body>
</html>
Error message:
jquery error jquery-3.5.1.js:4046 jQuery.Deferred exception: Cannot set properties of undefined (setting '_DT_CellIndex') TypeError: Cannot set properties of undefined (setting '_DT_CellIndex')

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.

display value from php table when clicking on a button on another page

Following is the table i created for displaying the Restaurant Name, Location and Menu for table owners.
Now each of the row for the column Menu have Button as values.
My table is ready with perfect values.
NOW MY PROBLEM IS HOW TO DO:-
Upon clicking the button corresponding to the each Restaurant, a new File(openmenu.php) will open and will echo the Restaurant Name, Mobile Number of that Restaurant and the menu.
But so far, on clicking every Button ,I can only display above entries of the Last row of the table. Help Me Out. I am new to php.
table.php
<?php
include 'nav.php';
$sql = 'SELECT * FROM owners';
$query = mysqli_query($con, $sql);
if (!$query) {
die ('SQL Error: ' . mysqli_error($con));
}
?>
<html>
<head>
<link rel = "stylesheet" type = "text/css" href = "css/style.css">
<style>
.data-table{
width: 1024px;
margin-left: 150px;
text-align:center;
border: 1px solid firebrick;
background-color: white;
}
td,th{
border: 1px solid firebrick; padding: 3px 2px 1px 1px;
}
</style>
</head>
<body>
<div class="container">
<article>
<table class="data-table">
<thead>
<tr>
<th>Restuarant Name</th>
<th>Location</th>
<th>Menu</th>
</tr>
<tr>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_array($query)){
$_SESSION['resphone'] = $row['resphone'];
$_SESSION['restaur'] = $row['restaur'];
echo '<tr>
<td>'.$row['restaur'].'</td>
<td>'.$row['loc'].'</td>
<td style="background-color:firebrick;"><form method="post" action="openmenu.php?id=$row[restaur]"><input value="<?php echo $restaur;?>" type="hidden">
<input type="submit" value="View"></form></td>
</tr>';
}
?>
</tbody>
</table>
</form>
</article>
</div>
</body>
</html>
openmenu.php
<?php
include('nav.php');
?>
<html>
<head>
<link rel="stylesheet" href="css/style.css">
<style>
table, td {
border: none;
text-align: center;
text-align-last: center;
}
</style>
</head>
<body>
<div class="container">
<article>
<form method="get" align="center" action="" class="formwrap" enctype='multipart/form-data'>
<h1><?php $restaur = $_SESSION['restaur'];
echo $restaur ;?></h1>
<h1>Call to Order:</h1>
<?php $resphone = $_SESSION['resphone'];
echo $resphone;
?>
<br>
<br>
<?php
$sql = "select img from owners where restaur ='$restaur'";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($result);
$image_src2 = "upload/".$row['img'];
?>
<img src='<?php echo $image_src2; ?>' >
</form>
</article>
</div>
</body>
</html>
Issue 1
In this snippet you are setting the session variables resphone and restaur to the values of the store you are currently iterating over. Over and over again. That's why you're only ever getting the last store's information - it's the last things you set those variables to.
while ($row = mysqli_fetch_array($query)){
$_SESSION['resphone'] = $row['resphone'];
$_SESSION['restaur'] = $row['restaur'];
Issue 2
You should probably change the form method to get and discard the unused hidden input like so:
<form method="post" action="openmenu.php?id=<?=$row['restaur']?>">
<input type="submit" value="View">
</form>
Or more likely just change it a plain old a link:
View
Issue 3
You're completely ignoring store id requested in openmenu.php. You are using $_SESSION where you should be using $_REQUEST or $_GET. I'm not going to give an example of how you should do that. Instead, please refer to this answer before moving any further.
first you getting data from database & then use view button for openmenu.php but why u use this way
<form method="post" action="openmenu.php?id=$row[restaur]"><input value="<?php echo $restaur;?>" type="hidden"><input type="submit" value="View"></form>

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.

Categories