broj1 356 Humble servant Featured Poster

The session_start function must be called before any html is sent. Best place is on very top of the script:

<?php 
session_start();
?>
...
margin-left: 94px;
margin-top: -66px;
margin-left: 94px;
margin-top: -66px;
max-width: 100%;"/></a></h1>
...

See the PHP manual entry for the session_start function, especially the Notes part.

broj1 356 Humble servant Featured Poster

Are you talking about database records? What is the table(s) structure?

broj1 356 Humble servant Featured Poster

OK, I feel bad a little bit for not being slightly more diplomatic and polite since you appear to be new to this forum. The point is that forums like this one work more or less this way: you do a bit of research first (which is usually a lot of googling), then you try to code a bit, and when yu get stuck prepare a concise and focused question(s) and post it here along with corresponding parts of your code. If you do it this way I am sure other members will be more than happy to post solutions here in short time. So please have look the link in my previous post, try to do a basic script and then tell us where you have problems.

broj1 356 Humble servant Featured Poster

Welcome to Daniweb. Please read this sticky.

This is the first hit from duckduckgo search:

http://www.plus2net.com/php_tutorial/php_forgot_password.php

and there are heaps of others. You can find a lot of useful stuff regarding your question on this forum, too.

broj1 356 Humble servant Featured Poster

You should use isset():

if(isset($_POST['delete'])) {
    ...
}
broj1 356 Humble servant Featured Poster

The simplest way is to enclose the whole html table within a form. In each row there is a delete button which is actually an input element with a type="submit". The name attribute of each delete button should be a corresponding ID of the row in the database (typicaly a primary key by which you address the row to be deleted). So hitting a delete button will trigger a request and send the ID of the row to be deleted in a $_POST (or possibly a $_GET but not recommended). All you need in a deleting part of the script to fire a DELETE SQL statement to the database.

The disadvantage of this approach is in that the page gets refreshed on each delete which might be not that user friendly if you wish to delete many rows quickly. Other solutions are to have a checkbox in each row and one delete button for the whole html table or to use Ajax (so the rows get deleted behind the scenes).

Edit: Ajax, as Diafol already suggested above :-)

broj1 356 Humble servant Featured Poster

You are welcome. If there are no more questions please mark the thread as solved. Happy coding in 2015.

broj1 356 Humble servant Featured Poster

You are welcome. Once you have some code or at least a skeleton, post it here so we can offer you more detailed help.

Once you have no more problems please mark the thread as solved. Happy coding in 2015.

broj1 356 Humble servant Featured Poster

Provided that you keep user data in a database, just add a field containing the path to the image. You can provide default image (or two, based on sex) and add a functionality for users to provide their own photos.

broj1 356 Humble servant Featured Poster

The following is a function that will create links to pages. In addition to the First and Last buttons I also added the Next and Prev buttons which might be useful. I avoided mixing html and php code so html statemens are being echoed. The links are wrapped in a div so you can style the elements. Also links are wrapped in span elements, again for styling. The separator between links is customizable but you could get even better look using CSS.

This function works but not everything might be meeting your expectations. It is to show the concept, you fine tune it yourself.

function displayLinks($totalPages, $displayedLinks = 6, $currenttPage = 1) {

    // customizable link separator
    $separator = " | ";

    // when number of pages is less than 6 (or whatever you set it to be)
    if($totalPages < $displayedLinks) {
        $displayedLinks = $totalPages;
    }

    // calculate the first and last page links
    $startPageLink = $currenttPage <= floor($displayedLinks / 2) ? 1 : $currenttPage - floor($displayedLinks / 2);
    $endPageLink = ($currenttPage + $displayedLinks) < $totalPages ? $startPageLink + $displayedLinks : $totalPages;

    if(($totalPages - $endPageLink) < (floor($displayedLinks / 2))) {
        $startPageLink = $totalPages - $displayedLinks;
    }

    // enclose the links in a div so you can style everything
    echo '<div class="pagination-links">';

    // add the 'First' and the 'Prev' buttons if links do not start with 1
    if($startPageLink > 1) {
        echo '<a href="'. $_SERVER["SCRIPT_NAME"] . '?page=1">First</a>';
        echo $separator;
        echo '<a href="'. $_SERVER["SCRIPT_NAME"] . "?page=" . ($currenttPage - 1) . '">Prev</a>'; …
broj1 356 Humble servant Featured Poster

Maybe this is not an answer to your question but I was just wondering why you do not use any of the ready made solutions for pagination. You can find some examples on phpclasses.org (they will want you to sign-up to download the code but I think it is worth it). The advantages are: you have a uniform class that handles pagination (in uniform way) on all pages with many database results, when you change the look of the pagination links the changes will reflect everywhere, you can add customization options through various methods etc. The bad side is that by using some else's solution you do not learn that much.

broj1 356 Humble servant Featured Poster

@imti32: sorry, I meant method (as noted in the text of the post). Correct code is:

<form method="post" id="nl-form" class="nl-form" action="../EMAIL.php">

Thanx for spotting, mate :-).

<M/> commented: Thanks :) +10
broj1 356 Humble servant Featured Poster

I had a quick look at the code and the main error is that you are missing a method attribute in the form, so it defaults to GET, but you are using POST parameters. So change the form line to:

<form action="post" id="nl-form" class="nl-form" action="../EMAIL.php">

There are other errors too, like:

  • if your document is of html5 type then you do not need to use / for closing tags of elements
  • you can not use em tag within the input element, you can style the placeholder using css as shown here
  • the starting div for the container is missing
  • some other missing variables but this might be due to some missing code in your post
<M/> commented: Thanks :) +0
broj1 356 Humble servant Featured Poster

Can you post the whole script that is returning error?

broj1 356 Humble servant Featured Poster

No worries, mate .-) Please mark this as solved. Happy coding in 2015.

broj1 356 Humble servant Featured Poster

Have you installed fpdf correctly so the directory structure is preserved. Font definition files are usually in font subdirectory of the fpdf installation. Check if this is so and if the helveticab.php file exists there.

broj1 356 Humble servant Featured Poster

As said in previous posts: correct the Test_2 method:

public function Test_2($rootName){
    foreach ($this->jsonObj->{$rootName} as $key => $value){
        echo $value->ID;
    }
}

and initialize the $var object before calling methods:

    $var = new JsonMaker("blabla.json");
    $var->Test_1("People");
    $var->Test_2("People");

And it would be wise to add some check for values before using them e.g.:

if(isset($this->jsonObj->{$rootName})) {
...    
}
broj1 356 Humble servant Featured Poster

In the Test_2 method the $rootName is not defined so it won't work.

Anyway, I do not see any added value in your approach. You could do all this just by using json_decode. But if you really want to do it through your custom class then you should have good reasons for that such as provide some custom validations, provide various types of output etc. In the above class i.e. you should check if file exists in the constructor, maybe use setters and getters to set paths and get values etc.

broj1 356 Humble servant Featured Poster

The problem is in the name of the References field (column) which is a Mysql reserved word and should not be used as a field name. If you still wish to use it as a field name you should enclose it in backticks. I would recommend you change it so you avoid possible errors in future.

$sqls = "INSERT INTO saveproposal (ID, PI, Email, RTitle, Coauthors, ExSummary, LReview, Objective, Methodology, EOutput, `References`, RDuration) VALUES (NULL, '$peru', '$email', '$title', '$auth', '$eta', '$pta', '$ota', '$mta','$eota','$rta','$rdt');";

Se the list of mysql reserved words here.

broj1 356 Humble servant Featured Poster

I'll do a bit of guessing here since I do not have experience with MS SQL server. It seems that MS SQL support is not installed in your EasyPHP environment (default is mySql). There is some info on this link on how to do it.

broj1 356 Humble servant Featured Poster

The error is in the generateOrderedArray function which returns resource ID (a special PHP type) instead of an array of student ID numbers. Below is the code that should work (see the coments within).

function generateOrderedArray()
{
    // initialize the return array
    $retArray = array();

    // do the connection stuf
    $db = mysql_connect("localhost", "root", "");
    mysql_select_db("dbehomebooking",$db);

    // query for student ID numbers database
    $query = "SELECT studentid FROM approval";

    // result of querying (resource ID)
    $res = mysql_query($query) or die ('<p>' . mysql_error());

    // put the ID numbers from the database into the return array
    while ($row = mysql_fetch_array($res))
    {
        $retArray[] = $row['studentid'];

        // you can also echo it for testing
        echo '<br>',$row['studentid'];
    }

    // return the array of ID numbers
    return $retArray;
}

The binarySearch function seem to work OK.

Also the html tag on line 3 should be before the form tag.

broj1 356 Humble servant Featured Poster

You can not echo $_SESSION[$banner] if $_SESSION[$banner] has not been set before.

broj1 356 Humble servant Featured Poster

Seems like you posted while I was preparing my answer to the previous question. See my post if it is usefull and understandable.

broj1 356 Humble servant Featured Poster

Edit: Ups, I did not see your post above when writing this.

Cool. My idea is that in the database you would have two tables: one for incident related categories (it will populate the checkboxes - the 15 values in the code above) and one main table for incidents (it will contain an incident numbers and al the checked categories for each incident).

Example of first table (let's call it incident_categories):

cat_id | category
------------------------
1      | Incident data 1
2      | Incident data 2
3      | Incident data 3
4      | Incident data 4
5      | Incident data 5
6      | Incident data 6
...
15     | Incident data 15

Example for second table (let's call it incidents):

incident_id | incident_categories
---------------------------------
1           | [2,8]
2           | [6]
3           | [5,7,14,15]
4           | 
5           | [2,9,11]
...

To save the data after the form was submited the code could look something like:

// do this only if the form was submited
if(isset($_POST['submit'])) {
    // initialize an array for errors
    $errors = array();

    // check if incident number has been input and is valid
    // (i.e. contains only numbers)
    if(isset($_POST['incident-number']) && is_numeric($_POST['incident-number'])) {
        // sanitize it and store it into a variable
        $incident_number = intval($_POST['incident-number']);
    } else {
        // if somethimg is not OK with the entered incident number
        // or if it has not been entered
        // set an error message
        $errors[] = "Error: invalid incident number.";
    }

    // check if any checkboxes have been checked
    // …
broj1 356 Humble servant Featured Poster

If you do not have image ID then $data array is not set. You should check for it before using it, especially in these two lines:

if(isset($data['image']) && isset( $data['newfilename'])) {
    echo $data['image'];
    echo '<div id="updateimage"><img src="images/'.$data['newfilename'].'"  height="250px"></div>';
}
broj1 356 Humble servant Featured Poster

Maybe it should be:

<?php echo $_SESSION['banner']; ?>

but I can't tell without seeing the code where you set the $_SESSION value.

broj1 356 Humble servant Featured Poster

Still does not answer my question: has the $_SESSION['adm_banner.jpg'] been set at all anywhere in the code? Is there a line saying:

$_SESSION['adm_banner.jpg'] = 'something';

or maybe:

$_SESSION[$banner] = 'something';

so you can then echo it. I doubt it is. You probably have an error in your logic. Try to describe what you want to achieve.

broj1 356 Humble servant Featured Poster

OK, again. Where is the $_SESSION['adm_banner.jpg'] getting set?

On line 7 in your first post you assign a value from the database to the $banner variable:

$banner = $data['image_bn'];

Then on line 13 you try to echo the $_SESSION[$banner] variable:

echo $_SESSION[$banner];

From the error message it seems that the value of the $banner variable is adm_banner.jpg. So you are essentially trying to echo the $_SESSION['adm_banner.jpg'] variable. The question is: has the $_SESSION['adm_banner.jpg'] been set at all anywhere in the code? It seem not. I guess you have an error in your logic.

broj1 356 Humble servant Featured Poster

OK. Please mark it solved.

broj1 356 Humble servant Featured Poster

I presume the above code is not the form you want but some example you found somewhere. Following your description this is how I would code it:

<?php 
// define checkbox data here
// (you might read it from the database)
$inicidentData = array(
    1 => 'Incident data 1',
    2 => 'Incident data 2',
    3 => 'Incident data 3',
    4 => 'Incident data 4',
    5 => 'Incident data 5',
    6 => 'Incident data 6',
    7 => 'Incident data 7',
    8 => 'Incident data 8',
    9 => 'Incident data 9',
    10 => 'Incident data 10',
    11 => 'Incident data 11',
    12 => 'Incident data 12',
    13 => 'Incident data 13',
    14 => 'Incident data 14',
    15 => 'Incident data 15'  
);

// check if user clicked the submit button
// you do all the processing on this same page (you could also do it on another page)
if(isset($_POST['submit'])) {
    // you would save this to a database but we will do that 
    // in next step once you are happy with the form
    // for now lets just display what was selected
    echo '<pre>';
    print_r($_POST);
    echo '</pre>';
    exit();
}
?>

<form id="form_919443" class="appnitro" method="post" action="#">
<div class="form_description">
<h2>Incident report</h2>

<div>You are logged in as: <?php echo $UserName; ?>derp</div>

<label class="description" for="incident-number">Incident number</label>
<input id="incident-number" name="incident-number" class="element text medium" type="text" maxlength="255" value=""> 

 <ul>
 <?php 
 // generate checkboxes using php
 foreach($inicidentData as $inKey => $inData) {
     echo '<li><input type="checkbox" name="incident-data[]" value="' . $inKey . '">' . $inData . '</li>';
 }
 ?>
 </ul>

 <input …
JorgeM commented: Great job on your examples and explanations. +12
broj1 356 Humble servant Featured Poster

You have to use a HTML form here. The action attribute of the form should point to the script that will process the data (validate it, sanitize it and store it into the database). The method attribute (get or post) will define how the form will be posted (post method is recommended).

Within the form you will have an input element that will enable users enter the incident number. Give it some meaningful name (such as incident_number).

Also within the form you will have all of your checkboxes. Again use meaningful names so you can refer to the values once processing the data. Each checkboxes label will describe the incident type.

At the end you add a submit button which will trigger the posting action and bring data over to the processing script.

Use CSS3 and HTML5 if you can to lay the elements out and shape everything.

Once you are done with the form post the code here for us to comment and help you go to the next step which is processing the data.

broj1 356 Humble servant Featured Poster

You are missing the ; at the end of line 14

broj1 356 Humble servant Featured Poster

Yes, but where is the $_SESSION['adm_banner.jpg'] being set? If you want to echo it you have to set it first.

broj1 356 Humble servant Featured Poster

Seems like some obfuscated php code. The author probably did not want others to see it without a lot of effort. Might be connected to the copyright notice in the beginning of the script.

broj1 356 Humble servant Featured Poster

Is line 76 of the input_image.php actually a line 13 in the above snippet? If yes, obviously $_SESSION['adm_banner.jpg'] does not exist. Where is it supposed to be set?

broj1 356 Humble servant Featured Poster

Show the code, especialy the part that contains line 7.

broj1 356 Humble servant Featured Poster

I have tested your script and it works OK. This is the data I tested on:

INSERT INTO book (id, bname, aname, pname, description) VALUES 
(1, 'Book 1', 'Author 1', 'Publisher 1', 'Description 1'),
(2, 'Book 2', 'Author 2', 'Publisher 2', 'Description 2'),
(3, 'Book 3', 'Author 3', 'Publisher 3', 'Description 3'),
(4, 'Book 4', 'Author 4', 'Publisher 4', 'Description 4')

To make sure form submits to the same page I changed line 8 to:

<form action="#" method="POST">

What you can do is you can put an echo line just below line 54 and check what queries get generated:

echo "$sql<br>";
broj1 356 Humble servant Featured Poster

You don't have to be offended so quickly. I never said that I am better in PHP than you and I don't care about that anyway. And I was not studying your profile to better understand your question since this is not how this or other forums work. Based on your question which was very broad and a bit hard to understand I just tried to point you in a right direction on what to search. If you studied my profile you would have seen that I often put a lot of effort into helping others and I never tried to put people down. It's just not my style.

Anyway, have you read the guidelines on how to ask a question to get a good answer? Following this might get you to the solution much quicker.

Now, if you are asking a question about accounting stuff, I have no clue about that and really can not help here.

broj1 356 Humble servant Featured Poster
broj1 356 Humble servant Featured Poster

There are many ways: save it (database, json), store it in session, use $_POST/$_GET...

Post what you have so far and describe what you want to achieve.

broj1 356 Humble servant Featured Poster

Repeating: You should put the session_start() command on top of the every script for session to work.

broj1 356 Humble servant Featured Poster

I agree that the lastInsertId() is the safest approach to keep your data consistent. I think it also requires that the ID field is autoincremented/unique so keep that in mind when creating a table.

If you get errors please post the whole error messages (verbatim) here. If you use code from my post above you have to supply valid information (like credentials) to access the database.

broj1 356 Humble servant Featured Poster

You should put the session_start() command on top of the admin.php script for session to work.

broj1 356 Humble servant Featured Poster

For all the database manipulation nad testing it is a good idea to use some database GUI client. Many people use phpmyadmin, a web based client to mysql (mind you, some people hate it, but there are alternatives). I hope you use something like that.

Anyway you can insert first record by hand and it would have a value 0. Then in PHP code always check for the last ID using the corrected SQL statement from my previous post (the one in my previous post has an error in it, sory). This query return the highest ID form the table.

$query = "SELECT task_id FROM tasks ORDER BY task_id DESC LIMIT 1";

I suggest you use PDO to access mysql in PHP. There is a good tutorial here. Do not use the mysql extension which is deprecated and will be kicked out of PHP anytime soon.

This is an example of code for getting new ID. It is not tested and should be adapted for your case. Also any error handling is ommited for clarity

// set up the connection
$db = new PDO('mysql:host=localhost;dbname=<YOURDBNAME>;charset=utf8', '<YOURUSERNAME>', '<YOURPASSWORD>');
// query the database
$stmt = $db->query("SELECT task_id FROM tasks ORDER BY task_id DESC LIMIT 1");
// get the row
$row = $stmt->fetch(PDO::FETCH_ASSOC)
// add 1 to the last ID from the table
$newID = $row['task_id'] + 1;
// insert the new ID tinto the table (you can also use a prepared statement here)
stmt = $db->query("INSERT INTO tasks …
broj1 356 Humble servant Featured Poster

If you get stuck just come back here with as specific question as possible. You might either continue here or mark this thread as solved and start a new one.

broj1 356 Humble servant Featured Poster
broj1 356 Humble servant Featured Poster

OK, I'll try to generate some steps I think would be appropriate and you then correct me where I might be wrong.

  1. A user visits a task request form (say get_task.php)
  2. The form action attribute is e.g. confirmed_task.php
  3. The user fills-in all the necessary information and submits the form
  4. The confirmed_task.php opens up displaying the task ID. It actually does these things:

    • It first reads the last inserted ID from the database i.e. SELECT task_id FROM tasks ORDER BY task_id ASC LIMIT 1
    • It then calculates the new ID like $newID = $lastID + 1 (do some juggling here to get a string in a form of SS000234)
    • It displays the task ID message (i.e. echo "You have been assigne a task# $newID")
    • It sends you an email with the info about the user and the task

If this is what you wanted then tell me which step is making problems.

Also maybe post the database table structure if you have designed it yet.

broj1 356 Humble servant Featured Poster

Before writing a next task to the database you read the last task. However, if the user has the form opened in the browser, there might be a problem displaying the current last inserted task ID, since many tasks could have been inserted after opening the form. You can use ajax to refresh the task ID upon a click of a button or display the newly assigned ID ater the request. Maybe you specify y little your requirement bit more and provide some code you might already have.

broj1 356 Humble servant Featured Poster

The else if part of the code (line 23) should contain a condition.

The rest of the answer is waiting for you here (similar post you started earlier on).

broj1 356 Humble servant Featured Poster

If you want to pass multiple values you can do it this way:

xmlhttp.open("GET","getuser.php?q="+str+"&k="+somevalue,true);

In this case you will always have both q and k elements in the $_GET array. But it is a question of what you really intend to do. Maybe some other approach is more appropriate.