1.11M Members

Latest Posts in PHP

Re: in PHP
 
0
 

I've written quite a few of these in my time too. They can be simple - almost a flat table (not recommended, heh heh), or very involved.

You need to get pretty granular (IMO) with each entity. You will most likely be looking to store specific assessment data (e.g. a certain test) for certain classes of certain teachers in certain courses in certain subjects/faculties/departments.

Historical records should be just that - you can create archive tables if you need to. You don't really need them clogging up your oft-accessed tables if you have millions of them. For example, a student-class table:

stud_id | class_id (compound PK)

Could be emptied at the end of every academic year - the data being appended to prev-student-class (same structure). In our "real" school system is called a "rollover".

Give us an idea of the schema that you have so far and what key info you need to store.

Re: in PHP
 
0
 

I'm a bit confused with regard to the use of javascript in all this.
Please correct me if I'm wrong. The process you need is...

User logs into site
User clicks clock-on button
Button now disappears while this user is logged on until roughly the same time the next morning.
The clock-off button is displayed the whole time (after clock-on is clicked) until it itself is clicked.
If clicked before say 06:00 (following day), then no buttons will be shown until that specified time or until 00:00 (midnight) is reached.

The user can log in and out as many times as required - but they will only ever see one button (or perhaps none).

The cosmetic front-end is neither here nor there - the logic behind the DB manipulation is the key component.

settime.php?uid=<?php echo $uid?>

That I do not understand. If the user is logged in (username/password), then passing the user's db id around makes no sense. Use a session variable for this. This is a potential security hole, as a savvy user could just go to the url directly and enter...

settime.php?uid=675
timein.php?uid=675

Of course user #675 is actually not their real id - they're just being malicious.

Re: in PHP
 
0
 

A few other pointers that may prevent you having to come back...

include('dbLogin.php');
$id = trim($_POST['id']);

Suggests that $_POST['id'] is always set. You should make provisions for when this is not true as in direct access via url or curl or form spoofing. Place a redirect as a condition for this case...

if(isset($_POST['id']))
{
    //check for integer - but be careful which function(s) you use, e.g.
    //do you want to accept a string (e.g. itneer with a trailing space)
    //if conditions met...

    include('dbLogin.php'); //no need to include it outside the conditional blocks if it's not being used outside the conditional blocks 
    //...

}else{
    //redirect safely
}

In addition, you seem to be happy that an user can delete any record from the DB, whether that record "belongs" to them or not...

DELETE FROM exams WHERE id = '$id'

Ideally you'd have a session "userid" that would be passed to the query...

DELETE FROM exams WHERE id = '$id' AND user_id = '$userid'

Based on the number of affected rows (result), you'd return true or false to the user.

It should be noted that you are using mysql_* functions. Please consider using mysqli or PDO and the prepared statement object...e.g.

$stmt = $db->prepare("DELETE FROM exams WHERE id = ':id' AND user_id = ':userid'");

And then bind the parameters accordingly.

Re: in PHP
 
0
 

You may find it less burdensome on the server to just spit out json data from the DB and leave the templating/formatting to js/jQuery.

If I were you, I'd set up a set of different scenarios (formatting different aspects on server [including formatting via query] vs. client) and test each for response-completion times.

I know this is going to be unpopular, but you may wish to look at other technologies like Comet, node.js and websockets. Ajax is not particularly suited to this, however, having said that there are a number of excellent implementations out there - I believe Daniweb's own chatrooms are based on Ajax (Dani?)

Re: in PHP
 
0
 

Been on holiday. I didn't check all your code thoroughly, but are you refreshing the message list every 0.5 s?
And your update query is querying all records, not just from the last one?

If you have many users and you're ajaxing every 0.5 s, that could be a lot of calls - very slooow. Do you set a limit on the number of concurrent users?

Can an user have many tabs open all of which show your chat app, all of which are refreshing every 0.5s?

Your server sounds as though it may be very basic/slow, so cutting calls may be a way to speed things up.

When you retrieve messages from the DB as part of your refresh routine, ensure that you grab the last id - hold this in js - and pass it back to the refresh routine so that you're only retrieving new records from there onwards. If you have say a 1000 records, you don't want to be retrieving all 1000 every 0.5 s.

Re: in PHP
 
0
 

If the if($id != ""), try !== instead of != - this is one of the subtle issues that trip up a lot of PHP programmers. See the PHP online documentation about this.

Re: in PHP
 
0
 

pretec.php

<?php
function protect($v) {
    $v = trim($v);
    $v = stripslashes($v);
    $v = htmlentities($v, ENT_QUOTES);
    $v = mysqli_real_escape_string(mysqli_connect('localhost', 'hsn0_chat', 'pkR81ims'),$v);

    return $v;
}
?>

cn.php

<?php
$cn = mysqli_connect('localhost', 'hsn0_chat', 'pkR81ims') or
    die('Unable to connect to server');
mysqli_select_db($cn, 'hsn0_chat' ) or
    die(mysqli_error($cn));
?>

admin_signout_delete_content.php

<?php
session_start();
require('cn.php');
require('protect.php');
$username = protect($_POST['username']);
$username = $_SESSION['username'];

$query = "UPDATE users SET status='disconnected' WHERE username='$username'";
        mysqli_query($cn,$query);

$sql = 'DELETE FROM messages WHERE username="'.$username.'"';

$result = mysqli_query($cn,$sql) or
    die(mysqli_error($cn));
    header('Location:http://www.hsn0.4thgenhost.com/chat1/adminChat.php?logout=admin');
?>

signinout.php

<?php 
require('cn.php');
require('protect.php');

$username = protect($_POST['username']);
$username = $_SESSION['userName'];
$time = date('F.d.Y');

$sql = 'INSERT INTO users
    (username, join_date)
        VALUES
    ("'. $username . '", '.$time.')';
$result = mysqli_query($cn,$sql) or
    die(mysqli_error($cn));

?>

display_messages.php

<?php
session_start();
require_once 'cn.php';
require_once 'protect.php';
date_default_timezone_set("Asia/Karachi");


$fiveMinutesAgo = time() - 1000;

$sql = "SELECT m.*, DATE_FORMAT( message_time, '%h:%i %p')as mtime ,u.role FROM messages m ". 
"JOIN users u on u.username = m.username ORDER BY message_time ASC";
$result = mysqli_query($cn,$sql) or
    die(mysqli_error($cn));

while ($row = mysqli_fetch_assoc($result)) {
    $user = $row['username'];
    $msg_content = $row['message_content'];
    $hoursAndMinutes = $row['mtime'];
    $class = $row['role'];

    echo '<p><cite class="fa fa-user '.$class.'"><b>'. $user .':</b></cite> <output>'. $msg_content .'</output> <time class="fa fa-clock-o time">:' . $hoursAndMinutes . '</time></p>';

}

?>
<style type="text/css">
.time {
    float:right;
    font-size:14px;
}
.admin {
    color:#0B0;
}
</style>

send_messages.php

<?php
session_start();
require_once 'cn.php';
require_once 'protect.php';
if (isset($_POST['username'],$_POST['message'])) {
    $username = $_POST['username'];
    $message = $_POST['message'];
    $time = date('h:i A');

    $date = date('Y-m-d H:i:s');
    $sql = "INSERT INTO messages (username, message_content, message_time) VALUES ('$username', '$message' , '$date')";

    $result = mysqli_query($cn,$sql) or
        die(mysqli_error($cn));
}
?>

signout_delete_content.php

<?php
session_start();
require_once('cn.php');
require_once('protect.php');
//$userNname = protect($_POST['username']);
$userName = $_SESSION['userName'];

$sql = 'DELETE messages, users FROM messages INNER JOIN  users 
        WHERE messages.username = users.username AND messages.username = "'.$userName.'" ';

$result = mysqli_query($cn,$sql) or
    die(mysqli_error($cn));
    header('Location:http://localhost/chat1/chat.php?logout=user');
?>

this is the all php scripts except 2 more files which containing html content of admin and user area and some of php content,

just let me know if you also want to see that files, i did not posted that files cuz I dont neccessary to post that files.

Re: in PHP
 
0
 

I thought your form is suppose to be submitted through ajax. why is it submitting like a regular form?

Is the chat script reading from a text file? If so, take a look at the chat log. I left a message there.

Your site is about 180ms one way from where I'm at. That is pretty slow for a server, but then the chat response is super slow at >2 minutes response time.

We need to see your PHP script as already been suggested above.

I modified a chat script similar to this long time ago, but it was this slow as I can recall.

Re: in PHP
 
0
 

In practice you're checking for widows: if at the end you have only five (or less) rows then you add them to the previous page, if you have more, then you create a new one. Correct?

If yes, then this example should work:

<?php

require_once './pdf.class.php';

# basic settings
$pdf = new PDF();
$pdf->Addpage();
$pdf->SetAutoPageBreak('auto',false);

# generating some random data
# REPLACE these two lines with your $data2 and $header2
for($z = 0; $z < 45; $z++) { $data2[] = array_merge(array($z), range(10, 15)); }
$header2 = array_merge(array('#'), range('A','E'));

# split $data2 in arrays of 20 rows each
$chunked = array_chunk($data2, 20);
$count   = count($chunked);
$i       = 1;

# get the last array
$lastrows   = end($chunked);
$lastcount  = count($lastrows);

if($count > 0)
{
    $state = false;

    foreach($chunked as $rows)
    {
        # avoid to add the last array two times:
        # once merged and once alone in a new page
        if($state === true) break;

        # check last array before looping it
        if($count == $i + 1 && $lastcount <= 5)
        {
            $rows = array_merge($rows, $lastrows);
            $state = true;
        }

        # do not append a new page at the end of this loop
        if($count == $i) $state = true;

        # generate table
        $x = $pdf->GetX();
        $y = $pdf->GetY();
        $pdf->SetXY($x,$y+10);
        $pdf->SetFont('Arial','B',7);
        $pdf->cell(10,10,"Research Scholars(C - Current, P - Graduated)",0,0);
        $pdf->SetXY($x,$y+20);
        $pdf->BuildTable2($header2,$rows);

        # add pages
        if($state === false) $pdf->AddPage();

        $i++;
    }
}

$pdf->Output();

Regarding the code inside:

require_once './pdf.class.php';

Check this link: http://pastebin.com/nKRx4Ryt in practice is part of your code, without changes, you can replace it with you library.

Regarding:

I am unable to put screenshot in this,how to add screenshot in this...

You can upload a file / screenshot by clicking on the fifth icon from the right side of your textarea, check this screenshot:

ea7edbc400e8e1a6d11ce9eddba7c63c

Otherwise, if you have problems use dropbox, imgur, imageshack or a service of this kind to share an example. Hope it helps, bye!

Re: in PHP
 
0
 

Hello @veedeoo,

Sorry to say but your code does'nt work. did you saw my code which i used for time in kindly I request you to let me know how to disable that button once clicked in a day.

Really appreciated

Re: in PHP
 
0
 

If you are new to web development, you really have to get your HTML and CSS skills up to speed before you consider client and server side scripting which gives your site the dynamic features. Fortunately, HTML and CSS is very easy to pick up and learn.

From that point, I'd suggest JavaScript and one of the popular libraries such as jQuery. Fortunately again, its fairly easy to pick up and learn the basics. Advanced JavaScript takes some time and practice, but if you pick up the basics, then you can rely on jQuery to handle the difficult tasks.

From there, move on to the server scripting language of your choice. PHP is a natural choice for many..its open source, lots of online examples, help, etc.., but you can go with ASP.NET, JSP, etc.. You will also need to learn some SQL if you want to store data to really have a data driven site.

Re: in PHP
 
0
 

W3 Schools is one I've used and sometimes still reference. If you're looking for PHP specific things, PHP.net is a good reference but it's not a tutorial site. It's mainly a list of functions and what they do with examples.

Re: in PHP
 
0
 

Well personally i would suggest you Bucky's Room. The very basics of HTML, CSS, PHP and every thing you need.

Re: in PHP
 
0
 

By this do you mean I can use Java as my web server side as well as my application side?

There is an open source called Apache Tomcat. Have you heard about it? It is an open source implementation of the Java Servlet and JavaServer Pages.

If you want to develop this type of application, you can download XAMPP to test your application locally. You will have to host it on a server with a TomCat installed. Otherwise, a VPS is highly recommended.

This isn't really hard to do. I once hosted a Java written application on a thumb drive connected to my laptop's USB when I was an undergraduate student over my school's wireless network ssssh ... I must have said too much already... :)

PHP Tag Cloud