broj1 356 Humble servant Featured Poster

The problem is in lines 7 and 8 of the html file. You are missing '=' sign when assigning name attributes to input elements. This is the correct code:

value one: <input type="text" name="val1" size=10 /><br />
value two: <input type="text" name="val2" size=10 /><br />
broj1 356 Humble servant Featured Poster

What does not work (what would you like to achieve but you havent't yet)?

Your current CSS interpretation:
- the background for the body is a picture background.png
- the picture is fixed (i.e does not scrol when you scroll the contents)
- the picture does not repeat (tile) if background is larger than the picture (provide some compatible background color)
- text is Andalus (specify also more general font,too, such as serif), almost white (#EEEEEE)
- links (visited and unisited) are red
- heading 1 text are underlined (no need to specify font-family again, it is inherited from body)

Mind you, I do not regard myself as an CSS expert. You might get better advice form the Webdesign/HTML and CSS forum here:

http://www.daniweb.com/web-development/web-design/html-and-css/143

broj1 356 Humble servant Featured Poster

I do not know whether this is the cause for your trouble but there are two issues:
1. you start a table row within a list item (<li>) and end it outside the list item; html tags should be nested appropriately
2. putting a table (even if properly nested) within a list item might be valid but a bad idea (unless this is really really what you intended); things might get complicated to maintain so you have to have a good reason to do it

broj1 356 Humble servant Featured Poster

And to add an advice regarding the html code: the html code is OK but it is worth making it XHTML compliant (not a must but a good idea), unless you have a good reason to keep it as it is now. XHTML sode would be more future trouble proof as XHTML is already widely adopted and supported. This amongst other means that all the HTML tags should be in lower case and all tags should be terminated (i.e <br> should be <br />). As I said this is not a requirement just a recommendation.

broj1 356 Humble servant Featured Poster

What is the error message (if any) that you get? Have you checked if the update query gets constructed as expected? Place the following code on line 97 in grade.php:

die($sql);

. It will stop the script at the point where the query is constructed and echo the query. You can have a look at it whether it is syntactically correct and you can paste it in phpmyadmin or mysql client to test it.

broj1 356 Humble servant Featured Poster

You can use nowdoc syntax (requires PHP 5.3):

http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc

Please note that variables will not get parsed.

You could also use a heredoc syntax but I am really not sure whether function keyword gets parsed or not.

broj1 356 Humble servant Featured Poster

It is a good idea to plan ahead as much as possible. The higher the access rights are the higher the role value. As veedeoo suggested it pays if you use values that have enough free values between them so you can always add a new role which fits between two existing roles (ie. 200 for students with more privileges, 600 for teachers -trainees or 800 for administrators who have less rights than supervisors).

You can store the access rights based on the role in a session variable at loging time:

$_SESSION['access_level'] = 700;

and then check it on every page:

if(!isset($_SESSION['access_level']) or $_SESSION['access_level'] < 700) {

    log_this_guy_out();
}

// code for successfully logged in users
// ...
broj1 356 Humble servant Featured Poster

Hopefuly you are using CSS for layout. If yes, you can use different media types and rules: @media screen for normal screen, @media handheld for smaller screens on handeld devices. See:

http://www.w3.org/TR/CSS2/media.html

broj1 356 Humble servant Featured Poster

Post the last version of your code and table structures (or if you wish you can PM the access to your database).

broj1 356 Humble servant Featured Poster

Sorry to come back so late I am pretty busy finishing up a project at work. At the moment I can hardly take time to chat on skype on this subject or to spend too much time (i.e. to set up a database and prepare a code for you). Will try to help with bits and pieces as much as possible.

broj1 356 Humble servant Featured Poster

Seems like we have really a trouble communicating each other our texts :-).

So if I understand correctly:

You have one form to fill in your survey (anketa) where users also select for which city from the list of cities they select answers.

Then you have another form where users can select a city (same list of cities as in the first form) and see some statistics. I do not quite understand what the statistics should show. Is it statistic data for all the answers from the first form?

I think your first form and second form should each be included in own <form> ... </form> tags and have different IDs. Each form should have its own submit button which have to have different names (i.e. submit_vote and submit_stats). Then you have two if blocks when you test for each of two submit buttons.

if($_POST['submit_vote'])
{
// insert vote results in a database

}

if($_POST['submit_stats'])
{
// read results from a database, calculate whatever needed and display statistics

}

Setting the action attribute for each form depends on where do you want users to have results displayed. If this is on another page the above if blocks can be on that page.

If you use the same list of cities twice on the page it would be a good idea to put the cities in an array and generate select elements from that array. The following is a sample (a bit lenghty but easy to …

broj1 356 Humble servant Featured Poster

It does not matter what the name of select is as long as you refer to the same name in the $_POST array.

What is the error you are getting now?

broj1 356 Humble servant Featured Poster

Sorry, I do not understand exactly what you mean. The select element has to have it's name so you can use it once saved in $_POST array (after the form was submitted). If the name of the select element is cities the element of $_POST array will be $_POST and the value will be the name of the city that was selected. You use that name in your query. Results are always displayed on one page (either index.php or any other, depending what you set in action attribute) but since the page is set up dinamicaly from the query result it will always contain the data for different city (the city that the user selected).

If you want to display statistics on different page just set the action to it. Another important thing is that select element for cities should be in it's own form so you separate the collection of data for anketa from viewing statistics.

<form action="view_statistics.php" method="post">

Pokazi statistiku za <select name="cities">
<option value="donji_grad">Donji Grad</option>
<option value="karadjordjev_dud"><a href="karadjordjev_dud.php">Karadjordjev Dud</a></option>
<option value="plavinac">Plavinac</option>
...

</select>
<input type="submit" name="submit_stat" value="Statistika" />
...
</form>

On the page showing statistics for selected city (view_statistics.php) you might have code like:

<?php
// check if statistics form was submitted
if(isset($_POST['submit_stat'])) {

    $city = filter($_POST['cities']);

    // query for getting statistics from anketa table
    // this query might be different since I do not know the data structure and the logic of your app
    // maybe "SELECT COUNT(votes) FROM anketa WHERE location='" . $city"
    $query_c …
broj1 356 Humble servant Featured Poster

First, you have to give name to the select element on line 210 (i.e. cities).

Pokazi statistiku za <select name="cities">

Where do you want to display the statistics? Is it on the same page? If yes then you have to save all the values that user has already filled in, otherwise they can get very anoyed seeing the empty form (the form will empty on submission).

Basicaly the principle is that when you check for form submission with f($_POST['doSubmit'] == 'Submit') you can check whether $_POST exists (userhas selected a city). If it exists you can fire the query and store the result in a string which will be displayed somewhere on the page. Add the following code to your if block on line 6:

foreach($_POST as $key => $value) {
    $data[$key] = filter($value);
}

// check if any value was posted for cities
if(isset($data['cities'])) {

    // query for getting statistics from anketa table
    $query_c = "SELECT * FROM anketa WHERE location='" . $data['cities'];

    // execute the query
    $res = mysql_query($query_c,$link) or die("Error:" . mysql_error());

    // store the result of your query in the $row array
    $stat = mysql_fetch_assoc($res);

    // string for displaying statitics
    $stat_string = '<ul>';

    // $stat array now contains all the fields from anketa table (whatever they are)
    // you can now loop through them using foreach and store them in a string
    foreach($stat as $field => $data) {

        $stat_string .= "<li>$field: $data</li>";
    }

    $stat_string .= "</ul>";
}

Now you can display the string somewhere on …

broj1 356 Humble servant Featured Poster

So you want to select a city at the end of the form and see the statistics for that city (please note: on english version the select element for cities at the end is missing)? Do you want to see results on the same page or on different page (your action attribute of the form is currently set to the index.php)? It would be easier if you post some PHP code here.

broj1 356 Humble servant Featured Poster

Did you use PHP short tags (as it is displayed in your last post)? Maybe your web server is not configured for short tags. Also it might be a good idea to put a whitespace between the tags and PHP code.

broj1 356 Humble servant Featured Poster

Hope you are still interested in help for this :-).

First wrap your select element in form tags and set method (GET) and action (# -> self). Then add a submit button so the form can be submitted (or make the select element autosubmit).

// add <form> tags and a submit button
$submit = '<input type="submit" name="submit" value="Submit" />';

echo '<form method="get" action="#">' . $dropdown . $submit . '</form>';

Next checkfor the existence of a $_GET value in a $_GET array. If it exists the form was submitted and you can use the selected value of the select element to filter the results (use it with WHERE clause in your query).

// if the form was submited
if(isset($_GET['Test'])) {

    // sanitize test somehow
    $test = $_GET['Test'];
    
    // add the filter condition to your query
    $test_query .= " WHERE test=$test";
}

Your code above modified to filter results:

<?php header('Refresh: 30'); ?>

<?php

// query to show all results
$test_query = "SELECT * FROM scores";

// if the form was submited
if(isset($_GET['Test'])) {

    // sanitize test somehow
    $test = $_GET['Test'];
    
    // add the filter condition to your query
    $test_query .= " WHERE test=$test";
}

$con = mysql_connect("localhost","test","test");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("equiscor_equiscoreLive", $con);

// Write out our query.
$query = "SELECT * FROM tests";
// Execute it, or return the error message if there's a problem.
$result = mysql_query($query) or die(mysql_error());
$dropdown = "<select name='Test'>";
while($row = mysql_fetch_assoc($result)) {
$dropdown .= "\r\n<option value='{$row['Test']}'>{$row['Test']}</option>";
} …
broj1 356 Humble servant Featured Poster

Works fine on my system: Fedora 15, Firefox 9, Apache 2.x on localhost. I think it should run on other systems too. What error do you get?. If you look at the page source in the browser is there anything displayed? What do you get if you add some text to the html code such as below?

<html>

<body>

<h1>Do you see HELLO WORLD or just WORLD?</h1>

<?php
echo ("HELLO");
?>

<span> WORLD</span>

</body>

</html>
broj1 356 Humble servant Featured Poster

I think preventing user going back using back button is not a very good idea. Back button is there to help the user navigating and disabling it is like taking a wheel out of a user's car if you know what I mean. I the user goes back to the login page you can tell them that this will log him out but you should still allow him to do it. Just my opinion based on the fact that I have quite a lot of experience with users' browsing habits.

But anyway, yes, you can use session to track valid logged-in users. There are some nice threads on this forum that can show you how.

http://www.daniweb.com/web-development/php/threads/410804
http://www.daniweb.com/web-development/php/threads/349627
...

broj1 356 Humble servant Featured Poster

I put the proposed changes to your code. It is slightly different from what I said in previous post since I become more familiar with your code. Hope this is what you are after and hopefully I haven't introduced some errors :-).

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Vote</title>

</head>

<body>

<?php

    //make connection to the database
    $connect = mysql_connect("localhost", "root","");
    if (!$connect)
    {
        die("database connection failed". mysql_error());
    }   

    //make sure we’re using the right database
    $select_db = mysql_select_db("vote");
    if (!select_db)
    {
        die("database selection failed " .mysql_error());
    }

    $query = "SELECT name, surname, stuID, votes FROM president";
    $result = mysql_query($query) or die(mysql_error());
    
    $row = mysql_fetch_row($result);
    
    //get and print the name, surname, stuID and votes
    while($row = mysql_fetch_array($result))
    {
        // check if the fields in $row contain anything
        if(isset($row[0])) {
            $row0 = $row[0];
        } else {
            $row0 = '';
        }
        
        if(isset($row[1])) {
            $row1 = $row[1];
        } else {
            $row1 = '';
        }
        
        if(isset($row[2])) {
            $row2 = $row[2];
        } else {
            $row2 = '';
        }
        
        if(isset($row[3])) {
            $row3 = $row[3];
        } else {
            $row3 = '';
        }

        // start the form
        echo "<form method=\"post\" action=\"votes.php\">";
        echo "<img src=\"logo.jpg\" width=\"50\"height=\"50\">";
        echo "Name: <input name=\"name\" type=\"text\" value=\"$row0\" />";
        echo "Surname: <input name=\"surname\" type=\"text\"  value=\"$row1\"  />";
        echo "StudID: <input name=\"stuID\" type=\"text\" value=\"$row2\"  />";
        echo "Votes: <input name=\"votes\" type=\"text\" value=\"$row3\"  />";
        echo "<input name=\"Vote\" type=\"submit\" value=\"vote\" />";
        echo "<br/>";
        
        // end the form
        echo "</form>";
    }

    //if vote button is clicked
    if …
broj1 356 Humble servant Featured Poster

First thing: escape double quotes in line 44:

echo "<img src=\"logo.jpg\" width=\"50\" height=\"50\">";

Lines 14 to 18 should go after the if on line 57. When you check whether the form was submited and if it was you can read POST variables and then you will be using the correct value in $stuID.

To avoid possible errors each $row element should be checked for existence before using it (it would be also better to use associative keys in result array). You actualy need only $stuID and you should check it for existence.

if(isset($stuID)) {
   $stuID = trim($_POST['stuID']);

   // do all the database writing here

} else {

   echo 'Error reading form data!';
}

Input element in row 47 has type="int". I do not think such type exists in HTML.

if(isset($row[0])) {
    $row0 = $row[0];
} else {
    $row0 = '';

if(isset($row[1])) {
    $row1 = $row[1];
} else {
    $row1 = '';

if(isset($row[2])) {
    $row2 = $row[2];
} else {
    $row2 = '';

if(isset($row[3])) {
    $row3 = $row[3];
} else {
    $row3 = '';;

//get and print the name, surname, stuID and votes
while($row = mysql_fetch_array($result)) {

    ...

    echo "Name: <input name=\"name\" type=\"text\"  value = \"".$row0."\"  />";
    echo "Surname: <input name=\"surname\" type=\"text\"  value = \"".$row1."\"  />";
    echo "StudID: <input name=\"stuID\" type=\"text\"  value = \"".$row2."\"  />";
    echo "Votes: <input name=\"votes\" type=\"text\"  value = \"".$row3."\"  />";
    echo "<br/>";

    ....
	}
broj1 356 Humble servant Featured Poster

This query indeed contains an error since there is no value for curso field - $row does not return anything - probably since it is outside the first while loop. Depending on what you want you should assign $row either to a variable or to an array within the first while loop and then use it in the second query.

broj1 356 Humble servant Featured Poster

Sorry my mistake. Put that code after line 38 just after the following line:

$sql_prog = "SELECT prog_curso FROM cursos WHERE cod_curso=".$row['cod_curso'];
die($sql_prog);
broj1 356 Humble servant Featured Poster

Put this on line 37 to debug:

die($sql_prog)

It should display your query. Paste it here (and also into myphpadmin to see if it returns anything). I have a feeling that $row['cod_curso'] does not contain what you are expecting.

broj1 356 Humble servant Featured Poster

The line $query_prog = mysql_query($sql_prog, $connect); returns false instead of a valid resource (and stores it in $query). The reason could be error in your sql statement ($sql) or error in your connection ($connect). You should check for existence of a valid resource before running a while loop:

if($query_prog) {

    while($row = mysql_fetch_array($query_prog)) {

        // ...
    }
} else {

    echo 'Something went wrong!';
}

Also check the correctness of your query in phpmyadmin or mysql client

broj1 356 Humble servant Featured Poster

So the code from the second block is actually not in admin.php but in intermediate page. Unset session variable in admin.php if you do not need it anymore otherwise you are running in circles.

unset($_SESSION['page']);
broj1 356 Humble servant Featured Poster

Why do you want to redirect to the admin page if you are already in the admin page?

broj1 356 Humble servant Featured Poster

I do not exactly understand the question. Do you want to update the database with the value that user has enetered in the input box?

broj1 356 Humble servant Featured Poster

Existing textbox values can be changed with javascript. Get the element by it's ID and change its value property:

document.getElementById(myTextBoxId).value = 'This is my new value';
broj1 356 Humble servant Featured Poster

Seems like order_entering.php script is not getting correct values in the POST array. Have you checked what is contained in the $_POST array (as I suggested insert the print_r($_POST) line in the beginning of the second script and tell us what it displays)?

broj1 356 Humble servant Featured Poster

What is actually the error now (post the error message)? Do not forget to comment out line 15 in the second script when testing.

broj1 356 Humble servant Featured Poster

Your select element is named menu_name while you are using the index product_name in the POST array. Check what the indexes in POST array are in add_stock_process.php. Put something like this at the beginning.

print_r($_POST)
broj1 356 Humble servant Featured Poster

Insert the following code after row 17 to check what the query contains:

die(query);

This will display the query in your browser. Then check whether the query contains appropriate values. If yes, copy the displayed query and paste it into phpMyAdmin (or whichever client you use to access your db) to test what it returns. If there are errors correct them or post them here.

One question: shall your query in line 9 not be narrowed to select the quantity for a specific product? Sometnig like:

$sql = "SELECT `quantity` FROM `rpms` WHERE `product_name`='$product_name'";
broj1 356 Humble servant Featured Poster

Yes, I am pretty sure so. PDF file enables you to position text precisely and it will print on many platforms exactly the same. Using TCPDF library you can create a document with all it's properties (page size, format, orientation etc) accurately defined margins and containing cells as per label specifications. Cells are filled then with the data from the database. You can define different font for each label if you wish. The library also takes takes care of creating page breaks.

You can also define what will the output be: a document can be opened in a browser or offered for a download or saved to a predefined location. You can send the PDF to the distribution center (or they can download it from your site) and they can just print it on sheets with labels.

Other option would be that you send them an Excel spreadshet (PHP can create an Excel spreadsheet file) and they use mail merge function to print the labels but that means they must do so me work themselves (preparing and carrying out a mail merge procedure in Word or other text processing program).

broj1 356 Humble servant Featured Poster

The problem might then be in add_stock_process.php file which is called upon submitting the form. Post the code of add_stock_process.php so we can help.

broj1 356 Humble servant Featured Poster

I think PDF file generated from data stored in a database would be the most accurate thing. For generating PDF I recommend using TCPDF library (http://www.tcpdf.org/) which is mature, supported and with plenty of examples. It is worth spending a day or two to learn how to use it.

broj1 356 Humble servant Featured Poster

In line 14 the value should be enclosed with quotes ((X)HTML requirement), which should be escaped (since you double quotes are used as string identifiers), elements of an associative array enclosed in {} and associative index enclosed in single quotes:

echo "<option value=\"{$menu['product_name']}\">{$menu['product_name']}</option>";

If it still does not work check the if $menu has correct (or any at all) values:

print_r($menu);
broj1 356 Humble servant Featured Poster

Just do the session_start() on the very beginning of the script and without the if statement.

broj1 356 Humble servant Featured Poster

You output a lot of html before calling a session_start() which is not OK. Put the call to session_start() at the very beginning of the file not on the line 78 as it is now.

<?php
//start session    
session_start();     

//unset any session data until user submits valid username and password    
// this is correct way not unset($_SESSION), sorry my mistake    
// see http://www.php.net/manual/en/function.session-unset.php    

session_unset();    
session_destroy(); 
?>
<!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>
...

Other errors:
- the <body> tag should immediately follow the </head> tag
- you have two <head></head> blocks in your file

broj1 356 Humble servant Featured Poster

If the error is the same as in your first post you still output some content before calling session_start(). Make sure there is nothing sent (even not a space before a ?php tag) before the call to session_start().

broj1 356 Humble servant Featured Poster

Is there any content sent in your included header.php file? Why don't you move session_start() to the very beginning (line 1)?

<?php
//start session    
session_start();     

//unset any session data until user submits valid username and password    
// this is correct way not unset($_SESSION), sorry my mistake    
// see http://www.php.net/manual/en/function.session-unset.php    

session_unset();    
session_destroy(); 

include("includes/header.php");
?>
broj1 356 Humble servant Featured Poster

You send some html (<body>...) before session_start() which is not allowed (unless you buffer of output or do not use cookie based session). Move session functions to the beginning of the script.

broj1 356 Humble servant Featured Poster

It might be hard to mix PHP code with HTML with this style of programming. You will be more or less limited to generate all HTML code with PHP I guess. Is that what you really want? And what is the role of the line 3 above (initialization of StdClass)? Are the functions methods of the class?

broj1 356 Humble servant Featured Poster

Where do the $p_spice, $p_veg and $p_allergy that you use as conditions in your if statements come from? Shouldn't they be a part of the $row array (like $row)?

I presume the paths to images are OK. There is an error in line 26 where you say

$nut='<img src= src="../Resources/nut.png" ...

These kind of errors happen when copying/pasting. Similar is with your alt="chilli" within each of img tags (even though the image is veg.png or nut.png).

broj1 356 Humble servant Featured Poster

Maybe you should post complete code so we can have a look at it.

broj1 356 Humble servant Featured Poster

Do you have session_start() function at the beginning of your script? If not it won't work. Check the $_SESSION contents with

print_r($_SESSION);

and compare it with the value of $HTML

print_r($HTML);
broj1 356 Humble servant Featured Poster

You are missing a curly bracket at the end of line 9 jn the above code.

$distance = $cities[$_POST['destination']]};
broj1 356 Humble servant Featured Poster

I have made some changes to your code and it works perfectly well in my browser. Changes are in comments.

Main thing is that you should use session_unset() php function to unset the session (I wrongly advised you to use unset($_SESSION) which is not recommended, sorry). See http://php.net/manual/en/function.session-unset.php and also read the comments. The rest is in code which is largely simplified, so it needs to be worked upon before the production! Hope it helps.

index.php (login page)

<?php

    // start session
    session_start();

    // unset any session data until user submits valid username and password
    // this is correct way not unset($_SESSION), sorry my mistake
    // see http://www.php.net/manual/en/function.session-unset.php
    session_unset();
    session_destroy();

?>

<h3>Login</h3>
<form method="post" action="proseslogin.php">

    <div>
    <labelfor="username">Username</label>
    <br />
    <input type="text" name="username" />
    </div>

    <div>
    <labelfor="password">Password</label>
    <br />
    <input type="password" name="password" />
    </div>

    <div><input type="submit" name="submit" value="submit" /></div>

</form>

proseslogin.php

<?php

// start session
session_start();

    $username = $_REQUEST['username'];
    $password = $_REQUEST['password'];

    // *** set login to false not to '' to be consistent with the return value
    // *** of the function periksa()
    $login = isset($_POST['login']) ? $_POST['login'] : false;

    // DEBUG CODE 1
    // uncomment last two lines and you should see the values that were
    // sent by the login form
    //
    // print_r($_REQUEST);
    // die();

//function
function periksa ($username, $password){

    if (($username=="guest") and ($password=="guest")){

        return true;

        } else {

            return false;
        }
    }

// cek
if (periksa($username, $password)) {

    $login=true;

} else {

    echo "Wrong user ID or password!";

    header("Location: index.php"); …
broj1 356 Humble servant Featured Poster

Make sure you do not send any character (not even a space) before header directive on line 9 otherwise the header will not be sent. You can test that if you put the code

if(headers_sent()) {
    echo 'Headers have already been sent';
}

after line 10 on admin.php. If you see this notice than you have sent some contents before sending the headers.

If you post complete code for your pages I can test them in my environment but not before tomorrow since I have to finish a project for the customer tonight. Meanwhile you can put the following code:

print_r($_SESSION);

or

die($_SESSION);

in various places to check wheter the contents of the session is what it should be. Appropriate places would be lines 8 and 12 in admin.php, line 8 in logout.php etc.

broj1 356 Humble servant Featured Poster

On the proseslogin.php page, line 39 shoud make more sense if it was:

$_SESSION['username'] = $username;

so it works for any user.

On the admin.php page do unset first and then redirect (swap lines 9 and 10).

On the admin.php page the condition statement is wrong. It should be:

if(!isset($_SESSION['username']) or $_SESSION['username'] !='guest')

But I am confused here since I assume that guest should not be allowed to access admin page!? So what is really the condition you want to check?