I am trying to search a mySQL database in PhP using POST, but I get these errors:
Notice: Undefined variable: ban1 in /Applications/XAMPP/xamppfiles/htdocs/bans.php on line 266

Notice: Undefined variable: banner1 in /Applications/XAMPP/xamppfiles/htdocs/bans.php on line 268

Notice: Undefined variable: bantl1 in /Applications/XAMPP/xamppfiles/htdocs/bans.php on line 270

Notice: Undefined variable: banreason1 in /Applications/XAMPP/xamppfiles/htdocs/bans.php on line 274

Notice: Undefined variable: ban2 in /Applications/XAMPP/xamppfiles/htdocs/bans.php on line 276

Notice: Undefined variable: banner2 in /Applications/XAMPP/xamppfiles/htdocs/bans.php on line 278

Notice: Undefined variable: bantl2 in /Applications/XAMPP/xamppfiles/htdocs/bans.php on line 280

Notice: Undefined variable: banreason2 in /Applications/XAMPP/xamppfiles/htdocs/bans.php on line 286
Here is the code that I am using, any ideas?:

echo"
<h1>Punishments
 <div class='col-sm-3 col-md-3 pull-right' style='float:right'>
<div class='container'>
  <div class='row'>
    <div class='col-sm-3 col-xs-12 col-lg-3'>
      <form class='form-search' action='./bans.php' method='post'>
          <div class='input-group'>
              <input type='text' class='form-control' name='psch' placeholder='Search Players'>
              <span class='input-group-btn'>
                  <button type='submit' name='submitbtn' class='btn btn-search'><span class='glyphicon glyphicon-search'></span></button>
              </span>
          </div>
      </form>
    </div>
  </div>
</div>
</div>
</h1>
<br>
<hr>";

        require ("./connect.php");
    if (isset($_POST['submitbtn'])) {
        $search = $_POST['psch'];
        $result = mysql_query('SELECT * FROM bans WHERE banned="$search" ORDER BY id DESC LIMIT 0,1') or die('Invalid query: ' . mysql_error());
        while ($row = mysql_fetch_assoc($result)) {
            $ban1 = $row['banned'];
            $banner1 = $row['banner'];
            $bantl1 = $row['timeleft'];
            $banreason1 = $row['reason'];
            $banappeal1 = $row['appealed'];
            $banacceptor1 = $row['acceptor'];
            $bantime1 = $row['time'];
            }
        $result = mysql_query('SELECT * FROM bans WHERE banned="$searched" ORDER BY id DESC LIMIT 1,1') or die('Invalid query: ' . mysql_error());
            while ($row = mysql_fetch_assoc($result)) {
                $ban2 = $row['banned'];
                $banner2 = $row['banner'];
                $bantl2 = $row['timeleft'];
                $banreason2 = $row['reason'];
                $banappeal2 = $row['appealed'];
                $banacceptor2 = $row['acceptor'];
                $bantime2 = $row['time'];
            }
        echo "
            <div class='jumbotron'>
            <h1></h1>
            <p>
<b>-----------------------------------------------</b>
<br>
<b>Banned:</b>$ban1
<br>
<b>Banner:</b>$banner1
<br>
<b>Time Left:</b>$bantl1
<br>
<b>Reason:</b>$banreason1
<br>
<b>-----------------------------------------------</b>
<br>
<b>Banned:</b>$ban2
<br>
<b>Banner:</b>$banner2
<br>
<b>Time Left:</b>$bantl2
<br>
<b>Reason:</b>$banreason2
<br>
<b>-----------------------------------------------</b>
</p>
            <p></p>
            </div>
        ";

    }
    else

it is All About variable you used
banner1 & bantl1 & bantl2 & Etc ....
Define it First :)

$banner1 = "";
$bantl1 = "";

Define it First :)

I did at lines 28-34

I did at lines 28-34

Only if there is a row returned. If no records are returned from your query, your variables are undefined.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.