broj1 356 Humble servant Featured Poster

My opinion: since you have data for all 12 seats in one row you have to select all entire rows with selected CID and then for each row loop through all 12 seats to see wheter email is not empty and the seat is confirmed. So the following query will get all rows for chosen CID:

$courseQuery = 'SELECT * FROM class WHERE CID = "'.$cid.'"';

and then the following code will send email just to the recipients with email filled in and who confirmed the course:

while ($row = mysql_fetch_array($result))
{
    for($s=1; $s<=12; $s++){

        $email = 's' . $s . 'e';
        $status = 's' . $s . 's';

        if($row[$email] != '' and $row[$status] == 'confirmed') {

            // send email
            mail($email, 'Put subject here', 'Put message here', 'Put From: address here);
        }
    }
}

How to prepare a formated email message was nicely shown in calebcook's post above.

Just a thought: there is a question wheter is it OK to have all seats as fields in one row. Maybe they should be in a new table called e.g. seats and have fields cid, seat_number, email, confirmed (of type boolean with values true/false or 1/0) etc. This way the space would be used more efficiently since only taken seats would be stored. Then you would join the two tables and select by CID and where confirmed equals 1. Just an idea.

broj1 356 Humble servant Featured Poster

What are variables $s1i, $s2i... and $s1s, $s2s... and where they get their values from? Do you get any error messages? What is the structure of the class table?

broj1 356 Humble servant Featured Poster

Apart from slight size increase you will get some redundancy since area code is stored in two fields (not a problem if area codes do not change, but you never know - from this perspective the tbl_id is better candidate for a foreign key) Your destination number could be without the area code, only the local phone number but I doubt you can change this now. You can add a foreign key with an UPDATE query so number of records should not be a problem if there arent too many area codes. You can prepare a php script to run the query.

broj1 356 Humble servant Featured Poster

If you add an area code as a foreign key to billing table then this query might help you:

SELECT `date`,`destination`,`callsec`,`tbl_cost`,`callsec`*`tbl_cost` AS price FROM `fees` RIGHT JOIN billing ON `tbl_code`=`tbl_code_fk`

Note that table names are omitted from the query for simplicity. Also a field name for date is maybe not a good idea since it is mysql function name and can cause errors.

broj1 356 Humble servant Featured Poster

If I get it right you have two tables for billing phone calls. The fees table has area codes and cost for each area code with tbl_id being primary key, the billing table holds data about calls made. The thing is that the tables are not linked with the same data, which means you should have a foreign key in the billing table (eg. tbl_id or tbl_code if it is unique). The area code (tbl_code) is actualy part of destination field but since it is not the same lenght in all records, you can't use a mysql SUBSTRING function to extract it. I would add a foreign key to the billing table (an area code if it is unique or tbl_id). Then the JOIN can be made.

broj1 356 Humble servant Featured Poster

I hope this is what you are looking for:

SELECT fees.tbl_cost FROM billing LEFT JOIN fees ON billing.tbl_code=fees.tbl_fee WHERE billing.tbl_code='011'
broj1 356 Humble servant Featured Poster

Introduce a foreign key in Table B which then have two fields: dst_code_fk with values 011, 012, 013... and fee with values 0.38, 0.55, 0.55... Then use join and if you want to find out a fee for dst_code 011 do it like this:

SELECT table_a.fee FROM table_a LEFT JOIN table_b ON table_a.dst_code=table_b.dst_code_fk WHERE table_a.dst_code='011'

The join type (left, right, inner, outer) depends of structure of your data. There are some nice examples of joins on the web.

broj1 356 Humble servant Featured Poster

Thanks to everyone for suggested improvements (and sorry for late reply since I was away). I must agree with all of them. The script was firstly prepared as to show concept of login to answer a thread and security part was neglected which I admit was wrong. It is too important a subject so it should be included. The following is a version with some improvements and notices.

Main changes:
1. username input cleaned and note added to use regular expression (which depends on username requirements); password not cleaned since it gets hashed
2. queries to create database, table and data removed since they depend on database used
3. table that holds user data renamed to tableofusers (just another little security good practice not to use comon names for tables and fields)
4. session variable not assigned until login is OK (to save hosting resources)
5. additional level of validation added by comparing password hashes in the script not just within the database query
6. username stored in session instead of login status (depends realy on what you need)
7. suggestions for further improvements added in comments
8. typos corrected and some other minor improvements made

There are also other ways of doing the login script of course. Please use this one as a concept and adapt it to your needs, requirements and environment. Also if you use some depreciated features (such as magic quotes) take them into account.

<?php …
broj1 356 Humble servant Featured Poster

Hi cereal

I am looking at sha1() function definition on http://php.net/manual/en/function.sha1.php which says:

string sha1(string $str [, bool $raw_output = false ])

Is it possible to use sha1() with salt?

broj1 356 Humble servant Featured Poster

You are welcome.

broj1 356 Humble servant Featured Poster

Sorry, this was intended to go under tutorials. Might have pushed the wrong button again.

broj1 356 Humble servant Featured Poster

I have prepared a tutorial with example on how to code a login page. It has been submited as a new thread to the tutorial section. It is not yet there though so I am posting the code here as well. Hope it will help you. It is well commented. Everyone is invited to comment on it and suggest improvements.

<?php
/*
Login script example
- displays a form for entering username and password
- checks wheter username and password exist in database and match
- if no match is found, clears the form and displays an error message
- if exactly one match is found, redirects user to another page

Tip: make page look nicer with some CSS

For this login example you will need working database (mySql used here), and
some test data as per instructions below (or you can use phpmyadmin or similar app)

Test data (2 users):

username 1: misterx
password 1: secretpassword1
hashed password1: (d5f835dbe946b420e1dacde0558078b4eee36745)

username 2: mistery
password 2: secretpassword2
hashed password2: (fd021e83bf64b46a2a7b707441dd167bc43749d4)

Prepare database 'mydatabase' with table 'user' and some test data

1. Use this or similar query to create database 'mydatabase'
CREATE DATABASE `mydatabase` ;

2.create DB user named 'testdbuser' with password 'verysecretdbpassword' and
 granthim privileges
CREATE USER 'testdbuser'@'%' IDENTIFIED BY 'verysecretdbpassword';
GRANT ALL PRIVILEGES ON * . * TO 'testdbuser'@'%'
IDENTIFIED BY 'verysecretdbpassword'
WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0
    MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

3. Use this or similar query to create table 'users' in database 'mydatabase'
CREATE TABLE `mydatabase`.`users` …
broj1 356 Humble servant Featured Poster

I have prepared an example of login page which displays a form with inputs for username and password and compares submited values with records in database. If match is found the user is redirected to another page, if not error message is displayed. This example is heavy commented. Hope it helps people who need this kind of script.

Please suggest improvements.

broj1 356 Humble servant Featured Poster

Your code is stil not OK. The credentials validation part is missing. You must check wheter supplied username exists in the database, and wheter password is correct. If both these conditions are true, you set the login condition ($_SESSION='1'). The flag $is_valid is not necessary it was propsed just for clarity.

The logic baicaly is:
1. set the login condition ($_SESSION='0') to false (or 0 in your case), until you check that the user provided correct credentials
2. check for any input from user (line 4)
3. if input exists check if the credentials are OK
4. if credentials are ok, set the login condition ($_SESSION='1') and redirect the user to authorized page
5. if credentials are not OK, do something elese (error mesage, sign up form...)
6. display the table with the login form

I would like to give you an example but am a bit tight with time so I do not promis anything.

broj1 356 Humble servant Featured Poster

Change line 4 to

if(isset($_POST['Submit']) and !empty($_POST['Submit']))
broj1 356 Humble servant Featured Poster

Does the version with double quotes and escaped $ give expected result?

$new_xml = "<?xml version='1.0'?>-<params>-<param><key>\$clubName</key><textValue>" .$club_name;

Please specify what is the expected result.

broj1 356 Humble servant Featured Poster

Change your login page to something like:

<?php
// start a session (always first thing in a script)
session_start();
// initialize session variable with value for not valid login
$_SESSION['loggedin']='0'
// check for form submission (user clicked on submit button)
if($_POST['submit']) {
// check if username and password are OK (query a database)
// and set some flag if OK (i.e. $is_valid = true;)  else set it to false
// ...
// check the flag
if($is_valid) {
// now set the session
$_SESSION['loggedin']='1'
// and redirect to next page 
header("location:page_for_loged_users.php")
} else {
// if the flag is set to false, user credentials were wrong
// redirect to page with an error or with login form or whatever
header("location:page_for_signup_or_error.php")
}
}
?>
//your html code with a login table

There are of course other ways of doing it like doing it all on one page and when wrong credentials were submitted the html code displays an error otherwise a login form.

broj1 356 Humble servant Featured Poster

You should set $_SESSION='1' only after the successful login not in the beginning of the script.

broj1 356 Humble servant Featured Poster

I am not sure if I understood the question but if you do not want to get the green $clubName parsed and replaced with it's value either escape the $ like \$clubName or put the whole string in single quotes and xml attributes in double quotes like:

$new_xml = '<?xml version="1.0"?>-<params>-<param><key>$clubName</key><textValue>' .$club_name;
broj1 356 Humble servant Featured Poster

I am not sure if I can answer that. I presume that $days should be assigned a value which is the difference between the arrival date and the departure date which are two forms back. So in the first form you should save this two dates either in a session ($_SESSION array on the server) or in a cookie or carry them over from form to form with GET (or POST) and hidden fields. But I am only guessing.

broj1 356 Humble servant Featured Poster

You should check the value of $days in the for loop in lines 37 to 42 that generate <option> tag values starting from 0 and up to $days. In generated HTML it is only one value for <option> tag (00). From the code published in your post I can not find where value for $days comes from.

broj1 356 Humble servant Featured Poster

I have clicked on above link, booked a home from 09/04/2011 to 09/08/2011, filled in the form and submited. I got a nice page with my reservation details. I can send you a snapshot but am not sure wheter is it possible through the forum.

broj1 356 Humble servant Featured Poster

Also surround the argument of onclick attribute with escaped double quotes like:

onClick=\"selectAndUpdate('$row1[size]')\"

(this is only recommendation from W3C).

broj1 356 Humble servant Featured Poster

I tried your code and get HTML without an error. The only thing I changed was I surrounded all the indexes of the $row1 array with single quotes like

$row1['SerialNo']
broj1 356 Humble servant Featured Poster

I am not familiar with Joomla. Do send the link maybe someone else might find the cause of the error. I will have time to look at it tomorrow (just about to leave).

broj1 356 Humble servant Featured Poster

Where is the definition of your class Unit? Is it in the include path or should you include it with include() ?

broj1 356 Humble servant Featured Poster

And also set php.ini configuration to display errors or use directive ini_set('display_errors', 1) to set configuration temporarily in a script.

Sorry for broken posts, I am doing many things at once :-)

broj1 356 Humble servant Featured Poster

Also there are two $ signs which are maybe being interpreted as a variable (lines 46 an 47). Try to escape them like this \$ or put string within single quotes.

broj1 356 Humble servant Featured Poster

The first thing I note is the missing ; in line 56 in the above listing.

broj1 356 Humble servant Featured Poster

If session is stored in a filesystem it is stored as plaintext and every user having access to directory can read the session data (at least root and sudoers). If it is saved in a database only users that have access to database and appropriate permisions can read the data.

broj1 356 Humble servant Featured Poster

The HTML code (second snippet) seem not to be generated from the PHP code in the first snippet since PHP code says id='gridRow' (single quotes) and HTML generated is id="gridRow" (double quotes)

I would code like this (all HTML attributes in double quotes):

echo "<tr id=\"gridRow\">
 <td >$count</td>
 <td> <input type=\"checkbox\" onClick=\"selectAndUpdate('$row1[size]')\"></td>
 <td> {$row1[SerialNo]}</td> 
 <td> {$row1[InHouseBranding]}</td> 
 <td> {$row1[BrandCode]}</td> 
 <td> {$row1[size]}</td> 
 <td> {$row1[Pattern]}</td>  
 <td> {$row1[EntryStatus]}</td>   
 </tr>";

Maybe my reply is not directly related to your question but the coding should be correct at first place to make it easier to spot the cause of the problem.

broj1 356 Humble servant Featured Poster

Copy the header-php file in the directory where index.html is and test wheter inclusion works by changing the include line to just

include('header.php');

. If that works than in your previous case the path was not correct.

broj1 356 Humble servant Featured Poster

Try to surround code in header.php with <?php ?> tags.

<?php
<div id="header">
     <h2>1stWebDesigner PHP Template</h2>  
</div>
?>
broj1 356 Humble servant Featured Poster

It is quite easy in PHP. You set form action to the same page and then first check wheter $_GET (or $_POST if method is post) array contain any submited values. The values that exist can be used for the HTML you wish to display below. An example:

if(isset($_GET['select1'])) {
    $HtmlBelow = $_GET['select1'];
}

Note that select element has attribute name="select1". You also have to take care of filtering the data passed from the form.

broj1 356 Humble servant Featured Poster

I use FPDF. On http://www.fpdf.org/ you have nice tutorials.

broj1 356 Humble servant Featured Poster

When you click refresh the form data gets resubmited. What you should do is check in the backend system (i.e a database) wheter submited account already exists.

broj1 356 Humble servant Featured Poster

Use print_r($mysql_result) to se what $mysql_result realy contains. Maybe it is an array.

broj1 356 Humble servant Featured Poster

Possible cause might be an endless loop. Check your for and while loops wheter they end as intended.

broj1 356 Humble servant Featured Poster

Is this the condition you want to check:

if($a < $b || $a < $c)

or in plain english: if $a is less than $b or $a is not greater or equal to $c?

broj1 356 Humble servant Featured Poster

Can you state in plain english what is the condition you want to check?

broj1 356 Humble servant Featured Poster

The difference between exmples is:

The former is using object oriented programming aproach. $DB is an object and Query() is a method of that object. The later is classical procedural approach where mysql_query() is a function. Both do similar task I guess. You in general decide wheter to use object oriented programming or procedural.

Just a note: your question is about PHP and executing SQL statement on MySql database. JQuery, as faras I know, is a Javascript library and hasn't got much to do with PHP and MySql.

broj1 356 Humble servant Featured Poster

In my opinion w3schools is an excelent resource but stays on a basic level. It is good idea to check how same things are done on php.net, sometimes in examples or comments sections you can find very useful stuff. I also used a book PHP6 and MySql Bible published by Wiley which I found very good (also for PHP 5).

broj1 356 Humble servant Featured Poster

Just to add my views of how I do it in a web app that runs on the intranet server. I use the later aprach. I have one PHP class that generates html code for each page on the site. In this class properties are elements of the page (head, body, headings paragraphs, included headers, footers, menus...). Each property can be used with default value or changed by methods. This way all pages have the same look and feel and still be customized programatically if necessary. The benefit is that I have total control over the html code from PHP, depending of user input, user rights and roles, session values etc. The downside might be performance, since server has to generate html for each page, but in my case this is not an issue. Another downside is that you can not use Dreamweaver or Frontpage or similar visual editor. Again not an issue for me since html is always generated by one PHP class.

broj1 356 Humble servant Featured Poster

EDIT: Sory, missed the heredoc tag. Both are correct. It is just a question of style. Either write html tags like in former case or echo them lake in later. ignore my statement below

The former is the correct way. Between the <?php and ?> tags only valid PHP sysntax can be included, otherwise you will get errors.

broj1 356 Humble servant Featured Poster

What is the full path to your script and the full path to your Classes directory?

If Classes is in your script's directory then remove slash before the Classes path.If Classes is somewhere else then set the include path(s) in php.ini so it(they) point(s) to where Classes and other include directories are. The directive in php.ini should look like:

include_path = "full:path1:full_path_2"

Path to php.ini is usually /etc/php.ini.

broj1 356 Humble servant Featured Poster

Your form has form elements with the same name in each row so $_POST array contains only the last set of values I guess. Try to enclose form elements that belong to one row in <form></form> tags (so each form has only one submit button).

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

I am afraid you can't. CSV is as far as I know a text file and can not contain formatting. You should save your data in excel or ods or pdf (or similar) to use formatting.

broj1 356 Humble servant Featured Poster

The second and third link on this page are broken. They open a page saying:

Invalid FAQ Item specified. If you followed a valid link, please notify the administrator

Just thought you might want to know.


Hi, and welcome to TechTalk.

Perhaps the first thing you should do is have a good read of the information contained in our FAQ section:

http://www.daniweb.com/techtalkforums/faq.php?

There you will find:

Forum Rules and policies, Webmaster Information, Privacy policy.

User Maintenance, General forum usage, Reading and posting messages.


There is quite a lot of ...

broj1 356 Humble servant Featured Poster

If you display contents in a table define two CSS classes for row background color - one for even rows and one for odd rows.

.tr_even {background_color: gray;}
.tr_odd {background_color: white;}

Then check the row number and use code:

($row_No % 2) ? echo '<tr class="tr_odd">' : echo '<tr class="tr_even">