Send $_GET using php or jquery - php

my index.php page has something like this:
if(isset($_GET['page'])) {
switch ($_GET['page']) {
case 'login':
include('login.php');
break;
case 'log_out':
$_SESSION['loggedin'] = false;
include('loggedout.html');
break;
case 'profile':
include('profile.php');
break;
case 'contact_us':
include('contact.html');
break;
default:
include('home.html');
break;
}
} else {
include('home.html');
}
Now I can easily call on a new page when a link is pressed or form is submitted i.e:
Home Contact Us
but what if I had an all in one form... It would need to be able to send a request through PHP code to my index.php to show the logged in page or reshow the login.php page but I cant seem to find anything that would allow me to send a request in php script i.e:
<?php
if(..) {
send request to index.php i.e index.php?page=profile
}
?>
The reason I need this is my index.php uses divs as formatting and thus if I dont request pages through index.php they are displayed in a new html (i.e it doesnt have my navigation bars etc)
As per a comment by #HydraIO and others how would this be done using JQuery?
Here is some code:
lgoin.php:
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1"
/>
<!--
//thanks http://decoraora.com/fototapete_115x175.php for the image http://decoraora.com/fototapete/images/664.jpg -->
<style type="text/css">
.table {
background: url("bg.jpg") no-repeat;
width: 600px;
height: 250px;
}
</style>
</head>
<body>
<?php
if (isset($_POST['formLogin'])) {
$un = $_POST['username'];
$pwd = $_POST['password'];
if($pwd!=''&&$un!='') {
if (md5($pwd)==='29ef52e7563626a96cea7f4b4085c124') {
$_SESSION['loggedin'] = true;
$_SESSION['login_error'] = 0;
$_SESSION['username'] = $un;
$_SESSION['password'] = $pwd;
//include('profile.php');
//header("Location: index.php/page=profile");
//header("Location: http://localhost/index.php?index.php?page=profile");
} else {
$_SESSION['login_error'] = 1;
echo 'this will dipslay in its own page';
//include('login.php');
}
}else {
$_SESSION['login_error'] = 2;
echo 'display in its own page';
//include('login.php');
?>
<form action="login.php" method="post">
<table bgcolor="white" align="center" border="1px" width="50%" style="height: 40%;">
<tr>
<td colspan="2" align="center">Login for CC Chat</td>
</tr>
<tr>
<td>Username:</td>
<td>Password:</td>
</tr>
<tr>
<td><input type="text" name="username" maxlength="50"/></td>
<td><input type="password" name="password" maxlength="50"/></td>
</tr>
<tr>
<td>Forgot your password?</td>
<td><input type="submit" name="formLogin" value="Login"/></td>
</tr>
<?php
if(isset($_SESSION['login_error'])) {
switch ($_SESSION['login_error']) {
case 1:
echo '<tr>';
echo '<td>';
echo '<font color="red">Password does not match</font>';
echo '</td>';
echo '</tr>';
$_SESSION['login_error']=0;
break;
case 2:
echo '<tr>';
echo '<td>';
echo '<font color="red">Password and/or Username cannot be empty</font>';
echo '</td>';
echo '</tr>';
$_SESSION['login_error']=0;
break;
default:
break;
}
}
?>
<tr>
<td colspan="2" align="center">© CopyLeft David Kroukamp 11039662 2013 - 2015</td>
</tr>
</table>
</form>
<?php
}
}else {
?>
<form action="login.php" method="post">
<table bgcolor="white" align="center" border="1px" width="50%" style="height: 40%;">
<tr>
<td colspan="2" align="center">Login for CC Chat</td>
</tr>
<tr>
<td>Username:</td>
<td>Password:</td>
</tr>
<tr>
<td><input type="text" name="username" maxlength="50"/></td>
<td><input type="password" name="password" maxlength="50"/></td>
</tr>
<tr>
<td>Forgot your password?</td>
<td><input type="submit" name="formLogin" value="Login"/></td>
</tr>
<?php
if(isset($_SESSION['login_error'])) {
switch ($_SESSION['login_error']) {
case 1:
echo '<tr>';
echo '<td>';
echo '<font color="red">Password does not match</font>';
echo '</td>';
echo '</tr>';
$_SESSION['login_error']=0;
break;
case 2:
echo '<tr>';
echo '<td>';
echo '<font color="red">Password and/or Username cannot be empty</font>';
echo '</td>';
echo '</tr>';
$_SESSION['login_error']=0;
break;
default:
break;
}
}
?>
<tr>
<td colspan="2" align="center">© CopyLeft David Kroukamp 11039662 2013 - 2015</td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
index.php:
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CC Chat</title>
<meta
http-equiv="content-type" content="text/html; charset=iso-8859-1"
/>
<!--
Thanks too http://stackoverflow.com/a/7851347/1133011 for the help
on layout which acts more like frames but avoids them and using divs. As frames have
known draw backs see here http://stackoverflow.com/questions/4600648/frames-with-php we
should thus rather use include in php
!-->
<style type="text/css" media="screen">
/* Generic pane rules */
body { margin: 0 }
.row, .col { overflow: hidden; position: absolute; }
.row { left: 0; right: 0; }
.col { top: 0; bottom: 0; }
.scroll-x { overflow-x: auto; }
.scroll-y { overflow-y: auto; }
.header.row { height: 75px; top: 0; background-color: #E5E5E5; }
.menu.row { height: 75px; top: 75px; background-color: #EDEDED; }
.body.row { top: 150px; bottom: 50px; background-color: #F5F5F5; }
.footer.row { height: 75px; bottom: 0; background-color: #EBEBEB; }
A:link {text-decoration: none}
A:visited {text-decoration: none}
A:active {text-decoration: none}
A:hover {font-size:24; font-weight:bold; color: red;}
</style>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<div class="header row">
<?php
include("header.html");
?>
</div>
<div class="body row scroll-y">
<?php
if(isset($_GET['page'])) {
switch ($_GET['page']) {
case 'login':
include('login.php');
break;
case 'log_out':
$_SESSION['loggedin'] = false;
include('loggedout.html');
break;
case 'profile':
include('profile.php');
break;
case 'contact_us':
include('contact.html');
break;
default:
include('home.html');
break;
}
} else {
include('home.html');
}
?>
</div>
<div class="menu row">
<?php
include("nav.php");
?>
</div>
<div class="footer row">
<?php
include("footer.php");
?>
</div>
</body>
</html>
UPDATED with JQuery attempt in if statement which checks password hash:
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1"
/>
<!--
//thanks http://decoraora.com/fototapete_115x175.php for the image http://decoraora.com/fototapete/images/664.jpg -->
<style type="text/css">
.table {
background: url("bg.jpg") no-repeat;
width: 600px;
height: 250px;
}
</style> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<?php
if (isset($_POST['formLogin'])) {
$un = $_POST['username'];
$pwd = $_POST['password'];
if($pwd!=''&&$un!='') {
if (md5($pwd)==='29ef52e7563626a96cea7f4b4085c124') {
$_SESSION['loggedin'] = true;
$_SESSION['login_error'] = 0;
$_SESSION['username'] = $un;
$_SESSION['password'] = $pwd;
//include('profile.php');
//header("Location: index.php/page=profile");
//header("Location: http://localhost/index.php?index.php?page=profile");
//exit();
echo "<script type='text/javascript'>";
echo "$.get('index.php?page=profile', function(data) {
$('.body.row').html(data);
alert('Load was performed.');
});";
echo "</script>";
} else {
$_SESSION['login_error'] = 1;
echo 'this will dipslay in its own page';
//include('login.php');
}
}else {
$_SESSION['login_error'] = 2;
echo 'display in its own page';
//include('login.php');
?>
<form action="login.php" method="post">
<table bgcolor="white" align="center" border="1px" width="50%" style="height: 40%;">
<tr>
<td colspan="2" align="center">Login for CC Chat</td>
</tr>
<tr>
<td>Username:</td>
<td>Password:</td>
</tr>
<tr>
<td><input type="text" name="username" maxlength="50"/></td>
<td><input type="password" name="password" maxlength="50"/></td>
</tr>
<tr>
<td>Forgot your password?</td>
<td><input type="submit" name="formLogin" value="Login"/></td>
</tr>
<?php
if(isset($_SESSION['login_error'])) {
switch ($_SESSION['login_error']) {
case 1:
echo '<tr>';
echo '<td>';
echo '<font color="red">Password does not match</font>';
echo '</td>';
echo '</tr>';
$_SESSION['login_error']=0;
break;
case 2:
echo '<tr>';
echo '<td>';
echo '<font color="red">Password and/or Username cannot be empty</font>';
echo '</td>';
echo '</tr>';
$_SESSION['login_error']=0;
break;
default:
break;
}
}
?>
<tr>
<td colspan="2" align="center">© CopyLeft David Kroukamp 11039662 2013 - 2015</td>
</tr>
</table>
</form>
<?php
}
}else {
?>
<form action="login.php" method="post">
<table bgcolor="white" align="center" border="1px" width="50%" style="height: 40%;">
<tr>
<td colspan="2" align="center">Login for CC Chat</td>
</tr>
<tr>
<td>Username:</td>
<td>Password:</td>
</tr>
<tr>
<td><input type="text" name="username" maxlength="50"/></td>
<td><input type="password" name="password" maxlength="50"/></td>
</tr>
<tr>
<td>Forgot your password?</td>
<td><input type="submit" name="formLogin" value="Login"/></td>
</tr>
<?php
if(isset($_SESSION['login_error'])) {
switch ($_SESSION['login_error']) {
case 1:
echo '<tr>';
echo '<td>';
echo '<font color="red">Password does not match</font>';
echo '</td>';
echo '</tr>';
$_SESSION['login_error']=0;
break;
case 2:
echo '<tr>';
echo '<td>';
echo '<font color="red">Password and/or Username cannot be empty</font>';
echo '</td>';
echo '</tr>';
$_SESSION['login_error']=0;
break;
default:
break;
}
}
?>
<tr>
<td colspan="2" align="center">© CopyLeft David Kroukamp 11039662 2013 - 2015</td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
I see the alert but am redirected to a blank html like before (even than before at least the form was reloaded

It sounds like you might want to evaluate all the data inside your index page first and do a page redirect by setting a header inside php to the same index page with the get query updated to whatever you want it to be.
header("Location: http://www.example.com/index.php?page=profile");
exit();
make sure you don't output any html with echo or any other way before you do the redirect. If your script heavily uses echo before that you can look into outputbuffering your echos.

PHP is a server-side language, and not dynamic. You want to use javascript (jQuery in my example).
$_GET = <?php echo json_encode($_GET); ?>;
if($_GET['val'] == some_value){
$.get(index.php?getvar=getval, {
complete: function(){
$('#div').val("YOUR OUTPUT"); // *
}
});
}
*This can be any code you feel like, you could replace the div with the entire php file if you chose to

Related

I can't update MySQL PHP

I don't get any errors but I can't update MySQL PHP. I want to change dropdown status from "sedang diproses" dropdown into "Berjaya or Tidak Berjaya". Also I can't change in the database "sedang diproses" into "Berjaya or Tidak Berjaya"
This is my Code Html
<?php
session_start();
include ('include/myFunction.php');
require('include/connect.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<link href="css/myStyle.css" rel="stylesheet" type="text/css" />
<link href="css/myStyle1.css" rel="stylesheet" type="text/css" />
<!-- Button to open the modal login form -->
<link href="css/myStyle3.css" rel="stylesheet" type="text/css" />
<body>
<div align="right">
<a href="logout.php" ><img src="img/logout.png" width="63" height="46" /></a>
</div>
<div class="header" align="left"><img src="img/gmbar.PNG" width="223" height="126" /><!-- end .header --><!-- end .header --></div>
<div class="content" style="font:Verdana, Geneva, sans-serif">
<div class="content" style="font:Verdana, Geneva, sans-serif">
<div class="topnav" id="myTopnav" style="font-family:Verdana, Geneva, sans-serif">Kembali
</div>
<p> </p>
<?php if($_SESSION['namaadmin'] ==null)
{
header('location:index.php');
}
else
{
?>
<form action="prosesstatus.php" method="post">
<table width="1002" height="87" border="0" align="center" bgcolor="#CCCCFF">
<tr bgcolor="#00CCFF">
<td width="30"><strong>Bil</strong></td>
<td width="298"><strong>Nama</strong></td>
<td width="176"><strong>Nama Kursus</strong></td>
<td width="150"><strong>Tarikh Daftar</strong></td>
<td width="150"><strong>Status</strong></td>
<td width="168"><strong>Kemaskini Status</strong></td>
<td width="131"><strong>Pilihan</strong></td>
</tr>
<?php
$namakursus = '';
if( isset( $_GET['namakursus'])) {
$namakursus = $_GET['namakursus'];
}
$sql1 = "Select * from pemohonan INNER JOIN kursus ON pemohonan.idkursus = kursus.idkursus
INNER JOIN pemohon ON pemohonan.idPemohon = pemohon.idPemohon WHERE kursus.namakursus = '$namakursus' ";
$result1=mysqli_query($dbc,$sql1) or die (mysqli_error());
$i=1;
while($row1 = mysqli_fetch_assoc($result1))
{
?>
<tr>
<td><strong><?php echo $i; ?><input name="idkursus" type="hidden" size="50" value="<?php echo $row1['idkursus'];?>"/><input name="idPemohonan" type="hidden" size="50" value="<?php echo $row1['idPemohonan'];?>"/></strong></td>
<td><strong><?php echo $row1['nama']; ?></strong><input name="id" type="hidden" size="50" value="<?php echo $row1['idPemohon'];?>"/></strong></td>
<td><strong><?php echo $row1['namakursus']; ?></strong></td>
<td><strong><?php echo $row1['tarikhpemohon']; ?></strong></td>
<td><strong><?php echo $row1['status']; ?></strong></td>
<td><select name="status" value="<?php echo $row1['status']; ?>">
<option value="sila pilih">-Sila Pilih-</option>
<option value="Berjaya">Berjaya</option>
<option value="Tidak Berjaya">Tidak Berjaya</option>
</select></td>
<td><input name="btnKemaskini" type="submit" value="Kemaskini" /></td>
</tr>
<?php
$i++;
}
mysqli_close($dbc);
}
?>
</table></form>
<p> </p>
<p> </p>
<div class="footer" style="font-family:Arial, Helvetica, sans-serif">
<?php footertext(); ?>
</div>
</body>
</html>
This is Image
This Is My Image DB
This is my Code Php
<?php
require ('include/connect.php');
$idPemohonan = '';
$idPemohon = '';
$idkursus = '';
if (isset($_GET['idPemohon'],$_GET['idkursus'],$_GET['idPemohonan']))
{
$idPemohon = $_GET['idPemohon'];
$idkursus = $_GET['idkursus'];
$idPemohonan = $_GET['idPemohonan'];
}
$tarikhharini=date('y-m-d');
$status=$_POST['status'];
$sql1 = "UPDATE pemohonan SET idPemohonan ='$idPemohonan' , idPemohon ='$idPemohon' , idkursus ='$idkursus' , tarikhpemohon ='$tarikhharini' , status='$status'
where idPemohonan = '$idPemohonan' and idPemohon = '$idPemohon'";
$result1 = mysqli_query($dbc,$sql1) or die (mysqli_error());
$num_row1 = mysqli_affected_rows($dbc);
echo "<script language=\"JavaScript\">\n";
echo "alert('Status Pemohonan Telah Dihantar!');\n";
echo "window.location='senaraipemohon.php'";
echo "</script>";
mysqli_close($dbc);
?>
Your code is not working because you haven't sent in
<form action="prosesstatus.php" method="post">
Parameters:
$idPemohon = $_GET['idPemohon'];
$idkursus = $_GET['idkursus'];
$idPemohonan =
$_GET['idPemohonan'];
If you want use $_GET link should look like:
prosesstatus.php?idPemohon=value&idkursus=value&idPemohonan=value
Or you should add these parameters in
Input type hidden and change in php to $_POST
I agree with others than you should use MVC for example some kind of framework (Laravel, CodeIgniter)
Or separate as much as possible php and html because your code looks unprofessional.
Your MySQL queries are vulnerable to SQL injection and most likely file
include/connect.php
is not outside public folder which is not good practice to do.

Table color text won't change

I want to change the text colors in my table
That is all my php code:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<form action="" method="POST">
Lista:<br>
<input type="text" name="camp_1">
<br>
<input type="submit" value="Submit" />
<?php
if (isset($_POST['camp_1'])){
$var = $_POST['camp_1'];
$var = str_replace(' ','', $var);
$x = explode(',', $var);
$odd = 1;
$sum = 0;
echo '<table>';
for($i = 0; $i < count ($x) - 1; $i = $i + 2){
if ( $odd ){
echo
'<tr>
<th>'.$x[$i].'</td>
<th>'.$x[$i + 1].'</td>
</tr>';
}
else{
echo
'<tr>
<td>'.$x[$i].'</td>
<td>'.$x[$i + 1].'</td>
</tr>';
}
$sum += $x[$i + 1];
$odd = 1 - $odd; // comutes between 0 and 1
}
if ( $odd ){
echo
'<tr >
<th>Total</th>
<th>'.$sum.' $</th>
</tr>';
}
else{
echo
'<tr>
<td>Total</td>
<td>'.$sum.' $</td>
</tr>';
}
echo '</table>';
}//if isset
?>
</form>
</body>
</html>
And my CSS file
Names style.css.
table th{
background-color: green;
color: #58FAD0;
}
td {
color: #CC2EFA;
}
It just ignores whatever I write in my CSS file, regarding td and th
I must add that both files are in the same folder
table, th, tr{
background-color: green;
color: #58FAD0;
}
td {
color: #CC2EFA;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Savings</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
<td>$100</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
<td>$150</td>
</tr>
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>$300</td>
</tr>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>$250</td>
</tr>
</table>
</body>
</html>

Why can't I insert my php login form into my site template?

what is going on?
I recently installed and updated a site template , and designed it.
My friend had some site which he got on it a php login form, for users to log in.
I asked him for the code and he gave me it, and ofc I just copied the code and pasted it between my site template code.
I know u confused, so here's the deal:
This is a basic page on my site:
<?php
include('config.php');
if(MODULE == 'none')
{
include(LOVE_ROOT . '/system/love_head.php');
$content = '<h2> Welcome to OUR SITE </h2>
<br />
Hey this is a test
<br />
Hey this is a test
<br />
Hey this is a test
<br /> <br />
Hey this is a test
<br />
Hey this is a test
<br />
Hey this is a test
<br />
Hey this is a test
<br />
Hey this is a test
<br /> <br />
Welcome
<br />
Welcome to our site
<br />
Hey this is a test
<br /> <br /> <br />
';
include(LOVE_ROOT . '/system/love_foot.php');
}
else
{
header('Location: modules/' . MODULE);
}
?>
and here is the login form php code:
<?php
ob_start();
?>
<html dir="rtl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255" />
<style>
a:link,a:visited,a:active
{
background: transparent;
color: #000000;
text-decoration: none;
}
a:hover
{
background: transparent;
color: #00dfff;
}
td {
border: 1px solid gray;
padding: 5px;
text-align: center;
}
</style>
</head>
<center>
<?php
include('mysql.php');
$fname = $_POST['fname'];
$password = $_POST['pass'];
$pass1 = md5($password);
$pass = sha1($pass1);
$select = mysql_query("SELECT * FROM `users` WHERE fname='$fname'");
$cu = mysql_fetch_array($select);
if (!empty($_COOKIE['adv_U']) AND !empty($_COOKIE['adv_P']))
{
echo "אתה כבר מחובר לתחרות.";
}
else
{
if (!empty($username) || !empty($password))
{
if (empty($cu))
{
?>
<font color="darkred"><b>
שגיאה - השם הפרטי שהכנסת לא קיים במערכת
</b></font>
<br><br>
<input type="button" value="חזור אחורה" onclick="window.location.href='javascript:window.history.back(-1)';">
<?php
}
else if ($pass == $cu['password'])
{
if ($cu['ban'] == 1)
{
echo "<font color='red'><b>אתה מורחק מהתחרות עקב עבירה על החוקים!</b></font><br>אתה מוחזר לדף הבית של המערכת...";
echo "<meta http-equiv='refresh' content='3; url=index.php'>";
}
else
{
setcookie('adv_U',$fname);
setcookie('adv_P',$pass);
header( 'Location: index.php' );
}
}
else
{
?>
<font color="darkred"><b>
הסיסמא שהכנסת שגויה
</b></font>
<br><br>
<input type="button" value="חזור אחורה" onclick="window.location.href='javascript:window.history.back(-1)';">
<?php
}
}
else
{
?>
<form method="post" action="login.php">
<table>
<tr><td>שם פרטי</td><td><input type="text" name="fname"></td></tr>
<tr><td>סיסמא</td><td><input type="password" name="pass"></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="התחברות"></td></tr>
<tr><td colspan="2" align="center"><font size="2">(עוד לא נרשמת?)</font></td></tr>
</table>
</form>
<?php
}
}
?>
</div>
</td>
</tr>
</table>
</body>
</html>
<?php
ob_end_flush();
?>
I tried to copy the php code between the headers of my page, to something like that:
<?php
include('config.php');
if(MODULE == 'none')
{
include(LOVE_ROOT . '/system/love_head.php');
$content = '<h2> Welcome to OUR SITE </h2>
<br />
<?php
ob_start();
?>
<html dir="rtl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255" />
<style>
a:link,a:visited,a:active
{
background: transparent;
color: #000000;
text-decoration: none;
}
a:hover
{
background: transparent;
color: #00dfff;
}
td {
border: 1px solid gray;
padding: 5px;
text-align: center;
}
</style>
</head>
<center>
<?php
include('mysql.php');
$fname = $_POST['fname'];
$password = $_POST['pass'];
$pass1 = md5($password);
$pass = sha1($pass1);
$select = mysql_query("SELECT * FROM `users` WHERE fname='$fname'");
$cu = mysql_fetch_array($select);
if (!empty($_COOKIE['adv_U']) AND !empty($_COOKIE['adv_P']))
{
echo "אתה כבר מחובר לתחרות.";
}
else
{
if (!empty($username) || !empty($password))
{
if (empty($cu))
{
?>
<font color="darkred"><b>
שגיאה - השם הפרטי שהכנסת לא קיים במערכת
</b></font>
<br><br>
<input type="button" value="חזור אחורה" onclick="window.location.href='javascript:window.history.back(-1)';">
<?php
}
else if ($pass == $cu['password'])
{
if ($cu['ban'] == 1)
{
echo "<font color='red'><b>אתה מורחק מהתחרות עקב עבירה על החוקים!</b></font><br>אתה מוחזר לדף הבית של המערכת...";
echo "<meta http-equiv='refresh' content='3; url=index.php'>";
}
else
{
setcookie('adv_U',$fname);
setcookie('adv_P',$pass);
header( 'Location: index.php' );
}
}
else
{
?>
<font color="darkred"><b>
הסיסמא שהכנסת שגויה
</b></font>
<br><br>
<input type="button" value="חזור אחורה" onclick="window.location.href='javascript:window.history.back(-1)';">
<?php
}
}
else
{
?>
<form method="post" action="login.php">
<table>
<tr><td>שם פרטי</td><td><input type="text" name="fname"></td></tr>
<tr><td>סיסמא</td><td><input type="password" name="pass"></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="התחברות"></td></tr>
<tr><td colspan="2" align="center"><font size="2">(עוד לא נרשמת?)</font></td></tr>
</table>
</form>
<?php
}
}
?>
</div>
</td>
</tr>
</table>
</body>
</html>
<?php
ob_end_flush();
?>
<br /> <br /> <br />
';
include(LOVE_ROOT . '/system/love_foot.php');
}
else
{
header('Location: modules/' . MODULE);
}
?>
Of course I handled all the problems, deleted php tags where it's not neccessery, closed qoutes and etc..
but still.. it just won't work.
Sorry for my English,
Sorry for my lame knowledge,
please try and help a bummed guy who stuck with this problem already a week..
Thanks alot!
ALSO(!) I tried to fix it with NetBeans... but didn't manage.. lol I dont evenk now how this software works..
If I take the php code as it self, the original one, it works. If I take the original index file without anything else, it works.
When I add the code to the site template with the "love_foot" "love_head" and etc.. around the php login code, it tells me "unexpected T String".
So what is the problem here?
Thanks alot , I am so LOST right now!
You're missing the semicolon on Line 8. That's causing the rest of the PHP lines to be ignored.
Change it to:
$content = '<h2> Welcome to OUR SITE </h2><br />';
And around line ~127, you forgot to open the <? tag.
I believe that should fix the errors.
However you should use an IDE with syntax highlighting. That'll help you debug code faster.

editing CSS of PHP grid

I have an editable grid where I want to edit the CSS such that the textarea to show the maximum width, but somehow I can't increase the width of the text area.
My database has three columns:
ID
Name
Gossip
I'm retrieving everything and displaying it in an editable grid using PHP.
index.php code
<?php
$db = new mysqli('localhost', 'root', '', 'bollywood');
$db->set_charset('utf8');
if ($db->connect_errno) {
die('Check the database connection again!');
}
$userQuery = 'SELECT Id,Name,Gossip FROM bollywood';
$stmt = $db->query($userQuery);
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var textBefore = '';
$('#grid').find('td input').hover(function() {
textBefore = $(this).val();
$(this).focus();
}, function() {
var $field = $(this),
text = $field.val();
$(this).blur();
// Set back previous value if empty
if (text.length <= 0) {
$field.html(textBefore);
} else if (textBefore !== text) {
// Text has been changed make query
var value = {
'row': parseInt(getRowData($field)),
'column': parseInt($field.closest('tr').children().find(':input').index(this)),
'text': text
};
$.post('user.php', value)
.error(function() {
$('#message')
.html('Make sure you inserted correct data')
.fadeOut(3000)
.html('&nbsp');
$field.val(textBefore);
})
.success(function() {
$field.val(text);
});
} else {
$field.val(text);
}
});
// Get the id number from row
function getRowData($td) {
return $td.closest('tr').prop('class').match(/\d+/)[0];
}
});
</script>
<title></title>
</head>
<body>
<?php if ($stmt): ?>
<div id="grid">
<p id="message">Click on the field to Edit Data</p>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Gossip</th>
</tr>
</thead>
<tbody>
<?php while ($row = $stmt->fetch_assoc()): ?>
<tr class="<?php echo $row['Id']; ?>">
<td><input type="text" value="<?php echo $row['Id']; ?>" /> </td>
<td><input type="text" value="<?php echo $row['Name']; ?>" /></td>
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
<?php else: ?>
<p>No actors added yet</p>
<?php endif; ?>
</body>
</html>
user.php code
<?php
// Detect if there was XHR request
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$fields = array('row', 'column', 'text');
$sqlFields = array('Id', 'Name', 'Gossip');
foreach ($fields as $field) {
if (!isset($_POST[$field]) || strlen($_POST[$field]) <= 0) {
sendError('No correct data');
exit();
}
}
$db = new mysqli('localhost', 'root', '', 'bollywood');
$db->set_charset('utf8');
if ($db->connect_errno) {
sendError('Connect error');
exit();
}
$userQuery = sprintf("UPDATE bollywood SET %s='%s' WHERE Id=%d",
$sqlFields[intval($_POST['column'])],
$db->real_escape_string($_POST['text']),
$db->real_escape_string(intval($_POST['row'])));
$stmt = $db->query($userQuery);
if (!$stmt) {
sendError('Update failed');
exit();
}
}
header('Location: index.php');
function sendError($message) {
header($_SERVER['SERVER_PROTOCOL'] .' 320 '. $message);
}
style.css code
body {
font: normal 14px Comic Sans, Comic Sans MS, cursive;
}
table {
width: 500px;
}
td, th {
border: 1px solid #d8d8bf;
}
th {
padding: 5px;
font: bold 14px Verdana, Arial, sans-serif;
}
td {
padding: 10px;
width: 200px;
}
td input {
margin: 0;
padding: 0;
// width:200px;
font: normal 14px sans-serif;
/** Less flicker when :focus adds the underline **/
border: 1px solid #fff;
}
td input:focus {
outline: 0;
border-bottom: 1px dashed #ddd !important;
}
#grid input {
// width: 200%;
}
You doing it wrong
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
Should be:
<td ><textarea cols="500" rows="100"><?php echo $row['Gossip']; ?></textarea>
textarea is html tag name but not input type. so change this.
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
to
<td ><textarea cols="500" rows="100"><?php echo $row['Gossip']; ?></textarea>
also add this css.
<style>
textarea {
resize: both;
width:700px;
}
</style>
also are you sure that you can get content using this.
<?php echo $row['Gossip']; ?>

Make dropdown sort list

I have this php code with a drop down pulling info from the database but cannot seem to figure out how to get the drop down selection to sort the list...
The drop down is showing the course name as the label but when selected needs to sort the list by course id.
Visit Here to see the table in action
<?php
$connect = mysql_connect('localhost','emscompl_paramed','PASSOWRD) or die(mysql_error());
$selectdb = mysql_select_db('emscompl_joom1283',$connect);
$sel = "SELECT us.fullname, s . *
FROM registered_users AS `us`
LEFT OUTER JOIN course_students AS s ON s.userid = us.userid";
$ressel = mysql_query($sel);
$fetchsel = mysql_fetch_array($ressel);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.titiel {
font-weight: bold;
}
td {
border-right-width: thin;
border-bottom-width: thin;
border-right-style: dotted;
border-bottom-style: solid;
text-align:center;
}
th {
background-color:#000000;
color: #FFF;
}
tr:nth-child(odd) { background-color:#eee; }
tr:nth-child(even) { background-color:#fff; }
</style>
</head>
<body>
<p class="titiel">Pre-Entrance Document Report</p>
<p> Please Select Course for Report</p>
<form method="post" action="preentrancereportsorted.php">
<label for="select"><select name="course" value="Select" size="1">
<?php
$sql = "SELECT * FROM courses";
$result = mysql_query($sql) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
$id=$row["id"];
$course=$row["coursename"];
$options.="<OPTION VALUE=\"$id\">".$course;
}
?>
<option>
<? echo $options ?>
</option>
</select>
<input type="submit" name="Submit" value="Generate Report">
</form>
<table width="1246" height="56">
<tr>
<th width="147" height="50">Student Name</td>
<th width="15">R</th>
<th width="18">M</th>
<th width="18">L</th>
<th width="81">Background</th>
<th width="83">Drug Screen</th>
<th width="112">Clear Background</th>
<th width="113">Clean Drug Screen</th>
<th width="97">Student Info</th>
<th width="88">School App</th>
<th width="117">Professional Recomendation</th>
<th width="119">Reasonable Accomadations</th>
<th width="59">Drivers Licesnse</th>
<th width="91">High School Diploma</th>
</tr>
<?php while ($row = mysql_fetch_array($ressel)) { ?>
<td width="146" height="50"><?php echo $row['fullname'];?></td>
<td width="17"><?php echo $row['entrancereadingscore'];?></td>
<td width="17"><?php echo $row['mathscore'];?></th>
<td width="17"><?php echo $row['locatinginfoscore'];?></td>
<td width="84"> <?php echo $row['backcalc'];?></td>
<td width="79"><?php echo $row['drugcalc'];?></td>
<td width="113"><?php if ($row['clearbackground']='1')
{
echo "Yes";
}
else
{
echo "no";
}
?></td>
<td width="114">
<?php if ($row['cleardrugtest']=='1')
{
echo "Yes";
}
else
{
echo "No";
}
?>
</td>
<td width="96">
<?php if ($row['studentinformationsheet']=='1')
{
echo "Yes";
}
else
{
echo "No";
}
?>
</td>
<td width="89">
<?php if ($row['schoolapplication']=='1')
{
echo "Yes";
}
else
{
echo "No";
}
?>
</td>
<td width="118">
<?php if ($row['professionalreco']=='1')
{
echo "Yes";
}
else
{
echo "No";
}
?>
</td>
<td width="119">
<?php if ($row['reasonableaccom']=='1')
{
echo "Yes";
}
else
{
echo "No";
}
?>
</td>
<td width="58">
<?php if ($row['driverlicesnce']=='1')
{
echo "Yes";
}
else
{
echo "No";
}
?>
</td>
<td width="91">
<?php if ($row['highschooldip']=='1')
{
echo "Yes";
}
else
{
echo "No";
}
?>
</td>
</tr>
<?php } ?>
</table>
</body>
</html>
If you want to sort your select box by id, then definitely use "ORDER BY" as Pachonk says above.
Also, I've noticed that your PHP below:
<option>
<? echo $options ?>
</option>
is outputting:
<option>
<option value="Some id">some text
<option value="some other id">some other text
... repeat for all options
</option>
You should remove the first from around the PHP (you are placing an tag in the php echo statement anyway) and place the tag in your php code above so that every has an
like:
$result = mysql_query($sql) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
$id=$row["id"];
$course=$row["coursename"];
$options.="<OPTION VALUE=\"$id\">".$course . "</option>";
^^^^^^^^^^^^^ added these
}
?>
// removed <option>
<? echo $options ?>
// removed </option>
</select>
Of course, you could just have the php in the while clause output your option right there and then too.
Hope that helps in some way.

Categories