How to use form data in MySql query?

  • eljay
    Answered on April 10, 2020 10:26 AM

    I am unable to figure out how to enter data into a form and then query mysql with the form entries and output the results:



    columns include but are not limited to labor, day, hours, etc.

    form includes entry for 1. Drivers: trucks, cars, fork lifts; 2. Days: mon, tues, wed... ; Hours: day, afternoons, nights.

    If I make entries into the form 1. trucks, 2: wed, 3: day then my query resembles SELECT * FROM work WHERE drivers = trucks AND days = mon AND hours = days then I want to enter the form data into a mysqli query and output which drivers drove a truck on the day shift on Monday.

    Been pulling my hair out trying to get this to work.

  • Bojan Support Team Lead
    Answered on April 10, 2020 10:52 AM

    Greetings and thank you for your message.

    If I understood you correctly, you wish to pull data from your table depending on the answers in the Form? If this is the case, then you need to modify your SQL query to include answers from the form:

    $query = 'SELECT * FROM work WHERE drivers = "' . $_POST['Drivers'] . '" AND days = "' . $_POST['Days'] . '" AND hours = "' . $_POST['Hours'] . '"';

    You can always echo $query variable to see if it's filled properly.

    To see additional information about this subject, please click here.

    Thank you for your cooperation.