-1

I have tried over 32 uploaded solutions, and nothing seems to be right -- Can anyone assist me? I am getting undefined indexes, and when I solve those issues, I keep getting the fatal error listed below. No idea what I am doing wrong. ?_? Can someone enlighten me?

P.S; It's not a duplicate, fatal error included, not apart of the duplicate post, nor any relevancy.

Errors

Notice: Undefined index: somename in /homepages/29/d599905820/htdocs/index.php on line 22 

Notice: Undefined index: username in /homepages/29/d599905820/htdocs/index.php on line 23 

Fatal error: Call to undefined method PDOStatement::bind_param() in /homepages/29/d599905820/htdocs/index.php on line 26

HTML

 <form action="" method = "POST">
      <input type="radio" name="someName" value="ip"> IP<br>
      <input type="radio" name="someName" value="uid"> UID<br>
      Enter Name: <input type="text" name="name" > <br>
      <input type="submit" name="submit">
    </form>

PHP

    <?php
            error_reporting(E_ALL);
            $submit=isset($_POST['submit']);
            if($submit)  
{
              $name=$_POST['somename'];
              $username=$_POST['username'];
              $con = new PDO('mysql:host='.$db_hostname.';dbname='.$db_database.';charset=utf8mb4', $db_termname,$db_password, array(PDO::ATTR_EMULATE_PREPARES => false,PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
              $stm=$con->prepare('SELECT * FROM users WHERE username = ?');
              $stm->bind_param("s",$username);
              $stmt->execute();
              $row = $stm->fetch(PDO::FETCH_ASSOC);
              if($name=='ip')
        {                       echo $row['ip'];  
        }
               else if($name=='uid')  
          {
                    echo $row['uid];
           }
 }
Comradeo
  • 85
  • 11
  • 1
    PDO doesn't have a `bind_param` method. You're mixing things up with mysqli. – Jonnix May 22 '16 at 10:36
  • @JonStirling How do I substitute? Or what do I do? – Comradeo May 22 '16 at 10:40
  • @TheCodesee Is the undefined variables and index linked to the fatal error, or is it the fact that PDO doesn't have a bind_param method? – Comradeo May 22 '16 at 10:41
  • @Comradeo Start by reading the [docs](http://php.net/pdo) and you'll see all the available methods. – Jonnix May 22 '16 at 10:42
  • *"P.S; It's not a duplicate"* - Yes it is and for a few. [PHP: “Notice: Undefined variable” and “Notice: Undefined index”](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) and [Can I mix MySQL APIs in PHP?](http://stackoverflow.com/questions/17498216/can-i-mix-mysql-apis-in-php) - which checking for the real errors, would have told you about it. – Funk Forty Niner May 22 '16 at 12:46
  • @Fred-ii- Your implicating a duplicate of two posts, how can it be a duplicate if they are totally irrelevant and are addressing certain situations? That's ludicrous. – Comradeo May 23 '16 at 05:49

2 Answers2

1

You are mixing PDO with mysql and there are multiple syntax errors. Your code should be like this:

<?php
error_reporting(E_ALL);
$submit = $_POST['submit'];
if($submit) {
   $name = $_POST['somename'];
   $username = $_POST['username'];
   $con = new PDO('mysql:host='.$db_hostname.';dbname='.$db_database.';charset=utf8mb4', $db_termname,$db_password, array(PDO::ATTR_EMULATE_PREPARES => false,PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
   $stmt = $con->prepare('SELECT * FROM users WHERE username=:username');
   $stmt->bindParam(":username", $username);
   $stmt->execute();
   $row = $stmt->fetch(PDO::FETCH_ASSOC);
   if($name=='ip') {                       
      echo $row['ip'];  
   }elseif
      ($name=='uid') {
         echo $row['uid];
      }
}
?>

<form action="" method="POST">
  <input type="radio" name="somename" value="ip">IP<br>
  <input type="radio" name="somename" value="uid">UID<br>
  Enter Name: <input type="text" name="username">
  <br>
  <input type="submit" name="submit">
</form>

If I don't have any records for 'UID' or 'IP' how can I make a case in PHP that echoes 'No records found?

if($name=='ip') {  
   if($row['ip'] == 'ip') {
      echo 'Result!';
   }else{ 
      echo 'No Result!';
   }
}

if($name=='uid') {  
   if($row['uid'] == 'uid') {
      echo 'Result!';
   }else{ 
      echo 'No Result!';
   }
}
The Codesee
  • 3,714
  • 5
  • 38
  • 78
0

You are using wrong name in your html, someName instead of somename, and username is missing on your form :

HTML

   <form action="" method = "POST">
     <input type="radio" name="somename" value="ip"> IP<br>
     <input type="radio" name="somename" value="uid"> UID<br>
     Enter Name: <input type="text" name="username" > <br>
     <input type="submit" name="submit">
   </form>
Sofiene Djebali
  • 4,398
  • 1
  • 21
  • 27