cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, can you show the controller that loads this view?

cereal 1,524 Nearly a Senior Poster Featured Poster

Yep: http://talks.php.net/show/phplondon13/

To browse through the slides use the keyboard arrows. Note I suggest Firefox to browse them, Chrome seems to not work fine.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

can you explain it a bit more? If I've understood you want to redirect only certain urls basing on regular expressions, correct? Are these slugs (now-when, an-other) saved into a database?

cereal 1,524 Nearly a Senior Poster Featured Poster
cereal 1,524 Nearly a Senior Poster Featured Poster

At line 10 there is an error:

if (isset($searching) && $searching==yes)

the value yes is a string not a constant, so change it to:

if (isset($searching) && $searching=='yes')

At line 82 you wrote:

echo $recordObj->mycolumn;

But you're retrieving title, content and images from the query, so it should be:

echo $recordObj->title;

A part this, it works fine, but I think you need to use UNION instead of the previous query:

$query = "SELECT static_content.title, static_content.content, static_content.images from static_content WHERE upper(static_content.images) LIKE '%$find%' or upper(static_content.title) LIKE '%$find%' or upper(static_content.content) LIKE '%$find%' UNION SELECT dynamic_content.title, dynamic_content.content, dynamic_content.images FROM dynamic_content WHERE upper(dynamic_content.images) LIKE '%$find%' or upper(dynamic_content.title) LIKE '%$find%' or upper(dynamic_content.content) LIKE '%$find%'";

Otherwise it can return all the rows from both the tables, not only the correct matches. Spot the differences.

Docs: http://dev.mysql.com/doc/refman/5.5/en/union.html

cereal 1,524 Nearly a Senior Poster Featured Poster

You can use a CSS to format the layout as you want, also read this article:

it is a bit old but still useful.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,
posting the structures of the tables would help to understand. Right now it seems you just need to select by av.sku_id:

select av.value, av.id, av.sku_id from product_attr_vals where av.sku_id = '#3103513504350';

But I suppose the value you were referring, i.e. 12.7oz, is saved somewhere, from the above I don't understand where this is.

Also when you talk about tabs are you referring to the result set or to a pagination?

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

It's normal because 0 equals to 01-01-1970 so, to get previous dates, you will receive negatives values. The problem is that, if you want to store it in MySQL, the from_unixtimestamp() function will not handle signed timestamps (i.e. negative values), if you want to display a datetime you will need a workaround. Example:

create table epoch (itime int(10) not null);
insert into epoch (itime) values(-unix_timestamp());
select * from epoch;

+-------------+
| itime       |
+-------------+
| -1391425879 |
+-------------+
1 row in set (0.00 sec)


SELECT DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), interval itime second),'%Y-%m-%d') as date from epoch;

+------------+
| date       |
+------------+
| 1925-11-28 |
+------------+
1 row in set (0.01 sec)

You get a similar result with the getdate() PHP function:

print_r(getdate(-1391425879));

Array
(
    [seconds] => 41
    [minutes] => 48
    [hours] => 13
    [mday] => 28
    [wday] => 6
    [mon] => 11
    [year] => 1925
    [yday] => 331
    [weekday] => Saturday
    [month] => November
    [0] => -1391425879
)

However, if you can, avoid unix timestamps and use datetime field types.

If you explain your goals we will try to suggest the best solution.

For more information check these links:

cereal 1,524 Nearly a Senior Poster Featured Poster

Always inside the loopCount statement if($loopCount == 1) add this:

if(preg_match("/[A-Z]{2}(?=[\s]{1,}[0-9]{5})/", $myValue, $match) == 1)
{
    $array_two[$arrayIndex]['state'] = $match[0];
}
else
{
    $array_two[$arrayIndex]['state'] = '';
}

The pattern will search for two uppercase characters right before five digits, so NY 40214 is valid, while NY a40214 is not valid.

cereal 1,524 Nearly a Senior Poster Featured Poster

Yes, it can be done. Inside the loop that generates this array place this code:

if($loopCount == 1)
{
    if(preg_match("/[0-9]{5}/", $myValue, $match) == 1)
    {
        $array_two[$arrayIndex]['zip'] = $match[0];
    }
    else
    {
        $array_two[$arrayIndex]['zip'] = 0;
    }   
}

Full example:

foreach ($result as $myValue)
{
    $loopCount = ($loopCount<5) ? $loopCount : 0;

    switch ($loopCount)
    {
        case '0':
            $second_index="cName";
            break;

        case '1':
            $second_index="local";
            break;

        case '2':
            $second_index="days_times";
            break;

        case '3':
            $second_index="contact";
            break;

        case '4':
            $second_index="marker";
            break;
    }

    $array_two[$arrayIndex][$second_index]=$myValue;

    if($loopCount == 1)
    {
        if(preg_match("/[0-9]{5}/", $myValue, $match) == 1)
        {
            $array_two[$arrayIndex]['zip'] = $match[0];
        }
        else
        {
            $array_two[$arrayIndex]['zip'] = 0;
        }

    }

    $arrayIndex = ($loopCount>=4) ? $arrayIndex+1 : $arrayIndex;
    $loopCount++;
}

It could be placed also inside case '1' but in that case it will return before the local key.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

if it does not work give us some more information: How it does not work? What result do you expect? What kind of problem you get? And possibly show your code. My example works fine for me in Google Chrome, Mozilla Firefox and Opera. Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

I cannot test right now, but try:

return 301 ^(.*)$ $1.php

Note that try_files is important because it will check if the script exists and will avoid some security issues, for example if somebody uploads a text file hell.txt and submit a request like this:

GET http://localhost/uploads/hell.txt/o.php

If o.php does not exists, the parser will execute hell.txt as a PHP script, the same if the file is an image with an embedded script.

Reference:

cereal 1,524 Nearly a Senior Poster Featured Poster

Something like this should work:

<!DOCTYPE html>
<html>
    <head>
        <title>Tabless</title>
        <style type="text/css">
            *{margin:0;padding:0;}
            .table { display:table; margin:50px auto; width:960px; position:relative; }
            .tr { display:table-row; margin:10px 0; }
            .td { display:table-cell; height:30px; }
            .strong {font-weight:bold;}
        </style>
    </head>
    <body>

        <div class="table">
            <ul class="tr strong">
                <li class="td">TEXT</li>
                <li class="td">TEXT</li>
                <li class="td">TEXT</li>
            </ul>
            <ul class="tr">
                <li class="td">TEXT</li>
                <li class="td">TEXT</li>
                <li class="td">TEXT</li>
            </ul>
        </div>

    </body>
</html>

Reference: https://developer.mozilla.org/en-US/docs/Web/CSS/display

Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Add the readonly attribute:

<input type="text" size="50px" name="page" value="<?php echo $page; ?>" readonly />

But remember that a client can always change the input, so if you do NOT expect changes, because for example you do not enable the editing through javascript, then you must ignore this field when you process the request.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, have you considered the DateTime library?

<?php

    #$dob = $_GET['dob'];
    $dob = '29-06-2009';

    $at_day = '31-03-'.date('Y');
    $dt_dob = new DateTime($dob);
    $dt_now = new DateTime($at_day);

    echo "<pre>";
    print_r($dt_now->diff($dt_dob));
    echo "</pre>";

Outputs:

DateInterval Object
(
    [y] => 4
    [m] => 9
    [d] => 2
    [h] => 0
    [i] => 0
    [s] => 0
    [invert] => 1
    [days] => 1736
)

As second argument you can set the timezone of each date and get the differences. For example:

<?php

    #$dob = $_GET['dob'];
    $dob = '29-06-2009';

    $at_day = '31-03-'.date('Y');
    $dt_dob = new DateTime($dob, new DateTimeZone('America/Los_Angeles'));
    $dt_now = new DateTime($at_day, new DateTimeZone('Europe/Rome'));

    echo "<pre>";
    print_r($dt_now->diff($dt_dob));
    echo "</pre>";

With two different timezones Los Angeles and Rome you get a different result:

DateInterval Object
(
    [y] => 4
    [m] => 9
    [d] => 1
    [h] => 15
    [i] => 0
    [s] => 0
    [invert] => 1
    [days] => 1735
)

Note: you should save everything to UTC and convert it to the local time when needed.

Documentation: http://www.php.net/manual/en/datetime.construct.php

cereal 1,524 Nearly a Senior Poster Featured Poster

Without the quotes and replace the dot with a comma, dateadd() takes three arguments the format, the integer to add and the date, currently it is like you are passing only the first argument because the quotes will submit it as a single string. So change it like this:

CASE WHEN candidat_rendezvous_date IS NOT NULL THEN dateadd(hour, 1, candidat_rendezvous_date) END
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, use dateadd():

dateadd(hour, 1, candidat_rendezvous_date)
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

this is probably caused by the mysqli_fetch_array() at line 16, it will move the internal pointer to the following row, so the loop will display only the last four items. To include the first one remove line 16, i.e.:

$card_data_result = mysqli_fetch_array($card_data);

Otherwise simply use the variable:

echo $card_data_result['build_name'];

In alternative use data_seek() to reset the pointer:

$card_data_result = mysqli_fetch_array($card_data);
mysqli_data_seek($card_data, 0);
while ($list = mysqli_fetch_array($card_data)){

Docs: http://www.php.net/manual/en/mysqli-result.data-seek.php

cereal 1,524 Nearly a Senior Poster Featured Poster

The loops seem to be fine, the error means that $array_two is served as a string not as an array. Check if there is an intermediate step that resets the variable.

cereal 1,524 Nearly a Senior Poster Featured Poster

I'm not sure I've understood your request. But if you open the above stylesheet you will see:

@font-face {
  font-family: 'Patua One';
  font-style: normal;
  font-weight: 400;
  src: local('Patua One'), local('PatuaOne-Regular'), url(http://themes.googleusercontent.com/static/fonts/patuaone/v4/yAXhog6uK3bd3OwBILv_SD8E0i7KZn-EPnyo3HZu7kw.woff) format('woff');
}

You can paste the above in your stylesheet and remove the link to Google. Then if you download and install the font in your system the @font-face rule will check your system and only if it does find the font it will connect with the remote system.

Now, accordingly to the Google Fonts FAQ you can download the font and use it in your local system or in your web server:

So you could even change the url() in the src: attribute, with your server, for example:

http://localhost/fonts/PatuaOne-Regular.ttf

In order to download the file, open the font page and click on the download icon (right side of the page):

cereal 1,524 Nearly a Senior Poster Featured Poster

Set the name attribute to the input field, otherwise the POST array will not receive it and the if statement will fail. This:

<input type="submit" value="Login">

Must be:

<input type="submit" name="submit" value="Login">
cereal 1,524 Nearly a Senior Poster Featured Poster

Remove the semicolon preceding extension otherwise the line is considered a comment and remove also the double quotes, so:

extension=php_com_dotnet.dll
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, try to remove the white spaces between the addresses in the destination variables $to and $to2, so these:

$to      = "email@gmail.com, ".$reg_email;
$to2     = "email@gmail.com, admin@xxxxxxx.com";

Should be:

$to      = "email@gmail.com,".$reg_email;
$to2     = "email@gmail.com,admin@xxxxxxx.com";
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, show the query generated by your script, i.e.:

print_r($qry);

Then try to run the same query through a mysql client, from shell or by PHPMyAdmin. And add:

$res = mysql_query($qry) or die(mysql_error());

To be sure it runs fine.

cereal 1,524 Nearly a Senior Poster Featured Poster

Change it to:

SET @date_start = DATE_FORMAT(STR_TO_DATE(@from_date,'%d/%m/%Y'), '%Y-%m-%d');

Full example:

> SET @from_date = '29/11/2010'; SET @date_start = DATE_FORMAT(STR_TO_DATE(@from_date, '%d/%m/%Y'), '%Y-%m-%d'); show warnings; select @date_start;
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Empty set (0.00 sec)

+-------------+
| @date_start |
+-------------+
| 2010-11-29  |
+-------------+
1 row in set (0.00 sec)

Note: if you get warnings restart the client, it could be that a variable remains in memory.

cereal 1,524 Nearly a Senior Poster Featured Poster

The problem is the scope of the function not the include(), a function will not consider an external variable unless this is global and you define it inside the function, for example:

<?php

include 'conn.php';

function q()
{
    global $conn;
    $stmt = $conn->query("select * from users limit 1");
    return $stmt->fetch(PDO::FETCH_ASSOC);
}

print_r(q());

As alternative you can pass the connection as argument of the function:

<?php

include 'conn.php';

function q($conn)
{
    $stmt = $conn->query("select * from users limit 1");
    return $stmt->fetch(PDO::FETCH_ASSOC);
}

print_r(q($conn));

Another alternative is to return from the included file, for example:

$conn = new PDO('config', '', '');
return $conn;

And then:

<?php

$conn = include 'conn.php';

function q($conn)
{
    $stmt = $conn->query("select * from users limit 1");
    return $stmt->fetch(PDO::FETCH_ASSOC);
}

print_r(q($conn));

Check the documentation:

cereal 1,524 Nearly a Senior Poster Featured Poster

@toxicandy

With imagettfbbox() you can precalculate the width of the string and add the space that you want to both sides, for example if you want 50px per side you will do:

$font = './arial.ttf';
$fontsize = 14;

$bbox = imagettfbbox($fontsize, 0, $font, 'Powered by PHP ' . phpversion());

If you print $bbox you get:

Array
(
    [0] => 0
    [1] => 4
    [2] => 294
    [3] => 4
    [4] => 294
    [5] => -15
    [6] => 0
    [7] => -15
)

These are the coordinates of the string, we need $bbox[4] because it represents the upper right corner, X position and $bbox[0] because it is the lower left corner, X position. With $bbox[4] we can generate the width of the image:

$imgx = $bbox[4]+100;

where 100 is the number of pixels we want to add (50 per side). With this you can start to create the image:

$imgy = 100;
$im = imagecreatetruecolor($imgx, $imgy);

now to center horizontally the text we have to perform this:

$xpos = $bbox[0] + ($imgx / 2) - ($bbox[4] / 2);

It will output 50, but if instead of $imgx = $bbox[4]+100; you want to double the sizes:

$imgx = $bbox[4]*2;

It will adapt to the new sizes accordingly to the font size. The same procedure can be done to determine the vertical alignment. The final example script looks like this:

<?php

// Path to our font file
$font = './arial.ttf';
$fontsize = 14;
$string = 'Powered by …
cereal 1,524 Nearly a Senior Poster Featured Poster

Try with imagettfbbox() as suggested in this comment:

Also, consider to use mb_strtolower() and mb_convert_case() instead of strtolower() and ucwords() because the latters will not work correctly with special characters. In your case just use:

$name = mb_convert_case($Name, MB_CASE_TITLE, "UTF-8");

Reference: http://php.net/mb_convert_case

Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

It should not depend on CodeIgniter, this can relate to the system in which PHP is executed: in the case is not synchronized. Have you tried to display the date time from a CodeIgniter view? If you can, compare it with a simple script, for example:

echo date('d-m-Y H:i:s');

It could be that some insert queries are failing, in this case it can be helpful to see the ajax call and the Controller.

cereal 1,524 Nearly a Senior Poster Featured Poster

Probably somewhere, one of the echos or of the variables is missing a ;, for example:

if(1 == 1)
{
    echo 'true'
}

The missing ; will generate the same error.

cereal 1,524 Nearly a Senior Poster Featured Poster

You're starting the class in $chimp, not in $MailChimp, so change this:

$chimp = $MailChimp->call('lists/subscribe'

To:

$result = $chimp->call('lists/subscribe'
cereal 1,524 Nearly a Senior Poster Featured Poster

You can use attributes(), for example:

<?php

$file = simplexml_load_file("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");

foreach($file as $key => $value)
{
    echo "Time: ". $value->Cube->attributes()->time . "<br /><br />";
    foreach($value->Cube->Cube as $key_1 => $value_1)
    {
        echo "Currency: ". $value_1->attributes()->currency . " Rate:". $value_1->attributes()->rate ."<br />";
    }
}
cereal 1,524 Nearly a Senior Poster Featured Poster

That's probably happens because you're trying to access the controller from the application directory instead of using the index.php file.

If, for example you have a controller named Articles, then try:

http://localhost/index.php/articles

If this does not help then try to provide more information:

  • an example of url used to access to the app
  • example code
cereal 1,524 Nearly a Senior Poster Featured Poster

There are many. Among the Google Fonts, I think good compromises are Roboto and Lato:

cereal 1,524 Nearly a Senior Poster Featured Poster

Mine is more an idea than a solution: you will probably need the position (in coordinates) inside the state, in order to evaluate the nearest border. For example, in MySQL, having the coordinates of each city, you can query and get the result for the cities in a defined range, the first of the result set outside the national border will be in the nearest state.

But the IP is not always the correct source city, a part proxies, sometimes you get the IP of a Tier 2 (or 3) node, for example if you check for italians IPs those can be matched to cities distant up to 800km from the real user location, depending on the node that will send the request out.

The Geolocation API can probably be more accurate, check for:

cereal 1,524 Nearly a Senior Poster Featured Poster

Yep, you have to buy the license to use it as webfont and then you apply it to the website through the @font-face attribute. In order to work you need to host the file in your server or in a CDN (Content Delivery Network).

For the license check here:

If you click on Webfont View you can read the license agreement, this is important because it explains how you can use the font. In some cases, for example, you cannot use a font to create a logo or for commercial sites.

Additional note: if you go through the above link and read the licensing tab, you will see that they allow the webfont for 250000 views and after that the font must be bought another time.

cereal 1,524 Nearly a Senior Poster Featured Poster

Or is it destined to default down to Arial a majority of the time (provided the user doesn't have Helvetica Neue or Helvetica installed on their machines)?

Correct.

But you can include a font from a remote server, check for example at Google Fonts: http://www.google.com/fonts

cereal 1,524 Nearly a Senior Poster Featured Poster

Use a foreach loop to get the keys and the values:

foreach($array as $key => $value)
{
    echo "$key has variable $value";
}

You can also use array_keys() and array_values(), for example:

$akeys = array_keys($array);
$avalues = array_values($array);

for($i = 0; $i < count($array); $i++)
{
    echo "{$akeys[$i]} has variable {$avalues[$i]}";
}

Another approach with next(), current() and key():

for($i = 0; $i < count($array); $i++)
{
    echo key($array) ." has variable ". current($array) . "<br />";
    next($array);
}

Reference: http://php.net/manual/en/ref.array.php

cereal 1,524 Nearly a Senior Poster Featured Poster

Maybe I got it, add $stmt->store_result(); before num_rows. Looking better at my previous test I was getting your same output, now is:

mysqli_stmt Object
(
    [affected_rows] => 1
    [insert_id] => 0
    [num_rows] => 1
    [param_count] => 1
    [field_count] => 1
    [errno] => 0
    [error] => 
    [sqlstate] => 00000
    [id] => 1
)
diafol commented: Fantastic! Big thanks +0
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi!

It seems to work fine form me, but this:

$stmt->$mysqli->bind_param("s", $dbname);
$stmt->$mysqli->execute();

should be:

$stmt->bind_param("s", $dbname);
$stmt->execute();

My example:

$stmt = $mysqli->prepare("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ?");
$stmt->bind_param("s", $dbname);
$stmt->execute();

print_r($stmt);
$result = $stmt->get_result();

while($r = $result->fetch_array(MYSQLI_BOTH))
{
    echo $r[0];
}

And outputs:

mysqli_stmt Object
(
    [affected_rows] => -1
    [insert_id] => 0
    [num_rows] => 0
    [param_count] => 1
    [field_count] => 1
    [errno] => 0
    [error] => 
    [sqlstate] => 00000
    [id] => 1
)

And the dbname.

Consider that if you're using mysqli_stmt::get_result(), this is available only if you using MySQLi through the MySQL Native Driver.

cereal 1,524 Nearly a Senior Poster Featured Poster

Add the fourth parameter and it will cut the word:

wordwrap($string, "80", "<br>", true);
diafol commented: heh, rep for infinite patience +14
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

Your script is almost correct but the session_start() must be in the first line of the script. So, if for example you're doing everything in the same script, you can write it like this:

<?php

    session_start();
    $_SESSION['error'] = null;

    if (empty($_POST['emailid']))
    {
        $emailid = "Please enter your email id";
        $_SESSION['error'] = $emailid;
    }

?>

<form  method="POST" action="">
    <input type="text" name="emailid"><?php if(isset($_SESSION['error'])) { echo $_SESSION['error']; } ?></br>
    <input type="submit" name="submit_form" value="Register">
</form>

The session error is null when the script starts, and if $_POST['emailid'] is empty then is set. If it doesn't start null the next time you submit the form it will always show the error message. You could also unset the error session in a second step, it's up to you.

Next control you can add is a filter to validate the email address, so it can become:

<?php

    session_start();
    $_SESSION['error'] = null;
    $_SESSION['emailaddress'] = null;

    if($_POST) print_r($_POST);

    if (empty($_POST['emailid']))
    {
        $emailid = "Please enter your email id";
        $_SESSION['error'] = $emailid;
    }
    else
    {
        $email = filter_var(trim($_POST['emailid']), FILTER_VALIDATE_EMAIL);

        if($email === false)
        {
            $emailid = "Please enter a valid email address";
            $_SESSION['error'] = $emailid;
        }
        else
        {
            $_SESSION['emailaddress'] = $email;
        }
    }

?>

<form  method="POST" action="">
    <input type="text" name="emailid" <?php if(isset($_SESSION['emailaddress'])) echo "value=\"{$_SESSION['emailaddress']}\""; ?>><?php if(isset($_SESSION['error'])) { echo $_SESSION['error']; } ?></br>
    <input type="submit" name="submit_form" value="Register">
</form>

Note that the validation of the email will fail if there are spaces before or after the email string, so it's important to use the trim() function to remove them.

Documentation:

cereal 1,524 Nearly a Senior Poster Featured Poster

The pattern in the preg match is missing the dash -, it should be [a-zA-Z0-9_-], so change the first to:

'/(https|http):\/\/(.*?)\/([a-zA-Z0-9_-]{11})/i'

And the second to:

'/(https|http):\/\/(.*?)\/(embed\/|watch\?v=|(.*?)&v=|v\/|e\/|.+\/|watch.*v=|)([a-zA-Z0-9_-]{11})/i'

Because in case of links as $yt_url = "http://youtu.be/--9oAhOSwpg"; it will not work.

cereal 1,524 Nearly a Senior Poster Featured Poster

This:

CASE WHEN minpart=0 
    THEN CAST(hourpart as nvarchar(200))+':00' 
    ELSE CAST((hourpart-1) as nvarchar(200))+':'+ CAST(minpart as nvarchar(200))END as 'total time'

is a statement, like if-then-else:

if the minpart (stands for minute) column value is 0 then total time will be hourpart:00, if instead the minpart is not zero, then the total time will be the result of (hourpart-1):(minpart). The CAST() function is used to convert the result from a datetime column type to a string type:

The columns used by these statements are generated by the subquery aliased as source:

FROM
(
    SELECT   EmplID, EmplName, InTime, [TimeOut], [DateVisited],
    DATEDIFF(Hour,InTime, [TimeOut]) as hourpart, 
    DATEDIFF(minute,InTime, [TimeOut])%60 as minpart  
    from times) source

As you see, in this last part, the query uses the DATEDIFF() function to generate the values that will be used in the case statements: hourpart and minpart.

About DATEDIFF:

cereal 1,524 Nearly a Senior Poster Featured Poster

In addition check also this link: http://php.net/migration54

cereal 1,524 Nearly a Senior Poster Featured Poster

@Ine_1

Hello, in practice you have to escape the quotes of the html code. If you use double quotes then you can write:

echo "<span class=\"smile\">hello</span>";

Notice how the class quotes are escaped by the backslash \". This can be rewritten in many ways:

echo "<span class='smile'>hello</span>";
echo '<span class="smile">hello</span>';

# with simple variable
$class = 'smile';
echo "<span class='".$class."'>hello</span>";
echo "<span class='$class'>hello</span>";
echo '<span class="'.$class.'">hello</span>';

# with array
$class['span'] = 'smile';
echo "<span class='{$class['span']}'>hello</span>";
echo '<span class="'.$class['span'].'">hello</span>';

Documentation:

cereal 1,524 Nearly a Senior Poster Featured Poster

Exactly, as I wrote in my last post, check line 796:

$reg_contact_h = mysqli_real_escape_string($dbc, trim($_POST['reg_contact_h']));
$reg_contact_m = mysqli_real_escape_string($dbc, trim($_POST['reg_contact_m']));

And then line 1018:

<tr>
    <td class="mainans">Contact Details*</td>
    <td>
        <label for="rqst_contact_h"></label>
        <input type="text" name="rqst_contact_h" class="roundedfield" id="rqst_contact_h" value="<?php if (!empty($reg_contact_h)) echo htmlspecialchars($reg_contact_h, ENT_NOQUOTES, 'UTF-8'); ?>" size="20">
        <label for="rqst_contact_m"></label>
        <input type="text" name="rqst_contact_m" class="roundedfield" id="rqst_contact_m" value="<?php if (!empty($reg_contact_m)) echo htmlspecialchars($reg_contact_m, ENT_NOQUOTES, 'UTF-8'); ?>" size="20">
    </td>
</tr>

If you try to print your POST request you will get:

Array
(
    [rqst_contact_h] => 12
    [rqst_contact_m] => 17
)

Instead it should print:

Array
(
    [reg_contact_h] => 12
    [reg_contact_m] => 17
)

Otherwise the variables at lines 796 & 797 will stay empty.

The issue is given by the name attribute in the input fields because it differs from all the others, in all your script it refers as reg_contact_h, inside the form, instead is named rqst_contact_h.

cereal 1,524 Nearly a Senior Poster Featured Poster

Maybe I got it: the name in the input field is rqst_contact_h while the script searches for reg_contact_h in the POST array and the same happens with reg_contact_m. So this:

<input type="text" name="rqst_contact_h" class="roundedfield" id="rqst_contact_h" value="<?php if (!empty($reg_contact_h)) echo htmlspecialchars($reg_contact_h, ENT_NOQUOTES, 'UTF-8'); ?>" size="20">

Must be:

<input type="text" name="reg_contact_h" class="roundedfield" id="reg_contact_h" value="<?php if (!empty($reg_contact_h)) echo htmlspecialchars($reg_contact_h, ENT_NOQUOTES, 'UTF-8'); ?>" size="20">

Otherwise change the server-side part, i.e. this:

$reg_contact_h = intval(trim($_POST['reg_contact_h']));

Becomes:

$reg_contact_h = intval(trim($_POST['rqst_contact_h']));

If it does not work, try by printing all the POST array:

print_r($_POST);

So you can check if the values are correct. If still in doubt and if you can, then please share all the part of the code that receives the POST request. Hope it helps! :)

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok try to do the same with the integer columns, since you're using prepared statements you can avoid mysqli_real_escape_string().

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi ignnniter, just a suggestion: strpos can lead to the same problem of the strstr approach, because it will check only for the first occurrence.

Tpojka suggested preg_match which is a better solution because you can use a pattern to return the last at-sign segment in the email i.e. the domain part. Here's an example:

<?php

$whitelist = array(
        '@some.tld',
        '@mine.tld'
    );

function checkMailDomain($mail, $whitelist)
{
    if(preg_match('/@(?!.*@).*+/', $mail, $matches) == 1)
    {
        return in_array($matches[0], $whitelist) ? true:false;
    }

    return false;
}

$mail = 'example\@some.tld@evil.org';
echo checkMailDomain($mail, $whitelist) === true ? $mail .' is allowed': $mail .' is not allowed';

$mail = 'example@mine.tld';
echo checkMailDomain($mail, $whitelist) === true ? $mail .' is allowed': $mail .' is not allowed';

It will output:

example\@some.tld@evil.org is not allowed
example@mine.tld is allowed

The above pattern /@(?!.*@).*+/ works like this: match the at-sign and all the following text that is not followed by another at-sign.

Reference: http://www.rexegg.com/regex-disambiguation.html

Bye!