2 Replies - 224 Views - Last Post: 19 October 2017 - 05:37 AM Rate Topic: -----

#1 sadaiyappan_  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 04-October 17

How do I search through a database to find match?

Posted 19 October 2017 - 05:25 AM

here is my code so far:

<?php
	
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'test');

/* Attempt to connect to MySQL database */
$conn = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

$sql = "SELECT name, password FROM stuff";




All I did was set up query. Now how do I create or setup an if statement to search through the "name" column in "stuff" table of the "test" database to find a match for the input of my "name" field on my form which is in a different .php page?

Then I have to repeat this for password then I have to echo a statement to say success or fail.

Is This A Good Question/Topic? 0
  • +

Replies To: How do I search through a database to find match?

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4136
  • View blog
  • Posts: 13,058
  • Joined: 08-June 10

Re: How do I search through a database to find match?

Posted 19 October 2017 - 05:29 AM

View Postsadaiyappan_, on 19 October 2017 - 02:25 PM, said:

Now how do I create or setup an if statement to search through the "name" column in "stuff" table of the "test" database to find a match for the input of my "name" field on my form which is in a different .php page?


You don't. You let SQL do it:

SELECT TRUE FROM stuff WHERE name = ? AND password = ?

although you should never store plain passwords anywhere.

This post has been edited by Dormilich: 19 October 2017 - 05:30 AM

Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is offline

  • the case is sol-ved
  • member icon

Reputation: 6379
  • View blog
  • Posts: 25,774
  • Joined: 12-December 12

Re: How do I search through a database to find match?

Posted 19 October 2017 - 05:37 AM

WHERE clause

... or any other basic SQL book or tutorial. What material are you using to study SQL?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1