1. Home >
  2. Apps >
  3. Groups >

Help Required on PHP

Question asked by techbkr3 in #PHP on Sep 1, 2012
techbkr3
techbkr3 · Sep 1, 2012
Member of CrazyEngineers
Excuse me CEans,

I am trying to retrieve the data from MySQL Database using WHERE function, but here i want to check WHERE='123' as input. To say clearly (i.e) WHERE=%INPUT%

thereby i can enter some input on dialog box and by clicking a button, the input given is used to retrieve the data via WHERE function.

Any Examples ??

or should i go ahead with JS ? Posted in: #PHP
[Prototype]
[Prototype] · Sep 1, 2012
Member of CrazyEngineers
You're facing problem in query or taking input?

In php, you can use the GET & POST request to transfer the input.
techbkr3
techbkr3 · Sep 2, 2012
Member of CrazyEngineers
[Prototype]
Thanks for your reply !
Let me check about that and get back to you soon 😀

P.S: Actually, i am not facing any problems here. I am seeking for the technique usage of WHERE function(MySQL) using user-defined input.
Prasad Ajinkya
Prasad Ajinkya · Sep 3, 2012
Member of CrazyEngineers
Tech, I could type this out in this forum, but this link on php.net explains it with sample code - https://www.php.net/manual/en/mysql.examples-basic.php

Your WHERE clause is part of your mysql query. Its not part of PHP

HTH
sulochana anand
sulochana anand · Sep 3, 2012
Member of CrazyEngineers
[Prototype]
You're facing problem in query or taking input?

In php, you can use the GET & POST request to transfer the input.
hi i m
Beginner for php.i installed it on my system.typed code in notepad.after that wat should i do to run php.
Manish Goyal
Manish Goyal · Sep 3, 2012
Member of CrazyEngineers
sulochana anand
hi i m
Beginner for php.i installed it on my system.typed code in notepad.after that wat should i do to run php.
You can Install some open source servers like wampp or xampp in your system, then put your php inside htdocs folder , after that you can run your file using your browser
by typing

https://localhost/filename.php
sulochana anand
sulochana anand · Sep 3, 2012
Member of CrazyEngineers
is htdocs predefined folder
Manish Goyal
Manish Goyal · Sep 3, 2012
Member of CrazyEngineers
Yes when you will install these server, htdocs will be inside it

You just need to place your files there
sulochana anand
sulochana anand · Sep 3, 2012
Member of CrazyEngineers
ok thanks i will try to do so.
Harish Kotra
Harish Kotra · Sep 4, 2012
Member of CrazyEngineers
Okay, I guess I will get you the working script completely here in this reply. As you said you need to enter a text and clicking button should retrieve it from the database.

- Create a form and remember POST is an ideal method in the forms usually.






- Now the PHP code to connect to the data base first and then search for what you actually need.


$dbuser = "user_access"; //username you created
$dbpass = "Anonym0us"; //password for the user

//variable to connect to the database
$con = mysql_connect("localhost","user_access","Anonym0us");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

//Connect to the database you created.

mysql_select_db("my_db", $con);

if($_POST['search'] == 'Search')
{

//foreach loop I am using here is just for a bit of security. You can do it directly also.
foreach($_POST as $key => $value) {
$data[$key] = filter($value);
}

$searchele = $data['ele'];

//tablename to be replaced with your table.
//rowname should be replaced with the row you want to search in.
//Coded by me Harish Kotra
$search = mysql_query("select * from tablename where rowname like '%$searchele%'");

while ($row = mysql_fetch_array($search)){
echo $row['rowname'];
}
}
?>

You must log-in or sign-up to reply to this post.

Click to Log-In or Sign-Up