Bob Hensley 20 Bob's Back!

The example at Rproffitt's link is on the right track. You'll want to reference PHP's Date/Time Supported Date & Time Formats list to ensure MySQL's CURDATE() function returns a date formatted in a manner that works.

Thankfully CURDATE()'s standard output is YYYY-MM-DD is an OK format to work with.

$format = 'd/m/y';

$todaysdate = new DateTime($rowvar['CurrentDate']);
$weekdate = new DateTime($rowvar['WeekStartDate']); 
$perioddate = new DateTime($rowvar['PeriodStartDate']); 

echo $todaysdate->format($format);
echo $weekdate->format($format);
echo perioddate->format($format);

Now obviously I pulled the format out and stored it in a variable, which you may or may not choose to do. If you're running different formats for the various dates, you wouldn't want to. But this way, if you are keeping them the same format, your code follows the DRY principle a bit more.

Bob Hensley 20 Bob's Back!
MySQL Stored Routines: Another Useful Scenario

In a past guide I discussed MySQL stored routines within MySQL. Now I’m back with another guide on MySQL stored routines. And this time it’s a more concrete case; one that you may run into yourself in the future (or maybe you already have)! Let’s jump right on, shall we?

The scenario…

You’re implementing a comments system to your application. Users will be able to comment on articles you and your staff post. A concern arises: explicit comments. It’s something all web developers have to deal with: people being crude and just not decent at all.

How you’re probably handling it right now…

Chances are your first intuition would be to filter explicit words in the application code. Maybe you hard-code the words into an array. Perhaps you put them in the database. Either way, you’d be handling the manipulation within the application code instead of the database.

I’m here to present a different solution!

In data-driven applications there will always be a juggle: how much should be handled by the application and how much by the database itself? I firmly believe that we should pass the buck off on the database anytime it makes sense. And in this scenario, I believe it makes sense.

By using stored routines we can push more responsibility onto the database. Should your application really care about what words are not allowed? I don’t believe so. After all, if the data is clean and secure then …

Bob Hensley 20 Bob's Back!

I'm not.
My idea is: if you want to stop a tsunami(a disease) you have to build a strong, huge concrete wall(a medication), a pebble(a dilution of a dilution?) will have little effect.

I don't believe homeopathy has a place in modern medicine. When you're sick enough that medication is necessary, it's not a matter of activating the "healing system" of your body. It's about augmenting it with chemical agents that will more specifically attack the cause of the illness.

Bob Hensley 20 Bob's Back!

Hi,
I have a question regarding php defined function. I want to see the logic implemented for all the php defined functions. How can I see that. For example I want to see what is the logic behing strstr or how strtolower works.Where can I see in wamp these definitions.
Thanks in advance.

PHP is an open source project. If you want to, you can download the source and look at how those functions are defined. Or you can browse through it via PHP's Github account, found here.

The strstr() function, for example, can be found in ext/standard/string.c:

/* {{{ proto string strstr(string haystack, string needle[, bool part])
   Finds first occurrence of a string within another */
PHP_FUNCTION(strstr)
{
    zval *needle;
    char *haystack;
    int haystack_len;
    char *found = NULL;
    char needle_char[2];
    long found_offset;
    zend_bool part = 0;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|b", &haystack, &haystack_len, &needle, &part) == FAILURE) {
        return;
    }

    if (Z_TYPE_P(needle) == IS_STRING) {
        if (!Z_STRLEN_P(needle)) {
            php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty needle");
            RETURN_FALSE;
        }

        found = php_memnstr(haystack, Z_STRVAL_P(needle), Z_STRLEN_P(needle), haystack + haystack_len);
    } else {
        if (php_needle_char(needle, needle_char TSRMLS_CC) != SUCCESS) {
            RETURN_FALSE;
        }
        needle_char[1] = 0;

        found = php_memnstr(haystack, needle_char,  1, haystack + haystack_len);
    }

    if (found) {
        found_offset = found - haystack;
        if (part) {
            RETURN_STRINGL(haystack, found_offset, 1);
        } else {
            RETURN_STRINGL(found, haystack_len - found_offset, 1);
        }
    }
    RETURN_FALSE;
}
Bob Hensley 20 Bob's Back!

The function getElementsByClassName() needs to be called on a DOM object. Simply put- you need to tell it what it should be searching through. Very often this is the document. But you could limit its scope to a table, a DIV, etc. etc.

var one = document.getElementsByClassName('orange')[0];

Bob Hensley 20 Bob's Back!

Hi all,

I have a contact form. In the message text area the right border is not showing in chrome browser. It is cool in other browsers.
here is the link http://theshortstoriesonline.com/amarnamrub/

Thanks

The issue is stemming from the slideInLeft class on the label housing the textarea. Removing that class actually remedies the issue. Specifically, it's the animation, as removing the -webkit-animation-name property from the class will fix the problem.

It looks like you're using a downloaded animation stylesheet. It may be more worth your time to just apply a patch, instead of trying to locate the root of the issue. One simple patch would be to put the border on the label and remove the border from the textarea. A couple inline styles and you'll be good to go.

Bob Hensley 20 Bob's Back!

how to include Europe time in this code?

All of the information you need can be found within the two links I provided you. For example, if you want to set the timezone to Europe/Rome:

date_default_timezone_set('Europe/Rome');

This isn't a random value, however. I linked you to the page before, but I'll do it again: all timezones supported are listed here.

diafol commented: You can lead a horse to water... heh heh +14
Bob Hensley 20 Bob's Back!

Hope someone can help me, someone has suggested that i change sql to sqli

That person gave you very valuable advice. The original MySQL extension, which you're using, has been deprecated as of PHP 5.5. Development on the MySQL extension ended years ago. Even if you disregard the deprecation you should be aware that it is missing features that make it very worthwhile to convert for (chiefly parameterized statements. Your code is extremely vulnerable to SQL injection attacks; parameterized statements are your solution.

As for your problem:

$b=mysql_select_db("database_name",$a);

This is your problem. In submit_form.php you haven't declared a value for $a. You have in config.php, though. But you don't bring in config.php for over 10 more lines. Fix this by requiring config.php at the top of your script.

Also, you're declaring $b in config.php. No need to do it in submit_for.php as well.

Bob Hensley 20 Bob's Back!

How do you create a spritesheet?

You would use a graphics editing application. Adobe Fireworks is popular for this, Photoshop is always a viable option, GIMP would be a free option, and the list goes on.

A spritesheet is simply one single image containing multiple sprites. Within the game you would load the single spritesheet and then only display one portion at any given appropriate time. It's more efficient to load into memory the single image than dozens more. Hence why spritesheets are used.

So keeping that in consideration: I would grid out the spritesheet into equal sections and ensure no one sprite exceeds said dimensions. Or at least not in a way you cannot effectively account for within your engine.

Bob Hensley 20 Bob's Back!

how can i develop pen pal program through pen pal

I understand what a pen pal is, but I have no clue what you're actually referencing. What is a pen pal program? And what do you mean by "through pen pal?" Are you actually familiar with C++?

Bob Hensley 20 Bob's Back!

Hi, i working on a profile system, each users has their public profile and its directory is in http://website.com/username but the proble is that my root is gonna get a bit messy if all folders of each user is created ther, so i want to put all users folder in a folder name users, but then the url be like http://website.com/users/username

Is it posible to some how when enter http://website.com/username still get the content of http://website.com/users/username

Thanks and sorry for my bad english

This is a good scenario for using Apache's mod_rewrite module. With it you can manipulate the URL and where it actually goes.

In this case you want to redirect everything to the users directory. Below is an example of how to do that. It checks to make sure the request isn't an actual file or directory first. If it is then you'll serve that and not a file in the users directory.

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*) /users/$1
</IfModule>

If the URL entered is (for example) http://domain.tld/someusername, this rewrite rule will actually serve http://domain.tld/users/someusername. The end-user will be none-the-wiser that their request is being modified internally.

Bob Hensley 20 Bob's Back!

I want to become a great programmer and software devolper.

Start now then. Programming is not a career you prepare for strictly through school. I've always said software development is very much a hobbyist profession. If it's not something you enjoy doing or you are not self-driven to learn (and continue learning), then it's not a profession you will succeed in.

Bob Hensley 20 Bob's Back!

if($results = mysql_num_rows($sql_query)) !== 0) //here!!!!

That line is throwing an error because you have closed both parenthesis, but then continued on to use a conditional operator. It looks to me that you attempted to do this:

if (($results = mysql_num_rows($sql_query)) !== 0)

Perhaps most importantly: I would strongly encourage you to stop using the original MySQL extension. As of PHP 5.5.0 the extension has been deprecated. It has not been actively developed in quite a few years. MySQLi or PDO are the recommended alternatives.

Bob Hensley 20 Bob's Back!

What's happening is your queries are erring out. Thus instead of a MySQL resource being returned by mysql_query (), an error is being passed. mysql_num_rows () expects, not surprisingly, a MySQL resource and not such an error.

One of the easiest ways to output this (per chrishea's suggestion) is to use an or die () clause.

$sql = mysql_query ('SQL HERE') or die (mysql_error ());

The result is: if the query fails the or die () will invoke, outputting the contents of mysql_error ().

One final note: you're using the outdated and, now, deprecated MySQL API. Unfortunately many online tutorials/guides are slow to move with the tides. It has been an extremely long time since the original API has been recommended, though. I would strongly encourage you to read up on, and switch over to, MySQLi or PDO. Given you're still very new, MySQLi done procedurally may be your best bet.

Bob Hensley 20 Bob's Back!

what is difference b/w web development & web designing.In which we have better scope or income?

Developers will, per national average, earn a higher salary than designers. That said, the two are entirely different skillsets and require different mentalities. People don't typically choose to go one way or the other due to salary, but rather which jives with their personality and the way their brain functions.

http://www.indeed.com/salary/Web-Designer.html
http://www.indeed.com/salary/Web-Developer.html

Takes those numbers with a grain of salt though. The difference may be even more marginal than Indeed leads one to believe.

Bob Hensley 20 Bob's Back!

In the last two posts above there are bracets missing. So the correct code is:

Mltiple isset () calls are not needed. That's an unnecessary action due to the isset () function being capable of receiving multiple parameters. Reference PHP's documentation on the isset () function.

When multiple parameters are passed to isset () it will return true if all are set or false if any of them are not. Thus it's the same logic as the code you've presented, but removes unnecessary code.

isset ($_GET['submit'], $_GET['test'])

broj1 commented: Thnx for pointing this out +6
Bob Hensley 20 Bob's Back!

We can't solve problems by using the same kind of thinking we used when we created them.
Albert Einstein

I love this quote and feel it can be applied to most anything.

Bob Hensley 20 Bob's Back!

that seem to be a good plan. just one question what is ext?

$ext is referring to the file extension (.jpeg, .png, etc.).

Bob Hensley 20 Bob's Back!

Apple devices have unique user agents, all with their device name within it. For example, an iPhone 5 may have a user agent of Apple-iPhone5C2 (which, by the way, will be most USA-based iPhone 5 users). This can be taken advantage in detecting whether a visitor is using an Apple device. The following script will do just that:

<script>
//<![CDATA[

iosReg = '/apple-[ipod|iphone|ipad]/i';

if (navigator.userAgent.search (iosReg))
{
  // What do you want to do with the Apple device?
}

//]]>
</script>

Fortunately (or unfortunately, in this case) I am an Android user so I cannot test the validity of my RegEx pattern. But it should be fine.

Bob Hensley 20 Bob's Back!

Are you constantly receiving this error or only after submitting the form? If it's constant then the problem lies with you not checking for form submission. Otherwise are you using the correct enctype attribute on the FORM element?

Make sure form submission has taken place prior to working with superglobals such as $_GET, $_POST and $_FILES

if ('POST' === $_SERVER['REQUEST_METHOD'])
{
  // work with the upload
}

Using multipart/form-data enctype

<form method="post" enctype="multipart/form-data">
Bob Hensley 20 Bob's Back!

I am puzzled that so many people actually like that smell enough to buy it. There are so many other scents to put in a can and spray on your body. Why is this one so popular right now? It really has an edge to it and makes your eyes water.

It's cheap and has a remarkable marketing campaign. Put those two elements together and there's little that cannot be accomplished. Including convincing young people to wear something akin to skunk scent.

Going along with your pet peeve, mine has to be people who wear too much cologne/perfume. Whether it smells good or not, there's a such thing as too much. I shouldn't have to smell someone fifty feet away.

Bob Hensley 20 Bob's Back!

Assuming $main_category_p is being set to $_POST['main_category']:

The problem is:

if($main_category_p == "Choose...")

The value attribute of the OPTION is what is sent via HTTP POST. Not the actual display text you're showing the client. That's arbitrary and has no implications beyond presentation. So, given your default value is actually "Choose one", that't what you'd want to be checking for in that IF statement.

Unfortunately, HTML5 doesn't support a placeholder element for SELECT statements. So avoiding this problem entirely is not possible. What I prefer to do, however, is to give the placeholder OPTION an empty value. Then, in PHP, check for a non-empty value. If it's empty, then the user chose the placeholder.

The HTML

<select name="main_cat">
  <option value="">Choose...</option>
  <option value="Apparel">Apparel</option>
  <option value="Home Decor">Home Deco</option>
  <option value="Beauty">Beauty</option>
</select>

PHP

$selected = $_POST['main_cat'];

if ( ! empty ($selected))
  echo $selected;
Bob Hensley 20 Bob's Back!

Break down exactly what you're doing and see if you can spot the logic problem.

if ( ! $email_p) 
{
  $forgot_error .= 'Error - Enter your email address';
}
else if (filter_var ($email_p, FILTER_VALIDATE_EMAIL))
{
  $forgot_error .= "Invalid e-mail address";
}

Your first statement is checking to see if $email_p is not defined; if it isn't, you shoot off the error message.

The second statement is checking to see if $email_p is a valid email address (by format, anyways). If it is, you shoot off an error message.

Do you see the problem now? Your logic doesn't line up with what you're trying to accomplish.

else if ( ! filter_var ($email_p, FILTER_VALIDATE_EMAIL))

Or

else if ( FALSE === filter_var ($email_p, FILTER_VALIDATE_EMAIL))

Whichever style you prefer.