在页面加载和表单上显示数据库结果使用通配符提交[关闭]

I am having issue trying to display a database result on page load and form submit. when the page loads it keeps giving me blank page but when I submit the form, I get results.

<?php
    $alpha = mysql_real_escape_string($_POST['alpha']);

    $p ="^[".$alpha."]";

    if (!isset($p)&&empty($p)){$p = "^[a-z]";}

    $select = "SELECT u.pname,u.categoryid,p.amountpaid,p.teller,p.handler,
    p.scollection,p.project,p.levies,p.status,q.quarter,q.year,
    p.invoice,q.ordinary_cf,q.special_cf,q.cate_id
    FROM users u
    INNER JOIN tbl_paymentalert p
    ON u.categoryid = p.catid

    INNER JOIN tbl_quartersummary q
    ON p.catid= q.cate_id
    WHERE q.quarter = :quarter AND q.year = :year AND pname REGEXP :p
    ORDER BY u.pname  limit :eu,:limit
";

$q=$conn->prepare($select);
$q->bindValue(':quarter', $quarter, PDO::PARAM_STR);
$q->bindValue(':year', $year, PDO::PARAM_STR);
$q->bindValue(':p', $p, PDO::PARAM_STR);
$q->bindValue(':eu', $eu, PDO::PARAM_INT); 
$q->bindValue(':limit', $limit, PDO::PARAM_INT);
$q->execute();
    ?>

Okay... so... you're getting the value from $_POST.

// if you're using mysqli_ or pdo and using a prepared query or data binding
// mysql_real_escape_string is not necessary... 
$alpha = mysql_real_escape_string($_POST['alpha']);

// even if $alpha was empty, $p will always be set and will
// never be empty because of the following statement.  
// if alpha is empty, $p will be "^[]"
$p ="^[".$alpha."]";


// this code will never happen... so your default won't be set.     
if (!isset($p) && empty($p) )
{
    $p = "^[a-z]";
}

do something like...

//        if `$_POST` is set,        use that value,   if not use 'a-z'
$alpha = (isset($_POST['alpha'])) ? $_POST['alpha'] : 'a-z'; 

$p = "^[".$alpha."]";

and then

$q->execute(array($quarter,$year,$p,$e,$limit));

Make sure those variables are set or you have handled what happens if they are not set. It might cause you to get no results back without any explanation.

(last edit, I swear, unless OP asks for clarification or something)
good job for trying out the pdo, normally people are scared of it and ignore the warnings. seriously, good job!