AndrisP 193 Posting Pro in Training

Your pattern checked only first character. Change to:
(!preg_match("/^[0-9a-zA-Z ]+$/", $name3))

Aeonix commented: Yea! +4
AndrisP 193 Posting Pro in Training
strlen(trim($string))
AndrisP 193 Posting Pro in Training
#include <stdio.h>

int main(){
    int i,s=8;
    while(s<=100){
        printf("\t%d\n", s);
        switch(i){
            case 4: i+=1; break;
            case 5: i+=2; break;
            default: i=4;
        }
        s+=i;
    }
    return 0;
}
AndrisP 193 Posting Pro in Training

Make multidimensional array eg

$categories = array(
    'cars' => array(
        'BMW' => array(
            'X1',
            'X3',
            'X5',
            'X6'
        ),
        'AUDI' => array(
            'A3',
            'A6'
        ),
        'MERCEDES'
    ),
    'moto' => array(
        'SUZUKI',
        'HONDA',
        'YAMAHA'
    ),
    'phones' => array(
        'SAMSUNG',
        'LG',
        'MOTOROLA'
    )
);
// etc

You can write data to ini file if it's much readable for you and build array with parse_ini_file() http://php.net/manual/en/function.parse-ini-file.php

Stefce commented: How much sub-arrays i can have ? +2
AndrisP 193 Posting Pro in Training
diafol commented: This needs to be a sticky! Heh heh. +14
AndrisP 193 Posting Pro in Training

use one of

    $query = "select count(*) from manuscript where year = :year";
    $sql=$con->prepare($query);
    $sql->bindParam(':year', $year);
    $total = $sql->fetchColumn();
    echo $total;

or

    $query = "select count(*) from manuscript where year = ?";
    $sql=$con->prepare($query);
    $sql->execute([$year]);
    $total = $sql->fetchColumn();
    echo $total;

do not mixed two methods of binding variables

AndrisP 193 Posting Pro in Training

edit links:

for($x=0; $x<$pages; $x++){
       echo '<a href="index.php?page='.$x.'"
                 style="text-decoration:none">'.($x+1).'</a>';
    }

after line 10 insert line $sql->bind_param('i', $year);

AndrisP 193 Posting Pro in Training

Initialize request variables outside of function before you call it

    $year = filter_input(INPUT_GET, 'year', FILTER_VALIDATE_INT);
    $page = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT);
    $refs = filter_input(INPUT_GET, 'refs', FILTER_VALIDATE_INT);

    getYear($year, $page, $refs);

drop lines 13 and 16-30 put new line instead:
if($page>$pages){ $page = $pages; }
elseif($page<0){ $page = 0 }
change variable name in line 14 $refs_per_page to $refs

AndrisP 193 Posting Pro in Training

show me your new version of function

AndrisP 193 Posting Pro in Training

Two similar function for different year is irrationally. I would suggest to transform getYear() and put year as parameter eg getYear($year). You can set many parameters eg getYear($year, $page, $refs) you can set default values also eg getYear($year=date("Y"), $page=0, $refs=20) then replace your query

$year = filter_input(INPUT_GET, 'year', FILTER_VALIDATE_INT);
$page = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT);
$refs = filter_input(INPUT_GET, 'refs', FILTER_VALIDATE_INT);

$query = "select * from manuscript where year = :year limit :page*:refs,:refs";

never put request variables directly to the SQL query! - use bind variables and bind params after prepare query

$stmt = $conn->prepare($query);
$stmt->bindParam(':year', $year, PDO::PARAM_INT);
$stmt->bindParam(':page', $page, PDO::PARAM_INT);
$stmt->bindParam(':refs', $refs, PDO::PARAM_INT);
$stmt->execute();

Replace HTML links eg

<a href="index.php?year=2015&page=0">2015/1</a>
<a href="index.php?year=2015&page=1">2015/2</a>
<a href="index.php?year=2015&page=2">2015/3</a>
.....
.....
.....
<a href="index.php?year=2016&page=0">2016/1</a>
<a href="index.php?year=2016&page=1">2016/2</a>
<a href="index.php?year=2016&page=2">2016/3</a>
rproffitt commented: Well said. +11
diafol commented: Good advice +14
AndrisP 193 Posting Pro in Training

And you can use attribute "required" for all required fields in a form such as:

<input type="email" name="email" width="20" required="required" />

HTML5 input type "email" is supported. if you use this type then client web browser check input email address before data form send to server. On the server side check email address with "filter_input()".

$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
AndrisP 193 Posting Pro in Training

For first:

  $id = $_GET['id'];
  $action = $_GET['action'];

is not good practice! It raise PHP error if not set. All request variables initialize like this:

$id = ( isset($_GET['id']) ? $_GET['id'] : '' );

"isset($action)" in to the line 9 is senseless, check it while initialize

$action = ( isset($_GET['action']) ? $_GET['action'] : 'edit' );
cereal commented: Hi, why not `filter_input()` then? https://php.net/filter-input +14
AndrisP 193 Posting Pro in Training

Try this:

 <?php
    $num=array(rand(), rand(), rand(), rand(), rand());
    for($i=0;$i<5;$i++)
    echo '<input type="number" value="'.$num[$i].'">';
    ?>

Your array is empty

AndrisP 193 Posting Pro in Training

Both order is valid but attribute "alt" is necessary for valid "img" tag

AndrisP 193 Posting Pro in Training

and don't put php variables directly in to the SQL query use bind_param instead http://php.net/manual/en/mysqli-stmt.prepare.php

AndrisP 193 Posting Pro in Training

In your example you trying send to server two variables by same name. I think more convenient is array of checkboxes with binary step values e.g.

<form action="" method="post"> 
<input type="checkbox" id="status_1" name="status[]" value="1" />
<input type="checkbox" id="status_2" name="status[]" value="2" />
<input type="checkbox" id="status_3" name="status[]" value="4" />
<input type="submit" />
</form>

then on the server side you get value as sum of array e.g.

$status = ( isset($_POST['status']) ? array_sum($_POST['status']) : 0 );

and then compare as binary e.g.

if($status & 1){ /* statement for option 1 */ }
if($status & 2){ /* statement for option 2 */ }
if($status & 4){ /* statement for option 3 */ }
AndrisP 193 Posting Pro in Training

If you replace to print recursive then you can see structure of the generated XML object

<!DOCTYPE html>
<html>
<body>
    <pre>
<?php
$xml=simplexml_load_file("demo.xml")
        or die("Error: Cannot create object");
print_r($xml);
?>
    </pre>
</body>
</html>

do with it what you want e.g. "foreach"

AndrisP 193 Posting Pro in Training

Your mistake is concatenate simbol before first string "||"

AndrisP 193 Posting Pro in Training

if you want insert:

INSERT INTO tablename (col1, col2, col3) VALUES (?,?,?)

if you want update table:

UPDATE tablename SET col1 = ? , col2 = ? , col3 = ? WHERE id = ?

your example contain illegal mix of sql commands.
And do not directly put variables into SQL, use prepare and execute statement!

AndrisP 193 Posting Pro in Training

You can use RLIKE instead:

SELECT 'sun' RLIKE '^sun[^shine]*$';
SELECT 'sunshine' RLIKE '^sun[^shine]*$';

or use word boundaries:

SELECT 'long text contain sun and other words' RLIKE '[[:<:]]sun[[:>:]]';
SELECT 'long text contain sunshine and other words' RLIKE '[[:<:]]sun[[:>:]]';
diafol commented: Good stuff on RLIKE :) +15
AndrisP 193 Posting Pro in Training

Line 35 return object and then you pass object in next query line 38

AndrisP 193 Posting Pro in Training
$transmission_type = ( isset($_POST['transmissionTypeInput']) && $_POST['transmissionTypeInput']=='automatic' ? 'automatic' : 'manual' );
cereal commented: I misread OP request and focused on the first bit of code... correct solution +1 +13
AndrisP 193 Posting Pro in Training

No - Linux is a version of UNIX

AndrisP 193 Posting Pro in Training

If you define function after call it, then declare it before
e.g. put line int func_compare(int x, int y); before main()

AndrisP 193 Posting Pro in Training

You can use <input type="number" min="0" /> instead of disable submit button in HTML5.

AndrisP 193 Posting Pro in Training
void pyramid(int count){
    cin >> lineTotal;
    count = lineTotal;
    for(int line=0; line < count; line++){
        if (count >= 10){
            int width=(count-line)*2;
            if (line<9) width--;
            cout << setw( width ) << line+1;
            }
        else {
            cout << setw(count-line) << (line+1);
            }

        for(int leftside = line; leftside > 0; leftside--){
            cout << setw(count>9&&leftside!=9?2:1) << leftside;
            }
        for(int rightside = 1; rightside <= line; rightside++){
            cout << setw(count>9?2:1) << (rightside + 1);
            }
        cout << endl;
        }
    cout << endl;
    }
AndrisP 193 Posting Pro in Training
#include <iostream>
#include <iomanip>

using namespace std;

void piramid(int count){
    setfill(" ");
    for(int i=0; i<count; i++){
        cout << setw(count-i) << (i+1);
        for(int j=i; j>0; j--){ cout << j; }
        for(int j=1; j<=i; j++){ cout << (j+1); }
        cout << "\n";
        }
    cout << "\n";
    }


int main(){
    piramid(1);
    piramid(2);
    piramid(4);
    piramid(6);
    piramid(9);
    return 0;
    }
AndrisP 193 Posting Pro in Training

void is no returns but can change input params e.g.

#include <iostream>
#include <stdio.h>

void myfunc(int &a, int &b, int &c){
    a += 1;
    b -= 2;
    c = a+b;
    return;
    }

int main(){
    int a=5,b=6,c=7;
    // print before myfunc()
    printf("a=%d b=%d c=%d \n", a,b,c);

    myfunc(a, b, c);

    // print after myfunc()
    printf("a=%d b=%d c=%d \n", a,b,c);
    return 0;
    }

result of next example will be identical

#include <iostream>
#include <stdio.h>

void myfunc(int &a, int &b, int &c){
    printf("a=%d b=%d c=%d \n", a,b,c);
    a += 1;
    b -= 2;
    c = a+b;
    printf("a=%d b=%d c=%d \n", a,b,c);
    return;
    }

int main(){
    int a=5,b=6,c=7;
    myfunc(a, b, c);
    return 0;
    }
AndrisP 193 Posting Pro in Training

it is not correct elements with the same ID in the one document

AndrisP 193 Posting Pro in Training
<input type="submit" name="submit" id="submit" class="btn btn-primary" value="Cancella" onclick="confirm('Are you sure?')?window.location='delete_article.php?id=<?=$row['id'];?>':alert('Cancelled');" />
AndrisP 193 Posting Pro in Training

This code check for SPACE in value:

document.form1.NEGERI.value==' '

but this check for empty value:

document.form1.NEGERI.value==''
AndrisP 193 Posting Pro in Training

I think 3 tables

SELECT
    (SELECT value FROM fruits WHERE value='Apple' LIMIT 1) as fruit ,
    (SELECT value FROM countries WHERE value='China' LIMIT 1) as countrie ,
    (SELECT value FROM sizes WHERE value='Small' LIMIT 1) as size;
AndrisP 193 Posting Pro in Training

I think you need 3 tables instead of 3 columns e.g.
Fruits, Countries, Sizes

AndrisP 193 Posting Pro in Training

When connected to the database immediatly set charset e.g.

$link = mysql_connect('localhost', 'root', '');
$db_selected = mysql_select_db("dbname", $link);
mysql_set_charset('utf8',$link);

or OOP version

$mysqli = new mysqli('localhost', 'root', '', 'dbname', 3306);
$mysqli->set_charset('utf8');
AndrisP 193 Posting Pro in Training

Perhaps more convenient to use the selector instead of a text field

<select name="bodovi">
    <script type="text/javascript">
    for(var i=1; i<=50; i++){
        document.write('<option value="'+i+'">'+i+'</option>');
        }
    </script>
</select>
AndrisP 193 Posting Pro in Training

Use elseif instead if in lines 5 and 6 of my code

AndrisP 193 Posting Pro in Training
if(!ctype_digit($var)){ echo "NOT DIGIT"; }
AndrisP 193 Posting Pro in Training

Cut and paste line 6 after the line 23

AndrisP 193 Posting Pro in Training

Line 25 replace elseif to if, lines 13, 16, 19, 22 need quotes like this:
if ($place == 'balkon')

AndrisP 193 Posting Pro in Training

I recommend to insert spaces:

<?php if($True == 0){ ?>
    <a href="/#"> Apply </a>
<?php } else { ?>
    <a href="/#"> Aleary applied </a> 
<?php } ?>
ravi142 commented: @AndrisP : Thank You. +1
AndrisP 193 Posting Pro in Training

swap()
is C++ built-in function

catastrophe2 commented: o its supposed be SWAP, but it still runs either way, just that i need to fix the problem i mentioned in my first post +1
AndrisP 193 Posting Pro in Training

e.g.

<?php 
// put php script - functions classes, methods etc

header("Content-type:text/html;charset=utf-8");
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>
"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="lt">

<head>
.....
</head>
<body>
<?php
// again php script in HTML body
?>
<p>print some HTML content</p>
<?php
// and again php script in HTML body
?>
</body>
</html>
AndrisP 193 Posting Pro in Training

Yes of course. See my comment above.

AndrisP 193 Posting Pro in Training

Yes of course. See my comment above

AndrisP 193 Posting Pro in Training

Put function to beginning of this file,

    <?php
    function parsefile($filename){
    $file = @file($filename);
    while(list($key,$val)=each($file)){
    $line = explode(";",$val);
    if($line[1]==$_SERVER['REMOTE_ADDR']) return true;
    }
    return false;
    }
    header("Content-type:text/html;charset=utf-8");
    ?>

edit lines 90-100

<div class="block last"><h2>Konkursas<br> dėl Vip,Admin</h2>
<?php if (parsefile("konkursas.txt")){ echo "Error message"; }
else { ?>
<form action='konkursas.php' method='post'>
<p>El. pašto adresas</p><input type='text' title="Čia turėtų būti jūsų email." name ='nail' size= '30'/>
<br />
<br />
<input type='submit' name='submit' value='OK'/>
<br />
</form>
<?php } ?>

and save this file as php

AndrisP 193 Posting Pro in Training

if you save in file as

<?php

fwrite($file,$email.";".$_SERVER['REMOTE_ADDR'].";".PHP_EOL);

?>

you can use this function

<?php

function parsefile($filename){
    $file = @file($filename);
    while(list($key,$val)=each($file)){
        $line = explode(";",$val);
        if($line[1]==$_SERVER['REMOTE_ADDR']) return true;
        }
    return false;
    }

?>
AndrisP 193 Posting Pro in Training

for example:

RewriteEngine on

RewriteCond %{REMOTE_ADDR} ^127.0.0.1$
RewriteRule !(^ban_page.html) /ban_page.html [R]
AndrisP 193 Posting Pro in Training

Not need input field "ip" in form - user can change it.

    <?php
    if (isset($_POST['submit'])) {
    $file = fopen('konkursas.txt','a+');
    $email = $_POST['nail'];
    fwrite($file,$email." [".$_SERVER['REMOTE_ADDR']."]".PHP_EOL);
    fclose($file);
    print_r(error_get_last());
    header("Location: http://www.mypage.com") ;
    }
    ?>
sigitas.darguzas commented: Thanks :) +0
AndrisP 193 Posting Pro in Training

No input tag types "ip" and "email". Please check http://www.w3schools.com/tags/tag_input.asp

sigitas.darguzas commented: okey but dont work. i need autopatic fill ip in konkursas.txt +0
AndrisP 193 Posting Pro in Training

Maybe this useful
SELECT LPAD(CAST(myValue AS DECIMAL(4,2)), 5, '0');
The result will be:
11.5, 5.5, 2.25, 1, 12.25
AS
11.50 05.50 02.25 01.00 12.25