CrazyEngineers
  • Help Required on PHP

    techbkr3

    techbkr3

    @techbkr3-gsED1X
    Updated: Oct 25, 2024
    Views: 1.4K
    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 ?
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • [Prototype]

    MemberSep 1, 2012

    You're facing problem in query or taking input?

    In php, you can use the GET & POST request to transfer the input.
    Are you sure? This action cannot be undone.
    Cancel
  • techbkr3

    MemberSep 1, 2012

    #-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.
    Are you sure? This action cannot be undone.
    Cancel
  • Prasad Ajinkya

    MemberSep 2, 2012

    Tech, I could type this out in this forum, but this link on php.net explains it with sample code - <a href="https://www.php.net/manual/en/mysql.examples-basic.php" target="_blank" rel="nofollow noopener noreferrer">PHP: MySQL extension overview example - Manual</a>

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

    HTH
    Are you sure? This action cannot be undone.
    Cancel
  • sulochana anand

    MemberSep 3, 2012

    [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.
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberSep 3, 2012

    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-#
    Are you sure? This action cannot be undone.
    Cancel
  • sulochana anand

    MemberSep 3, 2012

    is htdocs predefined folder
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberSep 3, 2012

    Yes when you will install these server, htdocs will be inside it

    You just need to place your files there
    Are you sure? This action cannot be undone.
    Cancel
  • sulochana anand

    MemberSep 3, 2012

    ok thanks i will try to do so.
    Are you sure? This action cannot be undone.
    Cancel
  • Harish Kotra

    MemberSep 4, 2012

    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.

    <form action="search.php" method="POST">
    <input type="text" name="ele" />
    <input type="Submit" name="submit" value="Submit" />
    </form>

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

    <?php

    $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'];
    }
    }
    ?>
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register