broj1 356 Humble servant Featured Poster

Do a simple debugging. Check if your query is OK. Insert this code after line 19:

die($checksql);

and enter the displayed query in phpMyAdmin (or other client). It should return 0 records or 1 record.

Or check what is the count that the query returns. Insert this code after line 21:

die($count);

It should display 0 or 1.

broj1 356 Humble servant Featured Poster

Dear wenothat,

I would be happy to help you but I think your problem is very complex. I do not have enough time to load an application form the above link (72 scripts) and try to find where you adapted it and what went wrong within this process. If you ask me, it is not a good idea at all to use the such complex code which you do not understand since you can create a lot of risky situations for yourself, your customer, your employer or your provider. My advice is: learn PHP to a level that you understand the working of the application you want to develop/customize and when you have concrete problems ask people on forum (this or others) to help. This is also what the rules of this forum (and most others) say.

This advice is not because I do not want to help but because it is better for you.

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 do you want to achieve (post more info)? Do you get any errors (post them)?

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

You have an error in line 1:

if ( ( "randgames.php", $_SERVER['PHP_SELF'] ) )

The comma (,) is unexpected there but i think you forgot to put the function name:

if ( [B]<some_function_here>[/B] ( "randgames.php", $_SERVER['PHP_SELF'] ) )
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

Make the background of the top image (Home button) transparent. You will need to convert it to png or gif since jpg does not support transparency.

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

You should escape the double quotes in line 4:

echo"<script language=\"javascript\">window.alert('Invalid password.')...
broj1 356 Humble servant Featured Poster

I do not know if this causes the error but you are missing an apostrophe after 75 in height='75.

Also check if $title contain anything.

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

Obviously your PHP code gets displayed instead of processed. Looking at the page source the code is between PHP short tags <? and ?>, which are maybe not allowed on this server. Try to use proper tags: <?php and ?>. Or check if all PHP block tags are in pairs.

broj1 356 Humble servant Featured Poster

@accra:
No. It means $this->total_pages is less than or equal to $this->scroll_pages.

Do not mix property access operator (->) with comparison operators (=>, <=...). See http://www.php.net/manual/en/language.oop5.properties.php.

broj1 356 Humble servant Featured Poster

I think the div has to be in your script all the time not only when you call a function. But it is hard to tell if I do not see the code. Maybe you post the whole script.

broj1 356 Humble servant Featured Poster

I would simply make a div section with the height e.g. 1em for messages that I know will be one line height. The variable for the error message is initialized with empty string and echoed withing the error div block. When an error occurs the error message is set appropriate string and echoed withing the error div block (or sometimes ajax response changes the innerHtml of the error div block).

$errorMessage = '';

if(someErrorCondition) {

    errorMessage = 'Error text';
}

echo '<div id="error-message">' . errorMessage . '</div>';

And in your syle sheet (or inline css):

#error-message {
    height: 1em;
    /* other css declarations here*/
}
broj1 356 Humble servant Featured Poster

You can define the height of the td element in pixels or em.

function myError($text, $kill=0){
    echo "<br><table class='popmessage' align=center cellpadding=5>
    <tr><td style=\"height:50px;\"><center><b>$text</td></tr>
    </table><br>";
    if($kill){include('footer.php');}
    }

This is how the cell will be alwas the same height (unless you display a very long message). I prefer to use divs instead of a table.

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

<= in this case means less than or equal to or in your example:

if the value of attribute $this->total_pages is less than or equal to a value of attribute $this->scroll_pages, then ...

See http://php.net/manual/en/language.operators.comparison.php

Attributes are variables of classes/objects, similar to properties in some other OOP languages. The -> is OOP operator to access properties and methods of an object (similar to a . in other OOP languages).

broj1 356 Humble servant Featured Poster

If this happens in a browser that haven't been used to access the app yet, it is an issue with your code (it's a good idea to test your app in all popular browsers anyway).

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

If I understand correctly you want to have a row clickable. I haven't tested this but I think you could use onclick event for a tr tag and a javascript to open a profile (in a same window or in a new window). Try something like:

$dealerList.="
  <tr bgcolor='#f7f7f7' onclick=\"document.location.href='memberProfiles.php?userId=$userId'\">
  <td height='50px'>...

Pagination is another topic. I use Pear Pager class for that. You can have a look at documentation, examples and code at http://pear.php.net/package/Pager. I found it very powerful and flexible and decided that it is not worth developing my own.

broj1 356 Humble servant Featured Poster

I do not know whether this is done professionally but I'll give it a try.

// change date of admission to unix timestamp
    $adm = strtotime($row['date_of_admission']);
    
    // get current time in a form of a timestamp
    $now = strtotime("now");
    
    // get the difference in seconds
    $diff = $now - $adm;

    // get years from the difference
    $years = floor($diff / (60 * 60 * 24 * 365));
    
    // get months from the difference
    $months = floor(($diff  % (60 * 60 * 24 * 365)) / (60 * 60 * 24 * 30) );
    
    // echo and see if it is OK
    echo "<p>The difference is $years years and $months months.</p>";

Note for improvements: wherever there is a division also check for division by zero. I also calculated months assuming 30 days in a month which is not exactly correct. Check if the dates are in correct format (see http://www.php.net/manual/en/datetime.formats.php). Make sure timezone is correctly set (see http://www.php.net/manual/en/function.date-default-timezone-set.php). Check whether $now is greater than $adm.

broj1 356 Humble servant Featured Poster
<?php ?
// start a html table
echo "<table>";

// suppose you have your query result stored in $result  
while($row = mysqli_fetch_assoc($result)) {

    // suppose this is your user from the database
    $fullName = $row['fullName'];

    // suppose this is user ID that helps constructing a link to where profiles are stored
    $userId = $row['userId'];

    // create link for that row (whatever it is, I'll just make it up)
    $link = "memberProfiles.php?userId=$userId"

    // echo one row
    echo "<tr><td><a href=\"$link\">$fullName</a></td></tr>";
}

// end a html table
echo "</table>";
>

This is just a simple example. It could be improved.

broj1 356 Humble servant Featured Poster

My approach in the application I work on is that PHP generates all the HTML code. I have a class that generates all parts of a page that are not affected by business logic (similar to Pear HTML_Page class, see http://pear.php.net/package/HTML_Page2). This class uses some other classes for footer, header, menus etc. Each script then uses methods of those classes and adds parts that are generated by business logic. This way the application's pages are easily maintainable. Of course I could have achieved this using other techniques like templating system (Smarty) or include files. The way I do it works fine for me since it is giving me plenty of programmatic control. Performance might be affected though, but hasn't been an issue since the application is being accessed over LAN and with limited number of users (20 concurrent users in practice, have tested with 50 and it was performing the same). Maybe this would not be a good solution for a really heavy traffic site.

broj1 356 Humble servant Featured Poster

What do you want to achieve with saving a php block in a variable? If you call this variable you already have to be within <?php ?> tags?

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

You are welcome. Please mark this thread as solved if your question has been answered. Happy coding in 2012.

broj1 356 Humble servant Featured Poster

In your php script that generates pdf you have to override existing method Header() with your code.There are nice examples on their website, see

http://www.tcpdf.org/examples/example_003.phps

To add custom text to the header use the Cell() method.

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

You will have to query the database for number of matches form your dropdowns using COUNT(*) function. You can use a query in mysql for your example similar to:

SELECT COUNT(*) FROM databasename WHERE Country='France' AND Age BETWEEN 18 AND 40 AND Education='High School' AND InterestA='Reading'

Just to give you an idea.

broj1 356 Humble servant Featured Poster

I will try to explain my approach since I also use TinyMCE. I use two divs: the first div holds a textarea (TinyMCE editor), a Save button and a Cancel button. The other div holds edited text as an ordinary paragraph and an Edit button. One div is hidden (display:none) and the other shown (display:block). By clicking on Edit button, the paragraph and Edit button div gets hidden and the textarea (editor) and buttons div gets displayed. By clicking Save or Cancel the editor and buttons div gets hidden, the content saved through ajax and paragraph div gets displayed with updated contents.

All this can be accomplished with Javascript functions. To manage the contents of an editor you have to get the instance of TinyMCE:

var ed = tinyMCE.get(edName)

To get the edited text from the editor use

var contents = ed.getContent();

You send the contents to a saving php script with ajax (this target php script contains code to save to DB). You update the paragraph that displays the contents with the text from the editor.

document.getElementById(contentsDivId).innerHTML = contents;

This is just an explanation of my approach and will hopefully help you in solving your problem.

broj1 356 Humble servant Featured Poster

You could use an obfuscator. It is not a 100% solution and it might create some work when maintaining but it is an option. Have look at http://www.phpprotect.info/.

broj1 356 Humble servant Featured Poster

I can't give you a good answer since I haven't used this feature so far so maybe you should ask in a mysql forum on daniweb instead.

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

And it also depends on the table type (engine) within a database. In mySql it is possible to do it if table type is InnoDb, but not if the type is MyIsam.

broj1 356 Humble servant Featured Poster

If password which is stored in the password database field is hashed (using md5 or sha1 function) then you have to also hash the password provide by the user (typed into a login form) and compare the hashes.

$hashed_password = sha1($passwod);
// ...
$sql = "SELECT * FROM skadate_profile WHERE username='".$userName."' AND password='".$hashed_password."'";

If all stored passwords are 40 chars long and have no reasonable meaning then they have probably been hashed with sha1 which by default produces 40 chars hash.

broj1 356 Humble servant Featured Poster

Let us peep on your code just a little bit. I am sure it is a secret but promise we won't tell anyone.

broj1 356 Humble servant Featured Poster

To export a PDF I use an open source TCPDF library (http://www.tcpdf.org/). It has an excellent page with man examples: http://www.tcpdf.org/examples.php. Hope it helps.

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

Your code is OK. I have been using this approach quite often (e.g. conditionally applying a background colour to a table). What makes you think the code does not work? Maybe the change just isn't visible. Try changing some other attributes to see whether there is any effect. Try:

$bgrPic1 = 'boxshadow1small.jpg';
$bgrPic2 = 'boxshadow2small.jpg';

echo"<div style='background-image: url($bgrPic1);text-align:center; height: 266px; width: 225px; '></div>";
echo"<div style='background-image: url($bgrPic2);text-align:center; height: 266px; width: 225px; '></div>";
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

One way of doing it:

1. On your entry page set up a javascript function that redirects to the page with javascript function hidding and displaying the form divs. If javascript is enabled the visitor will be redirected there and do the quiz.

2. If javascript is not enabled in the visitor's browser he will remain on the entry page which will be the page with no javascript.

The no-javascript page can be done in at least two ways:

1. All the questions are part of one form. The visitor has to pick the answers and at the end submit all of them.

2. Each question can be a separate page and the visitor has links to other questions. You can store intermediate results in a session variable (array) or directly in a database.

broj1 356 Humble servant Featured Poster

My solution was using javascript. If user has javascript disabled the other solution is by submitting a page and using $_GET or $_POST. The bad side is that the page gets refreshed each time the form gets submitted and ylso you have to store intermediate results. The safest way would be to have both options available:

1. check if javascript is enabled/supported
2. if yes use javascript
3. if not revert to submitting forms or let know the user that he can not participate