When I log into the site I come over to blabla.com/login/
HTML:
<?php
if(isset($_POST["login"]))
{
$logind = $mebe->logind();
}
?>
<form action="<?php $_SERVER['PHP_SELF'];?>" method="post">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>Brugernavn</td>
<td><input type="text" name="brugernavn" maxlength="300"></td>
</tr>
<tr>
<td>Adgangskode</td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="login" value="Log ind"></td>
</tr>
</table>
</form>
PHP: (login function is here:)
function logind()
{
if($_POST["brugernavn"] == "")
{
$error = 1;
}
if($_POST["pass"] == "")
{
$error = 1;
}
if($error != 1)
{
if ($stmt = $this->mysqli->prepare("SELECT id, brugernavn, rank, ranknavn FROM bruger WHERE brugernavn = ? AND adgangskode = ?"))
{
$stmt->bind_param('ss', $brugernavn, $adgangskode);
$brugernavn = $_POST["brugernavn"];
$adgangskode = sha1($_POST["pass"]);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id, $brugernavn, $rank, $ranknavn);
$stmt->fetch();
$count = $stmt->num_rows;
$stmt->close();
if($count > 0)
{
$_SESSION["logged_in"] = true;
$_SESSION["id"] = $id;
$_SESSION["brugernavn"] = $brugernavn;
$_SESSION["rank"] = $rank;
$_SESSION["ranknavn"] = $ranknavn;
if($_SESSION["logged_in"] == true and $_SESSION["rank"] >= 1)
{
?>
<script language="javascript" type="text/javascript">
window.location.href = "/wall/";
</script>
<?php
}
else
{
echo "Fejl..";
}
}
else
{
?>
<div class="alert error fade in">
<p>Forkert Brugernavn / Password.</p>
<a class="close" data-dismiss="alert" href="#" aria-hidden="true"><i class="fa fa-times-circle"></i></a>
</div>
<?php
}
}
//fejl
else
{
echo 'Der opstod en fejl i erklæringen: ' . $this->mysqli->error;
}
}
else
{
?>
<div class="alert error fade in">
<p>Forkert, Prøv igen!</p>
<a class="close" data-dismiss="alert" href="#" aria-hidden="true"><i class="fa fa-times-circle"></i></a>
</div>
<?php
}
}
If I use header('Location: /wall/'); then it will be just on the login page and did not show that one is log into the site in some way.
EIDT
it close site - only for users;
<?php
session_start();
include("phpFiler/fun.php");
$mebe = new mebe;
$db = $mebe->db_c();
error_reporting(E_ERROR);
if($_SESSION["logged_in"] == true)
{
?>
and open for alle users
<?php
session_start();
include("phpFiler/fun.php");
$mebe = new mebe;
$db = $mebe->db_c();
error_reporting(E_ERROR);
?>
Related
I want to update checked values in MySQL with PHP
<?php
require "../../../../config.php";
if (isset($_POST['btn-upload'])) {
try {
$connection = new PDO($dsn, $username, $password, $options);
$status = $_POST['status'];
$ck_id = $_POST['ck_id'];
for ($i = 0; $i < sizeof($ck_id); $i++) {
$sql = "UPDATE form_eg208 SET status=:status where ck_id IN (:ck_id)";
$statement = $connection->prepare($sql);
$statement->bindParam(':status', $status[$i]);
$statement->bindParam(':ck_id', $ck_id[$i]);
$statement->execute();
}
} catch (PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
if ($statement->rowcount() >= 0) {
echo '<div class="alert alert-success alert-dismissible" id="flash-
msg">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×
</a>
<h4> <strong>Success!</strong> Insert Record
Successfully</h4>
</div>';
} else {
echo '<div class="alert alert-danger alert-dismissible" id="flash-
msg">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×
</a>
<h4> <strong>Failed!</strong> Duplicate BGLPARTNO</h4>
</div>';
}
}
?>
my html code is
<?php
$id = $_REQUEST['cid'];
try {
$connection = new PDO($dsn, $username, $password, $options);
$j = 1;
$sql = "CALL view_eg208 (:bglpartno)";
$statement = $connection->prepare($sql);
$statement->bindParam(':bglpartno', $id);
$statement->execute();
$result = $statement->fetchAll();
} catch (PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
foreach ($result as $row1)
?>
<div class="container-fluid">
<div class="row">
<div class="col-md-12" style="margin-top:40px;">
<div class="card">
<div class="card-body">
<form method="post" action="" enctype='multipart/form-data' class="needs-validation" novalidate>
<div class="table-responsive m-t-40">
<table id="myTable" class="table table-hover table-bordered">
<thead class="thead-dark">
<tr>
<th>No.</th>
<th>Activity</th>
<th style="text-align:center;">Status</th>
</tr>
</thead>
<tbody>
<?php
if ($result && $statement->rowCount() > 0) {
foreach ($result as $row) { ?>
<tr>
<td>
<input type="checkbox" id="ck_id[]" class="filled-in chk-col-blue"
name="ck_id[]" value="<?php echo escape($row["ck_id"]); ?>"/>
</td>
<td style="color:black"><?php echo escape
($row["activity_name"]); ?></td>
<td>
<div class="form-group has-danger"
style="margin-bottom: 0;">
<input type="text" id="status[]" name="status[]" maxlength="100" class="form-control" value="<?php echo escape($row["status"]);?>" autocomplete="off" required="required">
<div class="invalid-feedback">
Please provide a Inputs.
</div>
</div>
</td>
</tr>
<?php }
}
$connection = null;
?>
</tbody>
</table>
When I update all the values then it works correctly but when single value then it updates the value of first box into that box which I selected. Please help me to solve this
Please make your checkbox input like this so you get the right status for the right ck_id index :
if ($result && $statement->rowCount() > 0) {
foreach ($result as $i => $row) { ?>
<tr>
<td>
<input type="checkbox" id="ck_id[]"class="filled-in chk-col-blue"
name="ck_id[<?php echo $i ?>]" value="<?php echo escape ($row["ck_id"]);?>"/>
</td>
<td style="color:black"><?php echo escape
($row["activity_name"]);?></td>
<td>
<div class="form-group has-danger"
style="margin-bottom: 0;">
<input type="text" id="status[]" name="status[<?php echo $i ?>]"
maxlength="100" class="form-control" value="<?
php echo escape ($row["status"]);?>" autocomplete="off"
required="required" >
<div class="invalid-feedback">
Please provide a Inputs.
</div>
</div>
</td>
</tr>
<?php
}
}
Also try to use foreach instead of for loops :
try {
$connection = new PDO($dsn, $username, $password, $options);
$status = $_POST['status'];
$ck_id = $_POST['ck_id'];
// for ($i = 0; $i < sizeof($ck_id); $i++) {
foreach ($ck_id as $i => $value) {
$sql = "UPDATE form_eg208 SET status=:status where ck_id IN (:ck_id)";
$statement = $connection->prepare($sql);
$statement->bindParam(':status', $status[$i]);
$statement->bindParam(':ck_id', $ck_id[$i]);
$statement->execute();
}
} catch (PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
I am trying to get the course attempt details where user attempted 2 times, so whenever I try to show 2 results its showing 2 results are same.
For example in first attempt if i failed and second attempt if i passed it showing 2 records data are passed only I don't know why it is happening like that.
Here is my code for that page:
<?php
global $DB, $USER, $CFG;
include("include/header.php");
date_default_timezone_set('Asia/Kolkata');
?>
<body>
<div style="
margin: 50px 30px 5px 0px;
float: right;
">
<?php
if ($_SESSION['idnumber'] == 3) {
?>
<button type="submit" name="linkcourses" value="linkcourses" class="btn btn-primary">Link Exam</button>
<button type="submit" name="accesscode" value="accesscode" class="btn btn-primary">Access Code</button>
<button type="submit" name="accesscode" value="accesscode" class="btn btn-primary">Create Single User</button>
<button data-toggle="modal" data-target="#contact_dialog" type="submit" name="accesscode" value="accesscode" class="btn btn-primary" style="cursor: pointer;">Max No. of Users</button>
<button data-toggle="modal" data-target="#bulk_upload" type="submit" name="accesscode" value="accesscode" class="btn btn-primary" style="cursor: pointer;">Bulk User Upload</button>
<button type="submit" name="accesscode" value="accesscode" class="btn btn-primary">Report</button>
<button type="submit" name="accesscode" value="accesscode" class="btn btn-primary">Groups</button>
<?php
}
if ($_SESSION['idnumber'] == 2) {
?>
<button type="submit" name="accesscode" value="accesscode" class="btn btn-primary">Report</button>
<?php
}
?>
</div>
<div class="container-fluid"style="background: #dddadd">
<div style="
margin: 50px 15px 5px 0px;
float: right;
">
<?php
if ($_SESSION['idnumber'] == 3) {
?>
<?php
}
?>
</div>
<div class="row" style=" margin-top: 20px;">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body" id="report_grid">
<div class="table-responsive" style="font-family: myFirstFont;">
<table id="datatable2" class="table">
<thead>
<tr>
<th style="color: #005EB8">Course</th>
<th style="color: #005EB8">Username</th>
<th style="color: #005EB8">First Name</th>
<th style="color: #005EB8">Last Name</th>
<th style="color: #005EB8">Total Time</th>
<th style="color: #005EB8">Start Date</th>
<th style="color: #005EB8">Completion Date</th>
<th style="color: #005EB8">Attempt</th>
<th style="color: #005EB8">Status</th>
<th style="color: #005EB8">Exam score</th>
</tr>
</thead>
<tbody>
<?php
require_once($CFG->dirroot . '/mod/scorm/lib.php');
require_once($CFG->dirroot . '/mod/scorm/locallib.php');
require_once($CFG->dirroot . '/course/lib.php');
global $DB;
//course table fetch
$sql1 = "SELECT cm.id as cmid,c.id,c.fullname,c.startdate,c.startdate,instance FROM {course} c LEFT JOIN {course_modules} cm ON c.id=cm.course where c.category != 0 and requested='0' AND cm.id!=''";
$courses = $DB->get_records_sql($sql1);
if (sizeof($courses)) {
foreach ($courses as $row) {
$scorm = $DB->get_record("scorm", array("id" => $row->instance));
$scoid = 0;
$orgidentifier = '';
if ($sco = scorm_get_sco($scorm->launch, SCO_ONLY)) {
if (($sco->organization == '') && ($sco->launch == '')) {
$orgidentifier = $sco->identifier;
} else {
$orgidentifier = $sco->organization;
}
$scoid = $sco->id;
}
$cmid = $row->cmid;
$coursename = $row->fullname;
$useridQry = '';
$userIds = '';
$login_id = $_SESSION['USER']->id;
if ($_SESSION['idnumber'] == 3) {
} elseif ($_SESSION['idnumber'] == 2) {
$records = $DB->get_records_sql("select * from {user} where maildigest=$login_id");
if (count($records)) {
foreach ($records as $row) {
$userIds[] = "'" . $row->id . "'";
}
if ($userIds != '') {
$userIds = implode(',', $userIds);
$useridQry = " and st.userid IN ($userIds)";
}
}
} else {
$useridQry = "and st.userid = $login_id";
}
$scom_id = $row->cmid;
$cm = get_coursemodule_from_id('scorm', $scom_id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST);
$query = "SELECT DISTINCT CONCAT(u.id, '#', COALESCE(st.attempt,0)) AS uniqueid, st.scormid AS scormid,st.value, st.attempt AS attempt, u.id AS userid,u.picture,u.firstname,u.lastname,u.username,u.firstnamephonetic,u.lastnamephonetic,u.middlename,u.alternatename,u.imagealt,u.email,u.idnumber FROM mdl_user u LEFT JOIN mdl_scorm_scoes_track st ON st.userid = u.id AND st.scormid = $scorm->id WHERE (st.userid IS NOT NULL) and idnumber != 0 $useridQry";
$attempts = 0;
$attempts = $DB->get_records_sql($query);
//print_r($attempts);
$row = array();
if (isset($attempts)) {
foreach ($attempts as $scouser) {
//print_r($scouser);
$type = '';
$status = '';
$totaltime = '';
$score = '';
if (!empty($scouser->attempt)) {
$timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $scouser->attempt);
} else {
$timetracks = '';
}
//echo $timetracks;
global $DB;
$tracks = $DB->get_records_sql("SELECT id, element, value FROM {scorm_scoes_track} WHERE scormid = ? AND userid = ? AND element IN('cmi.core.lesson_status','cmi.core.total_time','cmi.core.score.raw')", array($scorm->id, $scouser->userid));
foreach ($tracks as $trac) {
if ($trac->element == 'cmi.core.lesson_status') {
$status = $trac->value;
}
if ($trac->element == 'cmi.core.total_time') {
$totaltime = $trac->value;
}
if ($trac->element == 'cmi.core.score.raw') {
$score = $trac->value;
}
$scouser->times = $timetracks;
$scouser->status = $status;
$scouser->totaltime = $totaltime;
$scouser->score = $score;
$row[] = $scouser;
$start_date = $finish_date = '';
if (isset($scouser->times)) {
if (isset($scouser->times->start))
$start_date = date('Y-M-d H-i-s', $scouser->times->start);
if (isset($scouser->times->finish))
$finish_date = date('Y-M-d H-i-s', $scouser->times->finish);
}
} //foreach score track ends
?>
<tr class="gradeX">
<td ><?php echo $coursename; ?></td>
<td ><?php echo $scouser->username; ?></td>
<td ><?php echo $scouser->firstname; ?></td>
<td ><?php echo $scouser->lastname; ?></td>
<td ><?php echo $totaltime; ?></td>
<td ><?php echo $start_date; ?></td>
<td ><?php echo $finish_date; ?></td>
<td ><?php echo $scouser->attempt; ?></td>
<td>
<?php
//print_r($tracks);
//echo $status;
if (trim($status) == "completed") {
echo " Completed";
} elseif (trim($status) == "incomplete") {
echo "Incomplete";
} elseif (trim($status) == "failed") {
echo "Failed";
} elseif (trim($status) == "passed") {
echo "Passed";
} else {
echo "Not Started";
}
?>
</td>
<td>
<?php
if ($score == "") {
} else {
echo $score;
echo '%';
}
//echo $score;
?>
</td>
</tr>
<?php
} //foreach 104 ends
}//attempts if ends
} //course foreach ends
}//course if ends
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</body>
<?php
include("include/footer.php");
?>
</html>
I've created a database with two tables. I connected this database with a PHP page for a small CRUD app.
To execute the CRUD operations, I've created a crud.class.php that hold all operations.
Operations on the first table (membri) work but into the second (articoli) they fail, in the update articoli page.
Simply, I've create the same PHP function for the first table for the second, but it send me back this error:
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
Here are my crud.class.php and edi_articoli.php page:
Class.crud.php:
class crud
{
private $db;
function __construct($DB_con)
{
$this->db = $DB_con;
}
/***************************************** Crea Articoli******************************/
public function crea_articolo($data,$autore,$titolo)
{
try
{
$stmt = $this->db->prepare("INSERT INTO articoli(data,autore,titolo) VALUES(:data, :autore, :titolo)");
$stmt->bindparam(":data",$data);
$stmt->bindparam(":autore",$autore);
$stmt->bindparam(":titolo",$titolo);
$stmt->execute();
return true;
}
catch(PDOException $e)
{
echo $e->getMessage();
return false;
}
}
/***************************************** Update Articolo******************************/
public function getID_articoli($id)
{
$stmt = $this->db->prepare("SELECT * FROM articoli WHERE id=:id");
$stmt->execute(array(":id"=>$id));
$editRow=$stmt->fetch(PDO::FETCH_ASSOC);
return $editRow;
}
public function update_articoli($id,$data,$autore,$titolo)
{
try
{
$stmt=$this->db->prepare("UPDATE articoli SET data=:data,
autore=:autore,
titolo:titolo,
WHERE id=:id ");
$stmt->bindparam(":data",$data);
$stmt->bindparam(":autore",$autore);
$stmt->bindparam(":titolo",$titolo);
$stmt->bindparam(":id",$id);
$stmt->execute();
return true;
}
catch(PDOException $e)
{
echo $e->getMessage();
return false;
}
}
/***************************************** End Crea e aggiungi Articoli******************************/
/***************************************** Articoli******************************/
public function articoliview($query)
{
$stmt = $this->db->prepare($query);
$stmt->execute();
if($stmt->rowCount()>0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php print($row['id']); ?></td>
<td><?php print($row['data']); ?></td>
<td><?php print($row['autore']); ?></td>
<td class="setWidth concat"><div><?php print($row['titolo']); ?></div></td>
<td align="center">
<i class="glyphicon glyphicon-eye-open"></i>
</td>
<td align="center">
<i class="glyphicon glyphicon-edit"></i>
</td>
<td align="center">
<i class="glyphicon glyphicon-remove-circle"></i>
</td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td>Non c'è nulla qui...</td>
</tr>
<?php
}
}
/***************************************** End Articoli******************************/
/***************************************** CREAZIONE UTENTI******************************/
/****************************************************************************************/
public function create($nome,$cognome,$brev_descr,$descrizione)
{
try
{
$stmt = $this->db->prepare("INSERT INTO membri(nome,cognome,brev_descr,descrizione) VALUES(:nome, :cognome, :brev_descr, :descrizione)");
$stmt->bindparam(":nome",$nome);
$stmt->bindparam(":cognome",$cognome);
$stmt->bindparam(":brev_descr",$brev_descr);
$stmt->bindparam(":descrizione",$descrizione);
$stmt->execute();
return true;
}
catch(PDOException $e)
{
echo $e->getMessage();
return false;
}
}
public function getID($id)
{
$stmt = $this->db->prepare("SELECT * FROM membri WHERE id=:id");
$stmt->execute(array(":id"=>$id));
$editRow=$stmt->fetch(PDO::FETCH_ASSOC);
return $editRow;
}
/***************************************** END CREAZIONE UTENTI******************************/
/***************************************** UPDATE UTENTI ******************************/
public function update($id,$nome,$cognome,$brev_descr,$descrizione)
{
try
{
$stmt=$this->db->prepare("UPDATE membri SET nome=:nome,
cognome=:cognome,
brev_descr=:brev_descr,
descrizione=:descrizione
WHERE id=:id ");
$stmt->bindparam(":nome",$nome);
$stmt->bindparam(":cognome",$cognome);
$stmt->bindparam(":brev_descr",$brev_descr);
$stmt->bindparam(":descrizione",$descrizione);
$stmt->bindparam(":id",$id);
$stmt->execute();
return true;
}
catch(PDOException $e)
{
echo $e->getMessage();
return false;
}
}
/***************************************** END UPDATE UTENTI ******************************/
/***************************************** DELETE UTENTI******************************/
public function delete($id)
{
$stmt = $this->db->prepare("DELETE FROM membri WHERE id=:id");
$stmt->bindparam(":id",$id);
$stmt->execute();
return true;
}
/***************************************** END DELETE UTENTI******************************/
/***************************************** VIEW UTENTI ******************************/
public function dataview($query)
{
$stmt = $this->db->prepare($query);
$stmt->execute();
if($stmt->rowCount()>0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php print($row['id']); ?></td>
<td><?php print($row['nome']); ?></td>
<td><?php print($row['cognome']); ?></td>
<td class="setWidth concat"><div><?php print($row['brev_descr']); ?></div></td>
<td align="center">
<i class="glyphicon glyphicon-eye-open"></i>
</td>
<td align="center">
<i class="glyphicon glyphicon-edit"></i>
</td>
<td align="center">
<i class="glyphicon glyphicon-remove-circle"></i>
</td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td>Non c'è nulla qui...</td>
</tr>
<?php
}
}
/***************************************** END VIEW UTENTI ******************************/
/***************************************** Paging ******************************/
public function paging($query,$records_per_page)
{
$starting_position=0;
if(isset($_GET["page_no"]))
{
$starting_position=($_GET["page_no"]-1)*$records_per_page;
}
$query2=$query." limit $starting_position,$records_per_page";
return $query2;
}
public function paginglink($query,$records_per_page)
{
$self = $_SERVER['PHP_SELF'];
$stmt = $this->db->prepare($query);
$stmt->execute();
$total_no_of_records = $stmt->rowCount();
if($total_no_of_records > 0)
{
?><ul class="pagination"><?php
$total_no_of_pages=ceil($total_no_of_records/$records_per_page);
$current_page=1;
if(isset($_GET["page_no"]))
{
$current_page=$_GET["page_no"];
}
if($current_page!=1)
{
$previous =$current_page-1;
echo "<li><a href='".$self."?page_no=1'>Primo</a></li>";
echo "<li><a href='".$self."?page_no=".$previous."'>Precedente</a></li>";
}
for($i=1;$i<=$total_no_of_pages;$i++)
{
if($i==$current_page)
{
echo "<li><a href='".$self."?page_no=".$i."' style='color:red;'>".$i."</a></li>";
}
else
{
echo "<li><a href='".$self."?page_no=".$i."'>".$i."</a></li>";
}
}
if($current_page!=$total_no_of_pages)
{
$next=$current_page+1;
echo "<li><a href='".$self."?page_no=".$next."'>Prossimo</a></li>";
echo "<li><a href='".$self."?page_no=".$total_no_of_pages."'>Ultimo</a></li>";
}
?></ul><?php
}
}
/* paging */
}
Here my "update_articoli.php" page:
<?php
include_once 'dbconfig.php';
if(isset($_POST['btn-update']))
{
$id = $_GET['edit_articolo_id'];
$data = $_POST['data'];
$autore = $_POST['autore'];
$titolo = $_POST['titolo'];
if($crud->update_articoli($id,$data,$autore,$titolo))
{
$msg = "<br/><div class='alert alert-success'>
<strong>L'articolo è stato aggiornato correttamente!</strong>
</div>";
}
else
{
$msg = "<div class='alert alert-warning'>
<strong> C'è stato un errore durante l' aggiornamento dell' articolo !</strong>
</div>";
}
}
if(isset($_GET['edit_articolo_id']))
{
$id = $_GET['edit_articolo_id'];
extract($crud->getID_articoli($id));
}
?>
<?php include_once 'header.php'; ?>
<div class="clearfix"></div>
<div class="container">
<?php
if(isset($msg))
{
echo $msg;
}
?>
</div>
<div class="clearfix"></div>
<div class="container">
<h1>Modifica articolo</h1><hr>
<i class="glyphicon glyphicon-backward"></i> Torna alla lista articoli
<br/><br/>
<form method='post'>
<table class='table table-bordered'>
<tr>
<td>Data</td>
<td><input type='text' name='data' class='form-control' value="<?php echo $data; ?>" required></td>
</tr>
<tr>
<td>Autore</td>
<td><input type='text' name='autore' class='form-control' value="<?php echo $autore; ?>" required></td>
</tr>
<tr>
<td>Titolo</td>
<td><textarea name='titolo' rows="5" maxlength="100" class='form-control' required><?php echo $titolo; ?></textarea></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-update">
<span class="glyphicon glyphicon-edit"></span> Aggiorna articolo
</button>
<i class="glyphicon glyphicon-backward"></i> CANCEL
</td>
</tr>
</table>
</form>
</div>
<?php include_once 'footer.php'; ?>
Thanks for support.
I have a project that I'm doing now and my project consist of CRUD functions and it works fine. My project also has its pagination and search function.
The pagination is working but the search function does not seem to work. What I want is, a search where I can search anything within my table like I want to search all the fields or maybe a live search. Can somebody please help me.
Dbconfig.php
<?php
$db_host = 'localhost'
$db_username = 'root';
$db_password = '';
$db_name = 'survey';
try{
$db_con = new PDO("mysql:host={$db_host};dbname={$dbname}",db_username,$db_password);
}
catch(PDOException $exception{
echo $exception->getMessage();
}
include_once 'class.paginate.php'
$paginate = new paginate($DB_con);
?>
Class.paging.php
<?php
class paginate{
private $db;
function __construct($DB_con)
{
$this->db = $DB_con;
}
public function dataview($query)
{
$stmt = $this->db->prepare($query);
$stmt->execute();
if($stmt->rowCount()>0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['user_id']; ?></td>
<td><?php echo $row['username']; ?></td>
<td><?php echo $row['password']; ?></td>
<td><?php echo $row['province']; ?></td>
<!-- <td>visit</td> -->
</tr>
<?php
}
}
else
{
?>
<tr>
<td>Nothing here...</td>
</tr>
<?php
}
}
public function search($query)
{
$stmt=$this->db->prepare($query);
$query = '%' . $query . '%';
$stmt->bindparam('query', $query, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
if(empty($result) or $result == false)
return array();
else
return $result;
}
public function paging($query,$records_per_page)
{
$starting_position=0;
if(isset($_GET["page_no"]))
{
$starting_position= ($_GET["page_no"]-1)*$records_per_page;
}
$query2=$query." limit. $starting_position,$records_per_page";
return $query2;
}
public function paginglink($query,$records_per_page)
{
$self = $_SERVER['PHP_SELF'];
$stmt = $this->db->prepare($query);
$stmt->execute();
$total_no_of_records = $stmt->rowCount();
if($total_no_of_records > 0)
{
?><tr><td colspan="4" align="center"><?php
$total_no_of_pages=ceil($total_no_of_records/$records_per_page);
$current_page=1;
if(isset($_GET["page_no"]))
{
$current_page=$_GET["page_no"];
}
if($current_page!=1)
{
$previous =$current_page-1;
echo "<a href='".$self."?page_no=1'>First</a> ";
echo "<a href='".$self."?page_no=".$previous."'>Previous</a> ";
}
for($i=1;$i<=$total_no_of_pages;$i++)
{
if($i==$current_page)
{
echo "<strong><a href='".$self."?page_no=".$i."' style='color:red;text-decoration:none'>".$i."</a> </strong> ";
}
else
{
echo "<a href='".$self."?page_no=".$i."'>".$i."</a> ";
}
} if($current_page!=$total_no_of_pages)
{
$next=$current_page+1;
echo "<a href='".$self."?page_no=".$next."'>Next</a> ";
echo "<a href='".$self."?page_no=".$total_no_of_pages."'>Last</a> ";
}
?></td></tr><?php
}
}
}
Index.php
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="Bootstrap/bootstrap.css">
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
<body>
<div id="search-wrapper">
<form name="search" method="GET" action="">
<table id="search" class="table-responsive">
<tr>
<input name="var1" type="text" id="search-box">
<button id="submit" name="submit" type="submit">Search</button>
</tr>
</table>
<?php
$query = "SELECT * FROM `login` WHERE (`username` like :query or `password` like :query) ";
$paginate->search($query)
?>
</form>
</div>
<div id="table-wrapper" class="table-responsive">
<table id="data" class="table table-striped table-hover">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Password</th>
<th>Actions</th>
</tr>
</thead>
<?php
$query = "SELECT * FROM login";
$records_per_page=20;
$newquery = $paginate->paging($query,$records_per_page);
$paginate->dataview($newquery);
$paginate->paginglink($query,$records_per_page);
?>
</table>
</div>
<div id="footer">
cleartuts.blogspot.com
</div>
</body>
</html>
i have these three files:
index.php:
<div class="tweet_bx">
<form method="post" name="m_gigs" id="m_gigs" enctype="multipart/form-data" action="index.php">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="17%"><strong>Filter gigs by</strong></td>
<td class="<?php echo $class1; ?>" width="8%" align="center" ><a class="cuuuent" href="index.php?gigs=latest" >Latest</a></td>
<td class="<?php echo $class2; ?>" width="15%" align="center">Most Popular</td>
<td class="<?php echo $class3; ?>" width="15%" align="center"><a href="index.php?gigs=rating" >Best Ratings</a></td>
</tr>
</table>
<table>
<?php
include('Sql.php');
$c = new connexion();
$videos= $c->getVideos();
for($i=0;$i<sizeof($videos); $i++)
{
?>
<tr><td colspan = "2"><img src="<?php echo $videos[$i]['image']; ?> " /></td>
<td><label color="blue"><?php echo $videos[$i]['titre']; ?></label></td>
</tr>
<tr>
<td><label color="blue"><?php echo $videos[$i]['description']; ?></label></td>
</tr>
<?php
}
?>
</table>
</form>
</div>
<div class="tweet_bx">
<?php
?>
</div>
</div>
<?php include('right.php'); ?>
</div>
the file right.php:
<div class="right_box">
<div class="right_box_center">
<ul>
<?php
include('Sql.php');
$c = new connexion();
$categories = $c->getCategories();
for($i=0;$i<sizeof($categories) ; $i++){
?>
<li><?php echo $categories[$i]['categorie'];?> </li>
<?php
}
?>
</ul>
</div>
<img align="middle" src="images/img.jpg" />
<img align="middle" src="images/invite.jpg" style="padding-left:32px;" />
</div>
and finally the file sql.php:
<?php
class connexion {
function __construct(){
$HOST_DB ="mysql11.000webhost.com";
$NAME_DB="a1638637_fiverr";
$USER_DB ="a1638637_afif";
$PWD_DB="azerty2012";
$connect = mysql_connect($HOST_DB,$USER_DB,$PWD_DB) or die();
$db=mysql_select_db($NAME_DB);
}
//Registration part
function register($email,$login,$pass){
$verif_email= $this->exists($email,0);
$verif_user = $this->exists($user,1);
if(!$verif_email && !$verif_user){
$requete_insert_tem ="INSERT INTO member (`email`,`user`,`password`) VALUES ('".$email."', '".$login."','".$pass."'); ";
mysql_query($requete_insert_tem) or die();
return true;
}
else return false;
}
function exists($attribut,$number){
if($number==0){
$Log_query=mysql_query("SELECT * FROM member WHERE email ='$attribut'") or die(mysql_error());
if ($Log_query == true && mysql_num_rows($Log_query) >0)return true;
else return false;
}
if($number==1){
$Log_query=mysql_query("SELECT * FROM member WHERE user ='$attribut'") or die(mysql_error());
if ($Log_query == true && mysql_num_rows($Log_query) >0)return true;
else return false;
}
}
//login part
function login($attr, $pass){
$verif_email= $this->exists($attr,0);
$verif_user = $this->exists($attr,1);
if($verif_email){
$Log_query=mysql_query("SELECT * FROM member WHERE email ='$attr' AND password = '$pass'") or die(mysql_error());
if ($Log_query == true && mysql_num_rows($Log_query) >0) {
$p=0;
while ($Res_user = mysql_fetch_array($Log_query) ) {
$marques[$p] = $Res_user;
$p++;
}
}
return $marques;
}
if($verif_user){
$Log_query=mysql_query("SELECT * FROM member WHERE user ='$attr' AND password = '$pass'") or die(mysql_error());
if ($Log_query == true && mysql_num_rows($Log_query) >0) {
$p=0;
while ($Res_user = mysql_fetch_array($Log_query) ) {
$marques[$p] = $Res_user;
$p++;
}
}
return $marques;
}
return null;
}
function getCategories(){
$Log_query=mysql_query("SELECT distinct(categorie) FROM video ") ;
if ($Log_query == true && mysql_num_rows($Log_query) >0) {
$p=0;
while ($Res_user = mysql_fetch_array($Log_query) ) {
$marques[$p] = $Res_user;
$p++;
}
}
return $marques;
}
function getVideos(){
$Log_query=mysql_query("SELECT * FROM video ") ;
if ($Log_query == true && mysql_num_rows($Log_query) >0) {
$p=0;
while ($Res_user = mysql_fetch_array($Log_query) ) {
$marques[$p] = $Res_user;
$p++;
}
}
return $marques;
}
}
?>
i have this error : Fatal error: Cannot redeclare class connexion in /home/a1638637/public_html/Sql.php on line 2 . but i didn't redeclare the class connexion!!
i think that the problem is in the right.php file because:
the right part doesn't work
the error appears there
to fix this error i need to know
what is the error?
how can i fix it?
You need to use require_once instead of include. The SQl.php file is read and parsed twice and therefore it tries to redeclare an already declared class. With require_once this won't happen.