minitauros 151 Junior Poster Featured Poster

Well it seems like you already have some code. Is that not working correctly or? Checking if a checkbox is checked, by the way, can be done properly and easily by using .is(':checked') (jQuery, returns true or false).

minitauros 151 Junior Poster Featured Poster

First of all: are you then sure that your query is being executed?

Secondly: seems to me like a query problem, but I'm not sure! Have you tried either

$query = 'INSERT INTO ".$mysql_table." SET username = :username, password = :password, fullname = :fullname, email = :email, role = :role, active = :active, code = :code';

or

$query = 'INSERT INTO ".$mysql_table." (
        username,
        fullname,
        email,
        role,
        active,
        code
    ) VALUES (
        :username,
        :password,
        :fullname,
        :email,
        :role,
        :active,
        :code
    )';

?

minitauros 151 Junior Poster Featured Poster

A little help with that code:

header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="export.csv"');

These headers are sent to the browser, invisible to the end user. A browser always receives headers from a web server, telling it what kind of stuff it is working with. In this case the headers tell the browser that a text/csv file is being given to it, and that it should be offered to the user as a download called export.csv.

minitauros 151 Junior Poster Featured Poster

Apparently your $row_panier['subtotal'] has no value. I guess you could start by finding out why that is =).

minitauros 151 Junior Poster Featured Poster

Nice piece of code :). @topic starter: Just don't forget to contain your database code within a try-catch block if you set PDO's errmode to PDO::ERRMODE_EXCEPTION, as in gabrielcastillo's example.

minitauros 151 Junior Poster Featured Poster

So the user has to check some checkboxes, of which the values will then be converted to .csv and offered as a download? Or are there multiple .csv's available for download, and does the user have to select which of those he wants to download?

minitauros 151 Junior Poster Featured Poster

I guess you could use document.getElementById('loginstate').setAttribute('href', 'url');?

minitauros 151 Junior Poster Featured Poster

Could you add the following code right before your Total input and tell us what it says?

<?php
echo '<p>$shipping1 is now:';
var_dump($shipping1); echo '</p>';

echo '<p>$row_panier[subtotal] is now:';
var_dump($row_panier['subtotal']); echo '</p>';

echo '<p>The same stuff, number formatted is now:';
var_dump(number_format($shipping1 + $row_panier['subtotal'], 2, '.', '')); echo '</p>';
minitauros 151 Junior Poster Featured Poster

What is the error that is being caused?

minitauros 151 Junior Poster Featured Poster

Well, your checkboxes will not be in the $_POST['hidden'] array if they have not been checked. Therefore you cannot set them to 0 using a foreach() loop the way you are using it. You will somehow need to compare the checked checkboxes against the present checkboxes, and work with the difference. Or, you could create two checkboxes: one called "show" and one called "hide", and use those to determine the action of your query.

minitauros 151 Junior Poster Featured Poster

It's probably this:

You use while($row = mysql_fetch_array($result)) to fetch your data, so you cannot use $_SESSION["valid_id"] = $row->id; (an object) to access the fetched data. You should use $_SESSION["valid_id"] = $row['id']; (an array), since you are working with an array, not an object.

Indians commented: you are good at code. its working now. thanks. next i need to do upload employee image and then need to fetch. if i have any doubt i will ask you... +1
minitauros 151 Junior Poster Featured Poster

Well, for as far as I know the ? indicates the start of a query string, while & indicates the start of a new key/value pair inside that query string. E.g.:

website.com?key=value&key2=value2&this=that

The ? indicates the start, the & separates the key/value pairs.

minitauros 151 Junior Poster Featured Poster

Are you getting any errors or is the data not being inserted without giving you a notice/warning/error?

minitauros 151 Junior Poster Featured Poster

As both posters above are saying, you can use a header to redirect the user to another page. Example:

if($row["emp_username"] == $uname && $row["emp_password"] == $pwd)
{
    // Set the header that will redirect the user to the given page
    // when this page's PHP script is done loading.
    header('Location: mainpage.php');

    // Maybe we want to save some variables in a session. In that case,
    // example:
    $_SESSION['login'] = array(
        'user_id' => $uid, // Replace by the ID of the user you're logging in.
        'username' => $uname
    );

    // (In order for the session to work, you need to have used session_start();
    // before).

    // There is no need to output this message, as the user is being
    // redirected anyway, but I'll lave it in tact for you ;).
    echo "Welcome $uname";
}
else
{
    echo "Username and Password do not match";
}

More info about session_start() on php.net: click.

Oh, and a thing to get you started on password encryption: click. Note that this tutorial is using the md5() function, of which the use is strongly unadvised (as it is seen as deprecated by almost everyone), but it will give you an idea of what password encryption is.

minitauros 151 Junior Poster Featured Poster

You could try

<?php  echo number_format($shipping1 + $row_panier['subtotal'], 2, '.', ''); ?>

instead of

    <?php echo ($shipping1 + number_format($row_panier['subtotal'], 2, '.', '')); ?>

as it makes more sense to number format an int instead of number formatting an int to a string and then adding it to another int (as pritaeas says). Of course, both variables need to be set in order to do a sum. If this doesn't work, you could try checking for the presence of a value for both variables, for example:

<?php
echo '<p>The value of $shipping1 is:<br>';
var_dump($shipping1); echo '</p>';

echo '<p>The value of $row_panier[subtotal] is:<br>';
var_dump($row_panier['subtotal']); echo '</p>';
minitauros 151 Junior Poster Featured Poster

For as far as I know, when you do something like this:

<?php echo $shipping1+number_format ($row_panier['subtotal'], 2, '.', ''); ?>

it is not just an echo that is taking place; rather the script is parsed one by one and $row_panier['subtotal'] is added to $shipping1. I think this can easily be fixed by containing your echo in parentheses, example:

<?php echo ($shipping1 + number_format($row_panier['subtotal'], 2, '.', '')); ?>
minitauros 151 Junior Poster Featured Poster

Are you getting an error? Multiple errors? What seems to be the problem?

minitauros 151 Junior Poster Featured Poster

Oh that is because I seem to have made a typo in the for loop construction. It should be for(var i = 0; i < string_length; i++) instead of for(var i = 0; i <= string_length; i++). Hope this helps :)!

PS: I seem to have also made a small mistake in the other PHP script. It should be $new_number = $last_used_number + 1; instead of $new_number = $last_used_number++;.

minitauros 151 Junior Poster Featured Poster

Well, for starters, HBR_EMP_001 doesn't sound pretty random to me ;). If you want to increase a known number-letter combination by one, you could try this code in PHP (and note that this is just an example, working with the idea that your strings will always look like 'HBR_EMP_(number)'):

<?php
$string = 'HBR_EMP_001';
$regex = '/^\w+(\d+)$/';
preg_match($regex, $string, $matches);
$last_used_number = $matches[1];
$new_number = $last_used_number++;
$new_string = 'HBR_EMP_' . (str_pad($new_number, 3, 0, STR_PAD_LEFT));
minitauros 151 Junior Poster Featured Poster

Well with this code, and only this code, I'm getting a bunch of popups with "123" when I scroll:

$(window).scroll(function()
{
    // Let's check the scrollTop just to be sure stuff is working:
    console.log('ScrollTop: ' + $(this).scrollTop());

    if($(this).scrollTop() > 100)
    {
        alert(123);
    }
    else
    {
        alert(321);
    }
});

Have you checked your Firebug to see if any other errors are occurring that may be halting the execution of your script?

minitauros 151 Junior Poster Featured Poster

What is in $faq['slug']? By the way, why aren't you just using PHP to take care of the redirecting process? :) E.g.: redirect everything to index.php, then use $_SERVER['REQUEST_URI'] to find out what needs to be done.

E.g. www.yoursite.com/products/brand/diesel would redirect to index.php, which would then see that the URI is "products/brand/diesel", which information you could then use to PHP-include the appropriate files.

minitauros 151 Junior Poster Featured Poster

Well, it is working for me here, so then I must have falsely assumed you are working with jQuery. If you are working with jQuery, there must be something else going wrong. Did you check your Firebug for Javascript errors?

If you are NOT using jQuery, changing the randomStringToInput() function to this should work:

function randomStringToInput(clicked_element)
{
    var random_string = generateRandomString(10);
    var element = document.getElementsByName('emp')[0];
    element.value = random_string;
    clicked_element.parentNode.removeChild(clicked_element);
}
minitauros 151 Junior Poster Featured Poster

Hmmm I don't know but it seems kind of useless to me to put all this stuff inside a function that doesn't get executed, or does it when you pass it to jQuery? What about trying just:

$(window).scroll(function() {
    // Let's check the scrollTop just to be sure stuff is working:
    console.log('ScrollTop: ' + $(this).scrollTop());

    if ($(this).scrollTop() > 100) {
        alert(123);
    } else {
        alert(321);
    }
});
minitauros 151 Junior Poster Featured Poster

This should work:

<script>
function randomStringToInput(clicked_element)
{
    var self = $(clicked_element);
    var random_string = generateRandomString(10);
    $('input[name=emp]').val(random_string);
    self.remove();
}

function generateRandomString(string_length)
{
    var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var string = '';

    for(var i = 0; i <= string_length; i++)
    {
        var rand = Math.round(Math.random() * (characters.length - 1));
        var character = characters.substr(rand, 1);
        string = string + character;
    }

    return string;
}
</script>

<td><input type="text" name="emp" readonly="readonly" value=""></td>
<td><input type="button" value="Generate Employee Id" onclick="randomStringToInput(this)"></td>

What it does is it uses Javascript to generate a random string of X length, and then sets the value of input[name=emp] to be that random string.

minitauros 151 Junior Poster Featured Poster

Well, have you assigned $dialingCode to a value? In other words, is there some place in some script that says $dialingCode = $_POST['dialingCode'];? :)

You could check the value of $dialingCode by using var_dump($dialingCode);

minitauros 151 Junior Poster Featured Poster

Have you tried adding or die... to your query line? E.g.:

mysql_query(..query..) or die(mysql_error());

minitauros 151 Junior Poster Featured Poster

What happens if you echo your query string? E.g.

echo "INSERT INTO `sikeres` ($fields) VALUES ($data)";
minitauros 151 Junior Poster Featured Poster

EDIT: My bad wasn't reading correctly. Let me take another look :p.

What is the error you are getting?

minitauros 151 Junior Poster Featured Poster

What about a for loop?

<?php
for($i = 0; $i < count($array_1); $i++)
{
    $record_1 = &$array_1[$i]; // The & creates a reference instead of copying the value.
    $record_2 = &$array_2[$i];

    if($record1 == $record_2)
    {
        $record_2 = '000';
    }
}
minitauros 151 Junior Poster Featured Poster

Haha :). You are right in your second post.

function doSomething($value1, $value2 = 'test')
{
    echo $value1 . $value2;
}

// Will output "hellotest"
doSomething('hello');

// Will output "hellohello"
doSomething('hello', 'hello');

However, keep in mind that it is RECOMMENDED to place predefined parameters at the end of your function. I believe you will get a notice in PHP strict if you don't. E.g.:

Don't: function doSomething($value1 = 'abc', $value2, $value3)
Do: function doSomething($value1, $value2, $value3 = 'abc')

mmcdonald commented: Helpful information :D Thank you! +3
minitauros 151 Junior Poster Featured Poster

It queries a MySQL database and, for example, fetches the data you need, or updates it, or deletes it, or creates it. If you need help to start with PHP or MySQL, I guess you'd be better of starting a new topic than asking your questions in this one :).

minitauros 151 Junior Poster Featured Poster

Ah! Yea I didn't really think that it would work like I just described. But I hadn't thought of what you said, yet, either, so this is some insight for me =). Sounds like a neat plan.

minitauros 151 Junior Poster Featured Poster

Every field that has a value gets searched.

How would that work? Because the way I just interpreted that is: a Person object gets constructed with first name Jack and last name Weesl, then how would you use this object to perform a search? I mean, if you already have the person named Jack Weesl, what else could you search for with the data you already have?

minitauros 151 Junior Poster Featured Poster

Maybe you could try this:

$("#inputID").ready(function(){
    $("#inputID input").focus(function(){
        $(this).css("background-color","#fbecc5");
    });

    $("#inputID input").blur(function(){
        $(this).css("background-color","#f5f5f5");
    });

    $("#inputID textarea").focus(function(){
        $(this).css("background-color","#fbecc5");
    });

    $("#inputID textarea").blur(function(){
        $(this).css("background-color","#f5f5f5");
    });
});

I've added "#inputID" to all your jQuery selectors, so that only the inputs inside div#inputID are affected.

minitauros 151 Junior Poster Featured Poster

Sounds like you're on the right track. Seeing the rest of your code I think I would use a function that would convert a query string into a real query. For example if you want to search for WHERE field = value, you could transform an input string like "field=value" into "WHERE field = value". Problem arises when you start thinking about LIKE comparisons.

minitauros 151 Junior Poster Featured Poster

What do you do when you want to retrieve data by something other than ID?

minitauros 151 Junior Poster Featured Poster

Are you using a form to send the query? How is the request being sent?

minitauros 151 Junior Poster Featured Poster

That should work.. :\ Are you sure there are over 4 images in your database?

minitauros 151 Junior Poster Featured Poster

Hm yea for as far as I know the PDO::query() method returns a PDO statement (see also here). I don't know SQLite though. What works for me is this:

try
{
    //open the database
    $db = new PDO('sqlite:iSearch.sqlite');

    $statement = $db->prepare("SELECT Fname , Lname , RegoNo, Model, Color, MobNo, DeskNo, AltMobNo
        FROM Owner
        JOIN Cars ON Owner.id=Cars.Owner_id
        JOIN Contacts ON Owner.id=Contacts.Owner_id
        WHERE RegoNo LIKE :search_rego");
    $statement->bindValue(':search_rego', $search_Rego);
    $statement->execute();
    $result = $statement->fetchAll();

    // close the database connection
    $db = NULL;
}
catch(Exception $e)
{
    echo 'Exception : ' . $e->getMessage();
}

if($result)
{
    // Display results
    foreach($result as $row)
    {
        echo ' This Car Belongs to ';
        echo '<br>' . '<br>';
        echo $row['Fname'] . ' ' . $row['Lname'].'<br>';
        echo $row[ 'RegoNo'] . '<br/>';
        echo $row['Model'] . ' ' . $row['Color']. '<br>' ;
        echo '<br>';
        echo $row['MobNo'] . '<br>' ;
        echo $row['DeskNo'] . '<br>';
        echo $row['AltMobNo'] . '<br>';
    }
}
else
{ 
    // No results were found.
    echo '<p>No results were found.</p>';
}
minitauros 151 Junior Poster Featured Poster

Hm I don't know CI, but that sounds pretty unlogical to me. If you define the class Page as you are doing now, and if you include that class on every page that needs the navigation that it now contains, then there is no problem, right? As it would then contain the hardcoded navigation items that it contains right now each time it is included.

(See also the post above that wasn't there yet when I started typing this message ^^).

minitauros 151 Junior Poster Featured Poster

Hm this sounds like you would have to add an exception for each and every username that is being used in your system, am I right? For example you'd have to add an elseif($part == 'minitauros') {} if I were a user, right? This sounds a bit too complex, if you ask me.

If this is indeed the case, you would probably be better off by checking if the current collection of breadcrumbs is pointing to any user rather than to one user in specific, and to not add any new breadcrumbs if the breadcrumbs are pointing to a user.

Am I on the right track here? :)

minitauros 151 Junior Poster Featured Poster

Doesn't it work if you just add the following?

if($result)
{
    // Results were found.
    foreach($result as $row)
    {
        echo " This Car Belongs to " ;
        echo "<br />"."<br/>";
        echo $row['Fname']." ". $row['Lname']."<br />";
        echo $row[ 'RegoNo']. "<br/>";
        echo $row['Model']." ". $row['Color']. "<br />" ;
        echo "<br />";
        echo $row['MobNo']. "<br />" ;
        echo $row['DeskNo']. "<br />";
        echo $row['AltMobNo']. "<br />";
    }
}
else
{
    // No results were found.
    echo '<p>No results were found.</p>';
}
minitauros 151 Junior Poster Featured Poster
    else if ($part!='user') {
        $this->url .= "/$part";
        $repl = array('_', '...');
        $this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">'.strtoupper(str_replace($repl, ' ', $part)).'</a>';
    }

This appears to skip any $part that is named "user", correct? It seems that there is not another else { } part in your script, so from what I'd expect, the "user" parts should be skipped.

What exactly is happening?

minitauros 151 Junior Poster Featured Poster

Woops, I meant HAVING, of course, not WHERE :).

minitauros 151 Junior Poster Featured Poster

What about adding something like WHERE percent > 0 to your statement? :)

On a side note: I'm not sure if this is an efficient query. I'm not a MySQL expert, but for as far as my knowledge goes I think this query is executing its subquery a lot of times (each time a record is fetched, it has to execute the subquery). Why don't you just make two queries? One fetching the maximum COUNT from lm_users, and then one that fetches all the records. You could use PHP to do the percentage calculations. Anyone here with more information on this?

minitauros 151 Junior Poster Featured Poster

Is it not easier to just let him on your computer for a couple of minutes while you're in class? :) Or aren't you in class?

minitauros 151 Junior Poster Featured Poster

Well I guess it means that you have tried to initate too many connections. You should only construct your PDO object once. After it is constructed, you can work with that object the entire time (except if you need another connection, but I don't think you need that ;)?).

Maybe a better question: what is it that you are trying to make? :)

minitauros 151 Junior Poster Featured Poster

Oh yea I see I have a little mistake in my code. In PDO you bind parameters to values. For example if you have

WHERE field = :field AND field2 = :field2

you still need to tell PDO what :field and :field2 are, which you do using $statement->bindParam(). You are getting the error because you replaced :key by "1". You could use this code instead:

$query = 'UPDATE settings
    SET value = :value
    WHERE id = :id';

// Prepare the statement.
$statement = $db->prepare($query);


// Bind parameters.
$id = 1; // Change to what you want :id to be.

$statement->bindParam(':value', $_POST['value'], PDO::PARAM_STR);
$statement->bindParam(':id', $id, PDO::PARAM_INT); // If this is an integer, you should use PDO::PARAM_INT instead.

By the way, why are you using both the mysql_ functions AND the PDO class to connect to MySQL? :) I recommend using PDO only, as it is more secure.

minitauros 151 Junior Poster Featured Poster

This query:

SELECT value FROM settings WHERE value = "Login Script"

seems a bit odd to me. You are selecting the value field of records of which you already know what the value field contains (namely "Login Script"). It is something like saying:

SELECT "Login Script" AS value FROM settings WHERE value = "Login Script"

Now that must seem a bit odd, does it not? ;) If you want to get the value of value of a record of which you don't know the value of value yet, you should use another field to make a comparison. For example you could use

WHERE anotherfield = "Anothervalue", E.g. WHERE id = 5 or something like that.

As for your update query, I think you have misplaced your WHERE clause (but I'm not sure if it is not allowed to place it before your SET clause). I think it should be something like:

UPDATE settings SET value = "' . $new_value . '" WHERE field = yourvalue

An example:

<?php
// Changed it to include_once() as I think you will only need this file once per page load.
include_once('include/session.php');
$db = new PDO('mysql:host=localhost;dbname=******x2_login', '******x2_login', '********');

/***********************************************************************
Settings
*/

// Do we need to fetch data, or do we need to update data?
if($_POST)
{
    // We need to update data.
    $action = 'update';
}
else
{
    // We need to fetch data.
    $action = 'fetch';
}

switch($action)
{
    case 'fetch':

        // This query may return 1 - unlimited results, as we're …
minitauros 151 Junior Poster Featured Poster

Have you tried any MySQLi tutorials? Like:

http://www.xphp.info/mysqli-tutorial/
or
http://codular.com/php-mysqli
?