Help Required on PHP

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 ?

Replies

  • [Prototype]
    [Prototype]
    You're facing problem in query or taking input?

    In php, you can use the GET & POST request to transfer the input.
  • techbkr3
    techbkr3
    #-Link-Snipped-#
    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
    Tech, I could type this out in this forum, but this link on php.net explains it with sample code - PHP: MySQL extension overview example - Manual

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

    HTH
  • sulochana anand
    sulochana anand
    [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
    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

    #-Link-Snipped-#
  • sulochana anand
    sulochana anand
    is htdocs predefined folder
  • Manish Goyal
    Manish Goyal
    Yes when you will install these server, htdocs will be inside it

    You just need to place your files there
  • sulochana anand
    sulochana anand
    ok thanks i will try to do so.
  • Harish Kotra
    Harish Kotra
    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 are reading an archived discussion.

Related Posts

please if anybody having data mining projects please send........i need urgently to submit my madam at monday so plese send before monday(if u are having)
IBM is back with their award winning event - The Great Mind Challenge 2012. The event is open for all the engineering students from all over India to find the...
hey need ur help CEIANS..... how sms alerts or email alerts are been sent to one's mobile or mail id
I have a problem regarding displaying the time table in c language Can anyone help me i have to read a file as input containing 3 columns of timeslot ,...
hi can u give ideas regarding recent trends in power electronics...for taking seminar