Same page is loading when clicking pagination in DataTable PHP - php

When I click page number in DataTable, it is not moving to next page instead it loads the whole page again.
But if I click the DataTable sorting button and again I click the pagination page number, the DataTable is working fine. Can anyone help me to solve this. Thanks in advance.
<?php include 'header.php'; ?>
</style>
<!-- Breadcrumbs -->
<section class="bg-gray-7">
<div class="breadcrumbs-custom box-transform-wrap context-dark">
<div class="container">
<h3 class="breadcrumbs-custom-title">Sailing Schedules</h3>
<div class="breadcrumbs-custom-decor"></div>
</div>
<div class="box-transform" style="background-image: url(images/bg-typography.jpg);"></div>
</div>
<div class="container">
<ul class="breadcrumbs-custom-path">
<li>Home</li>
<li class="active">Sailing Schedule</li>
</ul>
</div>
</section>
<br>
<br>
<div class="container">
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Include config file
require 'config.php';
$sql = "SELECT * FROM long_sched";
if($result = mysqli_query($con, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table-custom table-custom-primary' id ='long_schd_table'>";
echo "<thead>";
echo "<tr>";
echo "<th>Service Name</th>";
echo "<th>Description</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td><a href=http://localhost/permatest/". $row['long_filepath'] . " target='_self' download>".$row['long_service']."</a></td>";
echo "<td>" . $row['long_desc'] . "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else {
echo "<p class='lead'><em>No records were found.</em></p>";
} else {
echo "ERROR: Could not able to execute ".$sql." " . mysqli_error($con);
}
// Close connection
mysqli_close($con);
?>
</div>
</section>
<br>
<br>
<?php include 'off_footer.php'; ?>
<script>
$('#long_schd_table').DataTable({});
</script>
The above code is giving this error but in my console I didn't get any error information.

Related

Saving Radio buttons info on php

I'm currently working on a voting project, i have a form that is populated from the database and i managed to use loops to generate radio buttons. However the radio button can only select one answer out of the possible eight, i need it to select an answer in each and every question. i know the radio button names are the same and the need to be different, however its a loop so i dont know how to change the names. any help?
Here is the code
<?php $title="POLLS | Voting - Home";
require_once( "includes/session.php");
include( "includes/connection.php");
include( "includes/header.php");
$query="SELECT user_id FROM users WHERE user_id={$_SESSION['user_id']}" ;
$result=mysql_query($query,$connection);
$row=mysql_fetch_row($result);
$_SESSION[ 'user_id']=$row[0]; ?>
<body>
<div id="outerDiv">
<div id="header">
<div id="mainMenu"> </div>
<!-- mainMenu -->
</div>
<!-- header -->
<div id="midBanner"> </div>
<div id="content">
<div id="mainContent">
<p>Welcome,
<?php echo strtoupper($_SESSION[ 'username'])?>!</p>
<form action="votingpage.php" method="post">
<?php $query="SELECT question_id,question FROM questions " ; $result=mysql_query($query, $connection); ?>
<form>
<table class="Question Table">
<th></th>
<?php echo "<tr>"; echo "<tr>"; echo "<tr>"; ***strong text***$num_rows="" ; $counter=$num_rows; while($row=mysql_fetch_assoc($result)){ echo "<br />"; $counter +=1 ; echo "<br />"; echo $counter; echo $row[ 'question']; echo "<br />"; $query1="SELECT qstn_ans_id, possible_answer FROM qanswers WHERE question_id= " . $row[ 'question_id'] ; $result1=mysql_query($query1, $connection); while($row1=mysql_fetch_assoc($result1)){ echo "<input type='radio' name='possible_answer'".$row1[ 'qstn_ans_id']. " value='".$row1[ 'qstn_ans_id']. "'/> ".$row1[ 'possible_answer']; echo "<br />"; } } ?> </table>
</form>
</div>
<!-- mainContent -->
<p class="clear" /> </div>
<!-- content -->
</div>
<!-- outerDiv -->
<?php include( "includes/footer.php"); ?>

how to check in database for records

i am using a simple database for a guestbook. I just can't figure out how to check if there has nobody written in the guestbook yet. Because in that case, there should be an echo: "Be the first to write in the guestbook". Otherwise, the rows should be echoed.
How can i do that?
Piece of the code:
if (mysqli_connect_errno($con))
{
echo "Connectie Database mislukt: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT name,message,email,datetime FROM guestbook");
while($row = mysqli_fetch_array($result))
{ ?>
<div class="velden"> <!-- voor styling van alle echo's; zie CSS -->
<div class="header">
<div class="naam"><?php echo $row['name']; ?></div> <!-- echo naam-->
<div class="email"><?php echo $row['email']; ?></div> <!-- echo email-->
<div class="tijd"><?php echo $row['datetime']; ?></div> <!-- echo datum en tijd-->
</div>
<div class="bericht"><?php echo $row['message']; ?></div> <!-- echo bericht-->
</div>
<?php } ?>
So there should be something like:
If(nobody has written) {
echo 'Be the first to write in the database";
} else {
//do the echo's
}
I believe mysqli_num_rows (http://php.net/manual/en/mysqli-result.num-rows.php) is what you're after.
if(mysqli_num_rows($result) == 0) {
echo 'Be the first to sign my guestbook!';
} else {
while($row = mysqli_fetch_array($result))
{ ?>
...
<?php } ?>
}
Here's an example from w3 schools: http://www.w3schools.com/php/func_mysqli_num_rows.asp
You can get the number of rows after you execute the query and then if the count is 0 echo "be the first..." else do you while that displays the guestbook... http://www.w3schools.com/php/func_mysqli_num_rows.asp
you should query
SELECT count(*) AS num FROM guestbook
if database is empty result will be 0, otherwise total number or rows in table

Warning: Illegal string offset 'id' in

I'm making a form to update my MySQL database, but for some reason I get the following error in my browser:
C:\wamp\www\Helpdeskapplicatie\update_hardware.php on line 49
Could someone tell me what I'm doing wrong??
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/layout.css"/>
</head>
<body>
<div id="menu">
<div id="menu_wrapper">
<ul>
<li>Configuratiebeheer<img src="afb/pijltje.png" width="10"/></a>
<ul>
<li>Lijst hardware</li>
<li>Hardware toevoegen</li>
<li>Hardware verwijderen</li>
</ul>
</li>
</ul>
</div>
</div>
<?php
$connect=mysql_connect("localhost", "root","");
mysql_select_db("helpdesk_middenpolder", $connect);
$id=$_GET['id'];
$q="SELECT * FROM hardware WHERE hardwareID=$id";
$r=mysql_query($q);
echo "<table border='1'>";
echo "<th>merknaam</th><th>producttype</th><th>hardwaretype</th>";
while ($x=mysql_fetch_array($r)){
echo "<tr>";
echo "<td>";
echo "<input type='text' value='".$x['merknaam']."'>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='".$x['producttype']."'>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='".$x['hardwaretype']."'>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($connect);
?>
<?php
if(isset($_POST['updatehardware'])){
$query = "UPDATE hardware SET merknaam='".$x['merknaam']."', producttype='".$x['producttype']."', hardwaretype='".$x['hardwaretype']."' WHERE hardwareID='".$id['id']."'";
mysql_query($query);
}
?>
<form method="post">
<input type="submit" name="updatehardware" value="Hardware updaten">
</form>
</body>
</html>
Your update query need to change like this,
hardwareID='".$id."'
instead of
hardwareID='".$id['id']."'
You are using $id['id'] instead of $_GET['id']. However never trust passed with GET/POST data. Use instead:
$id = (int) $_GET['id'];

Div not looping correctly

I'm trying to get my code to display multiple divs. But seems to only display one div correctly.
<?php
// database connection
//$result = mysqli_query($con,"SELECT * FROM test WHERE field5='Cohen'");
echo " <div id='1'>";
while($row = mysqli_fetch_array($result))
{
echo "<div class='tutorName'>" . $row['field1'] . "</div>";
echo "<div class='tutorPrice'>" . $row['field2'] . "</div>";
echo "<div class='tutorInstitution'>" . $row['field3'] . "</div>";
echo "<div class='tutorLocale'>" . $row['field4'] . "</div>";
echo "<div class='tutorPhone'>" . $row['field5'] . "</div>";
}
echo "</div>";
mysqli_close($con);
?>
I want the following to loop and over using the fields above (field1, feild2, etc):
<div id='' name='' class="column threecol">
<div class="course-preview premium-course">
<div class="course-image">
<img src="img.png" />
<div class="course-price">
<div class="corner-wrap">
<div class="corner"></div>
<div class="corner-background"></div>
</div>
<div class="price-text"><span class="amount">PerHour</span></div>
</div>
</div>
<div class="course-meta">
<header class="course-header">
<h5 class="nomargin">TutorName </h5>
<div class='gender'>Gender: </div>
<div class='price-range'>Price Range: </div>
<div class='institute'> Institute: </div>
</header>
</div>
</div>
</div>
Is your $result line really commented out in the real code? Or did you just add that comment for the example? If it's commented-out in the code you're testing, then that's probably the issue.
you want this? , 1 div wrap all content like table tr
$i=1;
while($row = mysqli_fetch_array($result))
{
echo " <div id='{$i}'>";
echo "<div class='tutorName'>" . $row['field1'] . "</div>";
echo "<div class='tutorPrice'>" . $row['field2'] . "</div>";
echo "<div class='tutorInstitution'>" . $row['field3'] . "</div>";
echo "<div class='tutorLocale'>" . $row['field4'] . "</div>";
echo "<div class='tutorPhone'>" . $row['field5'] . "</div>";
echo "</div>";
$i++;
}

PDO Messed Up My CSS / HTML Layout

One of my webpages that had perfect format under MySQL_* functions, suddenly got mixed up when I translated the old functions to PDO. The problem is that my Copyright bar is now floating above my table of MySQL data, while it should be at the bottom of the page. I'm not sure why it's happening. Any help is appreciated!
This is the portion of the file that I believe may be the problem:
<div id="content" style="float:center;background-image:url('http://tinyurl.com/bds4u2j');">
<ul class="menu">
<li>
<?php
if(!isset($_COOKIE['username'])){
echo "Welcome, guest!";
}else{
echo "Welcome, " . $_COOKIE['username'];
}
?>
</li>
<li><br></li>
<li><a class="item" href="index.html">Home</a></li>
<li><a class="item" href="classes.html">Classes</a></li>
<li><a class="item" href="contact.html">Contact</a></li>
<?php
if(!isset($_COOKIE['username'])){
echo '<li><a class="item" href="login.html">Login</a></li>';
}else{
echo '<li><a class="item" href="upload.html">Upload</a></li>';
echo '<li><a class="item" href="password_protect.php?logout=1">Logout</a></li>';
}
?>
</ul>
<center><h1>Mr. Stanford's first period</h1></center>
<br>
<center><h3>Your class files are available for download below</h3></center>
<br>
<br>
<center>
<?php
echo "<table border='1'>
<tr>
<th>Filename</th>
<th>Description</th>
<th>Download</th>";
IF(isset($_COOKIE["username"]))
{
echo "<th>Delete</th>","</tr>";
}
ELSE
{
echo "</tr>";
}
try{
$dbh = new PDO('mysql:host=$host;port=$port;dbname=$dbname','$username','$password');
foreach($dbh->query('SELECT * from period1') as $row) {
echo "<tr>";
echo "<td>" . $row['Filename'] . "</td>";
echo "<td>" . $row['Description'] . "</td>";
echo "<td><a href = ". $row['File'] ." ><button>Download</button></a></td>";
IF(isset($_COOKIE["username"]))
{
echo "<td><a href = 'deletefile.php?$s_id=". $row['s_id'] ."'><button>Delete</button></a></td>","</tr>";
}
ELSE
{
echo "</tr>";
}
echo "</table>";
}
$dbh=null;
} catch (PDOException $e) {
print "<br>ERROR: " . $e->getMessage() . "<br/>";
die();
}
$dbh=null;
?>
</center>
<br>
<br>
<br>
</div>
<div id="footer" style="background-color:#99FF33;clear:both;text-align:center;">
Copyright © David Schilpp 2013, All Rights Reserved
</div>
Again, thank you to anybody who can help me debug this problem!
I guessed that your table was not closed. see comments on question.
When you are facing this kind of problem (broken html), you should first analyse the html generated.
You can right-click on page and select View page source.
You can use tools freely available too.
As always, StackOverflow is great place to find answer and new stuff

Categories