cereal 1,524 Nearly a Senior Poster Featured Poster

You're welcome! If we are done, please mark the thread solved. Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

It seems all these arrays will have the same size, so you can loop them together, for example:

# read size of one of these arrays
$count = count($_REQUEST['gender']);

# loop
for($i = 0, $e = 1; $i < $count; $i++, $e++)
{
    echo "Student #{$e}: Gender: $gender[$i]    / Shoe-Size: $shoe_size[$i] / Clothing Size: $clothing_size[$i] / Heigth: $growth[$i]<br />";
}
cereal 1,524 Nearly a Senior Poster Featured Poster

You could implement this check directly in your PHP application. For example with rlanvin/php-ip library you can do:

$block = new IPBlock::create('111.111.111.111/24');

if($block->contains($_SERVER['REMOTE_ADDR']))
{
    header('HTTP/1.1 403 Forbidden');
    include $_SERVER['DOCUMENT_ROOT'] . '/error403.html';
    exit;
}

Assuming you're using a switch statement, when the case is mypage you run the IP check:

<?php

    switch($_GET['page'])
    {
        case 'mypage':
            # do check here
            break;

        # other code ...
    }

The same, for rewritten links, can be applied through parse_url(). A part this I don't have other ideas, bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Create $friends like this:

foreach($results as $row)
{
    $friends[$row['id']]['first_name'] = $row['first_name'];
    $friends[$row['id']]['last_name']  = $row['last_name'];
}

So you save the user ID as index key of the array, when you want to compare use array_keys() to generate an array of IDs:

$friend_keys = array_keys($friends);

foreach($friend_keys as $key)
{
    if( ! in_array($key, $membersarray))
    {
        echo $friends[$key]['first_name'] . ' ' . $friends[$key]['last_name'];
    }
}

Or simply:

foreach($friends as $key => $value)
{
    if( ! in_array($key, $membersarray))
    {
        echo $value['first_name'] . ' ' . $value['last_name'];
    }
}
cereal 1,524 Nearly a Senior Poster Featured Poster

IF is part of the core since 2.4, while Require is part of mod_authz_core, which is loaded by default and available since version 2.3, at least in debian & co.

Do you think it would be safe to assume majority of Apache servers (shared hosting etc.) would be using Apache 2.4+ by now?

I don't know, I don't have the numbers but I hope so: 2.4 is stable, while 2.2 is in legacy status and updated only for bug fixes and security patches.

There are a lot of differences between 2.2 and 2.4 but, unless using a specific unsupported module, I would always expect to find the latest stable version.

If you're trying to create a safer approach then use IfModule and IfVersion:

<IfModule mod_version>
    <IfVersion >= 2.4>
        <IfModule mod_authz_core>
            # execute code here
        </If>
    </If>
</If>

Or simply check if mod_authz_core is available.

cereal 1,524 Nearly a Senior Poster Featured Poster

what does [8-9] mean exactly?

This is used to define a range. The mod_rewrite module does not support the CIDR notation, in your case you could write:

RewriteCond %{REMOTE_ADDR} ^111\.111\.111\.$

Or:

RewriteCond %{REMOTE_ADDR} ^111\.111\.111\.[0-9]{1,3}$

By using Apache 2.4 there is another alternative: you can use the IF directive with Require, the matching rule would look like this:

<IF "%{REQUEST_URI} ^/mypage/$">
    Require not ip 111.111.111.0/24
</IF>
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi hi!

If considering only Apache you can try with the Location directive:

<Location /mypage/>
    order deny, allow
    deny from 10.0.0.120
</Location>

The applicable context for this directive is server config or virtual host, it means you cannot apply it into the .htaccess file and after each change you need to reload the server:

If you cannot access Apache configuration files, the other solution is to apply a rule to the rewrite conditions, for example:

RewriteCond %{REMOTE_ADDR} =123\.45\.67\.[8-9]
RewriteRule ^/mypage/ - [F]

Check the documentation below, there are several examples:

Note: in the documentation you will read about Denying Hosts in a Blacklist, this is not a perfect solution because all requests are queued and managed by Apache main process, so if you have a lot of connections, it can become a bottleneck.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

with mysqli_connect_errno() you check if there is an error, if yes then, with the same function, you get the error code, which is an integer, while with mysqli_connect_error() you get a string that describes the error.

The error code allows you to easily create a switch statement to perform specific operations, for example:

switch(mysqli_connect_errno())
{
    # unknown database
    case 1049:
        # mail admin, fallback connection
        break;

    # success
    case 0:
        # do not log, connection is fine
        break;

    default:
        # log normally
}

You can find an error list here:

Now, a MySQL error is composed by three elements:

ERROR 1049 (42000): Unknown database 'db_test'
  • the error code which is an integer
  • the SQLSTATE which is a string of five alphanumeric characters
  • the error message, which is a string describing the error

The MySQLi API does not return the SQLSTATE with the connections errors, you get them only with the queries, for example:

# wrong database
$mysqli = @new mysqli('localhost', 'user', 'pass', 'no_database');

if($mysqli->connect_errno)
{
    echo $mysqli->connect_errno . ': ' . $mysqli->connect_error;
    die();
}

# wrong query, replace `no_table` with `dual`
$mysqli->query("select 'abc' as row from no_table");

if($mysqli->errno)
{
    echo $mysqli->errno . ' ['. $mysqli->sqlstate .']' . ': ' . $mysqli->error;
    die();
}

If still in doubt, the SQLSTATE is a standard to define SQL errors. More info here:

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, as long acadCred.courseCode uses the same format of crse.preReq, your query should work fine. Could you show the table structures and some data?

cereal 1,524 Nearly a Senior Poster Featured Poster

What kind of values are returned by crse.preReq in the sub query: integers, CSV?

If CSV then the IN() clause is not the correct solution, because it can return something like this:

IN('2,3', '11,17,20', '5')

In order to work each value should be separated, not grouped by the row result, as in the previous example:

IN('2','3','11','17','20','5')

If this is the case, then you could use CONCAT_WS() in the subquery and FIND_IN_SET() instead of the IN() clause. For example:

SELECT FIND_IN_SET(21, (SELECT CONCAT_WS(',', 3, 12, 17, 21, 26) FROM dual)) AS result;

+--------+
| result |
+--------+
|      4 |
+--------+

Where 4 stands for the position in the subquery result list: anything different from 0 means a match.

Links:

If this is not the case then, please, provide some extra information about the tables and the result sets.

cereal 1,524 Nearly a Senior Poster Featured Poster

Try video.js: http://www.videojs.com/ it is open source.

cereal 1,524 Nearly a Senior Poster Featured Poster

Sorry for my last post, I think it doesn't help much: I'm seeing some weird results from BlueHost DNS server, whatever you search through dig is redirected to the same IP address 74.220.199.6 which is parking.bluehost.com, it doesn't match passhe.edu because they do not redirect any .edu domain, some information here:

So I'm not anymore sure this can be related with your issue. For now, please, do not consider it.

Going back to your script: last check you can do is to search directly their IP:

<?php

    $url = "http://204.235.148.32:8042/cgi-bin/Pwebrecon.cgi";
    print_r(get_headers($url));

With the IP it should work fine and temporarly fix your script, but if the problem is with your hosting DNS then it doesn't solve your issue in case you try to perform a request to another edu domain, for example:

<?php

    $url = "https://search.library.cornell.edu/";
    print_r(get_headers($url));

Anyway, I would still try the dig commands from a terminal in your remote server to evaluate the output and ask if it's possible to enable a forwarding DNS. If the correct IP is displayed then it's not BlueHost but something else like diafol's suggestion.

cereal 1,524 Nearly a Senior Poster Featured Poster

Forgot to add

klnpa.org is reachable from BlueHost DNS, so it may be this the problem, here's the output:

dig @ns1.bluehost.com klnpa.org

; <<>> DiG 9.9.5-3-Ubuntu <<>> @ns1.bluehost.com klnpa.org
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32087
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 2800
;; QUESTION SECTION:
;klnpa.org.                     IN      A

;; ANSWER SECTION:
klnpa.org.              60      IN      A       74.220.199.6

;; Query time: 210 msec
;; SERVER: 74.220.195.31#53(74.220.195.31)
;; WHEN: Tue Nov 25 21:26:39 CET 2014
;; MSG SIZE  rcvd: 54

As you can see there is an Answer Section with the IP address of klnpa.org. Depending on the configuration of your hosting plan, maybe you can add a forwarder DNS to match correctly all the domains, but as suggested in my previous post you may want to ask support to BlueHost.

cereal 1,524 Nearly a Senior Poster Featured Poster

Ah, so as diafol suspected, then, there's something that prevents my server from accessing the Pilot one. (Right?)

Yes, the error of get_headers() helps a bit: failed to open stream: Connection timed out.

I suspect the problem is given by the DNS of Bluehost, which are:

  • ns1.bluehost.com
  • ns2.bluehost.com

By quering passhe.edu through the dig command we can see the domain is not resolved by their DNS servers and so it could not be reachable from your server:

dig @ns1.bluehost.com passhe.edu

; <<>> DiG 9.9.5-3-Ubuntu <<>> @ns1.bluehost.com passhe.edu
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56885
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 2800
;; QUESTION SECTION:
;passhe.edu.                    IN      A

;; Query time: 242 msec
;; SERVER: 74.220.195.31#53(74.220.195.31)
;; WHEN: Tue Nov 25 20:40:23 CET 2014
;; MSG SIZE  rcvd: 39

While by testing through Google DNS we can see it:

dig @8.8.8.8 passhe.edu

; <<>> DiG 9.9.5-3-Ubuntu <<>> @8.8.8.8 passhe.edu
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20522
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;passhe.edu.                    IN      A

;; ANSWER SECTION:
passhe.edu.             899     IN      A       204.235.147.180

;; Query time: 247 msec
;; SERVER: 8.8.8.8#53(8.8.8.8) …
cereal 1,524 Nearly a Senior Poster Featured Poster

I think your setup should support this script.

Check the PHP error log on Bluehost and, if this doesn't help, then check the access & error log of Apache (or of the web server in use), from there you can understand if the problem is PHP or, as suggested, if the access is failing from your server.

A simple test you can do:

<?php

    $url = "http://pilot.passhe.edu:8042/cgi-bin/Pwebrecon.cgi";
    print_r(get_headers($url));

Should return something like this:

Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Date: Mon, 24 Nov 2014 12:01:11 GMT
    [2] => Server: Apache
    [3] => Connection: close
    [4] => Content-Type: text/html
)

At least you make sure it's accessible from your server.

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, here you can see the code and play the example:

Just click on run and then submit the form.

diafol commented: Thanks for the url - new site on me - runnable. Brilliant +15
cereal 1,524 Nearly a Senior Poster Featured Poster

(Or are you guys saying that you were actually able to return something from http://pilot.passhe.edu:8042/ ?)

(yes), it works fine for me, I'm attaching my full examples. If preferred I can paste all the code here.

what I'm asking is, what is there about http://pilot.passhe.edu:8042/ ... that makes it different from other sites that cURL readily scrapes?

Since it works, for me, there is no reason why this link is different from others.

cereal 1,524 Nearly a Senior Poster Featured Poster

@Ryujin

In addition to diafol suggestion :)

There is no specific rule, you have to try the forms to understand the functionality. In the vufind case the first problem is given by the $url, you're targetting the form page, but the action of the form is pointing to another page:

<form method="get" action="/vufind/Search/Results" id="advSearchForm" name="searchForm" class="search">

so to get results $url must be:

https://vf-kutz.klnpa.org/vufind/Search/Results

The method must be GET, because they could verify the request method also, since this is an advanced search form, the receiving script is going to check for more variables, for example, by searching math & euler the minimun query string to send is this:

$data = array(

    'join'              => 'AND',
    'bool0'             => array(
        'AND'
        ),

    'lookfor0'          => array(
        'math',
        'euler',
        ''
        ),

    'type0'             => array(
        'AllFields',
        'AllFields',
        'AllFields'
        ),

    'sort'              => 'relevance',
    'submit'            => 'Find',
    'illustration'      => -1,
    'daterange'         => array(
        'publishDate'
        ),

    'publishDatefrom'   => '',
    'publishDateto'     => ''

);

$body = http_build_query($data);
$url  = "https://vf-kutz.klnpa.org/vufind/Search/Results?".$body;
$results_page = curl($url);

Note lookfor0[], bool0[], type0[], daterange[]: are all arrays for example lookfor0[] can be declared multiple times, but there are some conditions: you have to match each with $type0[]. The above can be rewritten like this:

$data = array(

    'join'              => 'AND',
    'bool0[]'           => 'AND',
    'lookfor0[0]'       => 'math',
    'lookfor0[1]'       => 'euler',
    'lookfor0[2]'       => '',
    'type0[0]'          => 'AllFields',
    'type0[1]'          => 'AllFields',
    'type0[2]'          => 'AllFields',
    'sort'              => 'relevance',
    'submit'            => 'Find',
    'illustration'      => -1,
    'daterange[]'       => 'publishDate',
    'publishDatefrom'   => '', …
diafol commented: sorry c, heh heh, didn't mean to wander off in another direction +15
cereal 1,524 Nearly a Senior Poster Featured Poster

The problem here is that you are defining the array of options for curl without including the POST data:

CURLOPT_POSTFIELDS     => $curl_data,

$curl_data is not defined anywhere, and you're including the input in the url so this becomes a post request with an empty body and the variables in the GET array. What you can do is to prepare the body like this:

$DDCnumber = 873;
$url = "http://pilot.passhe.edu:8042/cgi-bin/Pwebrecon.cgi";

$data = array(
    'DB'            => 'local',
    'CNT'           => 90,
    'Search_Arg'    => $DDCnumber,
    'Search_Code'   => 'CALL',
    'submit.x'      => 23,
    'submit.y'      => 23
    );

$body = http_build_query($data);
$results_page = curl($url, $body);

And add an argument to the function:

function curl($url, $curl_data) {

then it should work fine.

cereal 1,524 Nearly a Senior Poster Featured Poster

Check if in your system there is the php_gmp.dll file, then edit php.ini and append:

extension=php_gmp.dll

Restart Apache and it should work. Check the comments for more information:

Otherwise, if you cannot find the dll file, you can use Math_BigInteger, you can install it by using pear or composer:

pear install Math_BigInteger
composer require pear/math_biginteger

In both cases you need to install the pear client or the composer client:

There's also BC Math which sometimes is shipped with the PHP core installation, but it depends a lot on the PHP version in use, I'm not sure about Windows situation. All these libraries treats the numbers as strings, which gives you the ability to not be limited by the CPU architecture. Math_BigInteger, when available, will use GMP or BC_Math to speed up the execution.

Example:

<?php

    require_once '/path/vendor/autoload.php';

    $a = new Math_BigInteger(rand(0,100), 10);
    $b = new Math_BigInteger(md5('test'), 16);

    echo $a->bitwise_xor($b);

By the way, I'm not sure this example is what you need, I'm just replicating my first example ^_^'

edit

I was forgetting, Math_BigInteger is also available on GitHub:

Just donwload library and include it in your script. This does not require for you to install pear or composer... bye!

diafol commented: great post! +15
cereal 1,524 Nearly a Senior Poster Featured Poster

@Lokesh_4 open a new thread, explain the issue and show the code.

cereal 1,524 Nearly a Senior Poster Featured Poster

Assign height and width to the #banner-background:

#banner-background {
    width:100%;
    height:100px;
    background: url('/images/banner.jpg') no-repeat top left scroll;
}

Then, if you want, you can assign the background directly to the parent div of the inputs:

<div id="banner-background">
    <input type="text" class="form" name="email">
    <input type="text" class="form" name="password">
</div>
cereal 1,524 Nearly a Senior Poster Featured Poster

Maybe:

$xor1 = gmp_init(md5('test'), 16);
$xor2 = gmp_init(decbin(rand(0, 100)), 2);
$xor3 = gmp_xor($xor1, $xor2);

echo gmp_strval($xor3);

?

cereal 1,524 Nearly a Senior Poster Featured Poster

Yup, use the Geocoding API, you can use cURL or simply file_get_contents(), an example:

<?php

    # geocoding
    $api = 'YOUR_SERVER_API_KEY';
    $url = 'https://maps.googleapis.com/maps/api/geocode/';
    $format = 'json';

    $paramenters = array(
        'address' => $_GET['address_line'],
        'key'     => $api
    );

    $submit   = $url . $format . '?' . http_build_query($paramenters);
    $response = json_decode(file_get_contents($submit), true);

    print_r($response);

The format can be either json or xml. Note: the Geocoding API is meant for server side operations, not for direct client access, for that as suggested in the documentation there is another API.

For more information read this:

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi! Define the namespace in Spotify.php:

<?php namespace Foo\Bar\Baz;

class Spotify
{
    public function __construct()
    {
        echo "yes"; 
    }
}

Then it should work fine.

diafol commented: Big hand. Thank you +15
cereal 1,524 Nearly a Senior Poster Featured Poster

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables

It happens because of:

$sql->bind_param('ss', $uname);

Since you're binding only one variable, which is string, you have to pass only one s:

$sql->bind_param('s', $uname);

s stands for string, if the value is an integer then it would be i, f for floats and b for blobs.

cereal 1,524 Nearly a Senior Poster Featured Poster

The real_escape_string method is part of mysqli, so to use it append it to the database object: $conn->real_escape_string($uname).

But don't rely on this for security you have to validate the input, then sanitize and use prepared statements:

$uname = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS);
$pword = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_SPECIAL_CHARS);

$query = $mysqli->prepare("SELECT * FROM users WHERE name = ? AND email = ?");
$query->bind_param('ss', $uname, $pword);

$query->execute();
$query->store_result();

if($query->num_rows > 0)
{
    # create session for valid user & redirect to profile
}

else
{
    # error, not found
}

Docs about sanitization of the input:

Docs about prepared statements:

cereal 1,524 Nearly a Senior Poster Featured Poster

Cannot find column [year]

Does the column year exists it the queried tables? Have you tried to perform the same queries directly in a MySQL client?

cereal 1,524 Nearly a Senior Poster Featured Poster

It depends on what you want to do, you could remove the container and add it again, just place another node to define in which area of the page you want to add the new empty container, in this case the html page will be:

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
</head>
<body>

    <div id="container"></div>
    <div id="marker"></div>

</body>
</html>

The new script is this:

<?php

$file = "./test.html";
$imgs = glob('../images/*.jpg');

$dom = new DOMDocument();
$dom->preserveWhiteSpace = true;
$dom->formatOutput = true;
$dom->loadHTMLFile($file);

$container = $dom->getElementByID("container");

if($container != null && $container->hasChildNodes())
{
    # remove the container
    $parent = $container->parentNode;
    $parent->removeChild($container);

    # create new container
    $container = $dom->createElement("div");
    $container->setAttribute("id", "container");

    # insert the new container before a specific node
    $marker = $dom->getElementByID("marker");
    $parent->insertBefore($container, $marker);
}

if(count($imgs) == 0 || $imgs === false)
    die('Error: glob is failing.');

# populate the new container
foreach($imgs as $img)
{
    $basename = pathinfo($img, PATHINFO_BASENAME);
    $tag = $dom->createElement("img");
    $tag->setAttribute('src', '/images/'.$basename);
    $container->appendChild($tag);

    # appending new lines and tabs
    $br = $dom->createTextNode("\n\t");
    $container->appendChild($br);

    $tag = null;
    $br  = null;
}

$dom->saveHTMLFile($file);

This is the easy method, but if you want, you can compare each child node values with the glob array to perform only specific operations, for this check:

Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

The meta tag is added automatically, just specify your own flavour to avoid a change of charset, for example:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Test</title>
</head>
<body>

    <div id="container"></div>

</body>
</html>

The fact that the tags are not added to the container means that glob() return an empty array or false. Before the loop you can add this check:

if(count($imgs) == 0 || $imgs === false)
    die('Error: glob is failing.');

Complete example:

<?php

$file = "./test.html";
$imgs = glob('../images/*.jpg');

$dom = new DOMDocument();
$dom->loadHTMLFile($file);
$container = $dom->getElementByID("container");

if(count($imgs) == 0 || $imgs === false)
    die('Error: glob is failing.');

foreach($imgs as $img)
{
    $basename = pathinfo($img, PATHINFO_BASENAME);
    $tag = $dom->createElement("img");
    $tag->setAttribute('src', '/images/'.$basename);
    $container->appendChild($tag);

    $tag = null;
}

$dom->saveHTMLFile($file);
cereal 1,524 Nearly a Senior Poster Featured Poster

You could use the DOMDocument class:

An example:

<?php

$file = "./test.html";
$imgs = glob('../images/*.jpg');

$dom = new DOMDocument();
$dom->loadHTMLFile($file);
$container = $dom->getElementByID("container");

foreach($imgs as $img)
{
    $basename = pathinfo($img, PATHINFO_BASENAME);
    $tag = $dom->createElement("img");
    $tag->setAttribute('src', '/images/'.$basename);
    $container->appendChild($tag);

    $tag = null;
}

$dom->saveHTMLFile($file);

By using the method getElementByID() you can define a container in your HTML in which append each new element, so the base for test.html of the above example is:

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
</head>
<body>

    <div id="container"></div>

</body>
</html>

Note: the doctype is important, otherwise it will add HTML 4.0.

cereal 1,524 Nearly a Senior Poster Featured Poster

What you don't understand?

cereal 1,524 Nearly a Senior Poster Featured Poster

In order to perform multiple updates you have to submit the fields of the form as array groups, for example:

<form action="" method="post">
<table>
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Size</th>
            <th>Qty</th>
            <th>Price</th>
        </tr>

    <tbody>
        <tr>
            <!-- group 0 -->
            <td><input type="text" readonly name="product[0][id]" value="23" /></td>
            <td><input type="text" name="product[0][name]" /></td>
            <td><input type="text" name="product[0][size]" /></td>
            <td><input type="text" name="product[0][qty]" /></td>
            <td><input type="text" name="product[0][price]" /></td>
        </tr>
        <tr>
            <!-- group 1 -->
            <td><input type="text" readonly name="product[1][id]" value="72" /></td>
            <td><input type="text" name="product[1][name]" /></td>
            <td><input type="text" name="product[1][size]" /></td>
            <td><input type="text" name="product[1][qty]" /></td>
            <td><input type="text" name="product[1][price]" /></td>
        </tr>
</table>

    <input type="submit" name="button" value="update" />
</form>

When you print the $_POST array you get:

Array
(
    [product] => Array
        (
            [0] => Array
                (
                    [id] => 23
                    [name] => Apples
                    [size] => 1
                    [qty] => 10
                    [price] => 6
                )

            [1] => Array
                (
                    [id] => 72
                    [name] => Oranges
                    [size] => 2
                    [qty] => 17
                    [price] => 8.90
                )

        )

    [button] => update
)

At this point you can loop $_POST['product'] to update each product separatedly:

foreach($_POST['product'] as $product)
{
    echo $product['id'] . $product['name'] . '... and so on';
}

Best would be to use prepared statements so you can create the update query and then just loop the execution with the parameters.

cereal 1,524 Nearly a Senior Poster Featured Poster

Ron, if you are performing an ajax request within the modal window then show us the javascript code you're using, that way we can suggest an appropriate solution.

But diafol suggested that the error is already there, it does not depend on the execution of the modal window, because the undefined index error happens in the server side.

This error should say something else, not only undefined index but also the index name, the script name and line error, for example:

<?php

    $a = array();
    echo $a['id'];

Will generate a notice:

PHP Notice:  Undefined index: id in /tmp/test.php on line 4

By checking the html source received by the browser you should be able to see the entire error and understand if this is generated by the absence of $_GET['id'] or of a column requested from the query result set.

cereal 1,524 Nearly a Senior Poster Featured Poster

Can you post the exact error? Undefined index regarding which array: $_GET, $_POST, $row?

cereal 1,524 Nearly a Senior Poster Featured Poster

Check the value of LimitRequestBody in the Apache configuration file, every request larger than this limit will be blocked, PHP will not even reply. After you adjust the value reload Apache, otherwise the change will not apply.

Docs: http://httpd.apache.org/docs/current/mod/core.html#limitrequestbody

By the way: if you check the response headers to the upload request, when hitting the server limits you should receive the 413 - Request entity too large error, so as previously suggested the error and access logs of Apache can be usefuls sources to track down the error.

cereal 1,524 Nearly a Senior Poster Featured Poster

Try with preg_match():

function validateScore($score)
{
    $score = trim($score);
    $pattern = '/^\d{1,2}[\s]?-[\s]?\d{1,2}$/';
    return preg_match($pattern, $score) == 1 ? true : false;
}

Valid inputs are:

var_dump(validateScore('2-0'));
var_dump(validateScore('2- 0'));
var_dump(validateScore('2 -0'));
var_dump(validateScore('2 - 0'));

Spaces around the string are removed by trim(). To validate only those without spaces between the dash change the pattern to:

$pattern = '/^\d{1,2}-\d{1,2}$/';

preg_match() returns integers 1 for true, 0 for false, the above function, instead, will return booleans. The flag \d will search for digits, {1,2} limits the range to 0-99.

cereal 1,524 Nearly a Senior Poster Featured Poster

You can use mysqldump:

mysqldump -uUSER -pPASSWORD DATABASE > backup.sql

Change USER, PASSWORD and DATABASE to match yours, you can add --routines to backup user defined functions and procedures.

More information here:

cereal 1,524 Nearly a Senior Poster Featured Poster

Check this link:

In practice you have to save the current position for each user and calculate the distance through a database query.

Note MySQL supports spatial indexes only with MyISAM and InnoDB engines, the latter since 5.7.5. But you may want to consider PostGIS also.

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, few questions:

  1. createdate is a datetime column?
  2. if yes, can you show the date format sent by the form?
  3. can you show the table schema? I'm not sure if you want to compare the date_in and date_out columns.

If the where condition is applied, it shouldn't return rows out of the range, an example here: http://sqlfiddle.com/#!2/6f8dbc/5

If the schema matches then you can try to modify the example on sqlfiddle to get your desired results.

cereal 1,524 Nearly a Senior Poster Featured Poster

You have to initialize the variables: if $submit is not set then $sql is not initialized and the query will fail.

Also for the query you can use the column BETWEEN value AND value condition. So change your code to:

$submit = $_POST['submit'];

# all code under this condition
if($submit)
{
    $sql = "SELECT * FROM inventory WHERE createdate BETWEEN '$date_in' AND '$date_out'";

    $result = mysql_query($sql) or die(mysql_error());

    if(mysql_num_rows($result) > 0)
    {
        while($row = mysql_fetch_array($result))  
        {
            echo "
            <tr>

                <td align='center' width='200'>
                {$row['date_in']}
                </td>

                <td align='center' width='200'>
                {$row['date_out']}
                </td>

                <td align='center' width='200'>
                {$row['model']}
                </td>

            </tr>
            ";  
        }
    }
}

echo "</table>";

For more information check:

You should use prepared statements. Take a look especially to the second link. Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

You can use DateTime::sub():

<?php

    $dt = new DateTime('2014-08-31 23:06:00');
    $dt->sub(new DateInterval('P30D'));

    echo $dt->format('Y-m-d G:i:s');

Docs:

cereal 1,524 Nearly a Senior Poster Featured Poster

So, for example:

<table id="names">
    <tr>
        <td data-name="oranges">
            oranges
        </td>
        <td data-name="apples">
            apples
        </td>
        <td data-name="coconut">
            coconut
        </td>
        <td data-name="strawberries">
            strawberries
        </td>
    </tr>
</table>

<form>
    <input type="text" name="aaa" value="" />
    <input type="text" name="bbb" value="" />
    <input type="text" name="ccc" value="" />
    <input type="text" name="ddd" value="" />
    <input type="text" name="eee" value="" />
</form>

Then you can do:

$("#names td").click(function(){
    var name = $(this).data('name');

    $('input:text:visible').each(function(){
        if($(this).val().length === 0)
        {
            $(this).val(name);
            return false;
        }
    });
});

JSfiddle: http://jsfiddle.net/hmwv1hx7/

cereal 1,524 Nearly a Senior Poster Featured Poster

Use insertGetId():

$id = DB::table('item_tbl')
    ->insertGetId(array('item_name' => $data['itemTb']));

docs: http://laravel.com/docs/queries#inserts

cereal 1,524 Nearly a Senior Poster Featured Poster

You can use each() to loop them, and then return false when you get the first empty value, as example:

<form>
    <input type="password" name="passwd" value="" />
    <input type="text" name="aaa" value="test 1" />
    <input type="text" name="bbb" value="test 2" />
    <input type="text" name="ccc" value="" />
    <input type="text" name="ddd" value="test 4" />
    <input type="text" name="eee" value="" />
</form>

JS:

$('input:text').each(function(){
    if($(this).val().length === 0)
    {
        console.log($(this).attr('name'));
        return false;
    }
});

Documentation: http://api.jquery.com/each/

cereal 1,524 Nearly a Senior Poster Featured Poster

Try by adding GROUP BY ip_username, ip_ip to the current query, it will return all users' ip, or if searching a specific user WHERE ip_username = 'Todor' GROUP BY ip_ip.

cereal 1,524 Nearly a Senior Poster Featured Poster

It can be done through Java Web Start: http://en.wikipedia.org/wiki/Java_Web_Start

You don't need PHP for this. To interact directly with software, instead, in Windows you can use the COM objects: http://php.net/manual/en/book.com.php

cereal 1,524 Nearly a Senior Poster Featured Poster

The Auth class is bounded to the User model, so when the authentication is satisfied you can access his information, check:

in particular read the Accessing The Logged In User paragraph.

In your case you can do:

public function authenticate()
{
    $fname = User::tryAuthenticate(Input::all());
    return Redirect::to('profile')->with('name', $fname);
}

And make the model method return the name, but it is not necessary, as you can always use Auth::user(), so:

public function authenticate()
{
    # true
    if(User::tryAuthenticate(Input::all())) return Redirect::to('profile');

    # false
    return Redirect::to('login')->with('error', 'Error: wrong credentials.');
}

And make User::tryAuthenticate() just return true or false.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, you can do:

Redirect::to('profile')->with('fname', Auth::user()->firstname);

Or:

Session::put('fname', Auth::user()->firstname);
Redirect::to('profile');

Then you have to get the value from session:

$data['items'] = DB::table('item_tbl')->get();
$data['fname'] = Session::get('fname');
return View::make('profile')->with('items', $data);

But:

  1. when using with() the value is flashed to session, and won't be available in the next request
  2. you can get the value directly in the controller:

    $data['fname'] = Auth::user()->firstname;
    

And also it always return false when i use Auth::check()

Can you show the login process (form and receiving route)? To restrict the access to the profile controller use the auth filter:

class ProfileController extends BaseController {

    public function __construct()
    {
        $this->beforeFilter('auth');
    }

To restrict the single method you can apply the same or at route level:

Route::get('profile', array(
    'before' => 'auth',
    'uses'   => 'ProfileController@showProfile'
    ));
Jake.20 commented: Just what i'm looking for! +2
cereal 1,524 Nearly a Senior Poster Featured Poster

It seems the default value for the new versions of debian & derivates:

Currently I don't have a new installation to verify, but you should be able to change the default value back to /var/www through the config files in /etc/apache2.

You could also move everything to your profile /home/lewashby/www/, it's just a matter of preferences.