Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8948529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:01:00+00:00 2026-06-15T13:01:00+00:00

(PROBLEM IS VERY DETAILED FOR TOO LONG DIDN’T READ: My guess is that i’m

  • 0

(PROBLEM IS VERY DETAILED FOR TOO LONG DIDN’T READ: “My guess is that i’m using the MYSQL_FETCH_ARRAY wrong.”)

Hello! The following codes purpose is to do a basic search in the database. The data is passed by a form. The tutorial I was using was written by: ‘Frost of Slunked.com’ and it was a basic register/login php MySQL tutorial, which worked perfectly. I managed to write a woking table-updater function and form-submit to add new data to the selected (so that’s working as intended.

config.php – conncets to the MySQL server, selects the database, starts the session, requires the functions.php (with authors comments included)

<?php
/*****************************
    File: includes/config.php
    Written by: Frost of Slunked.com
    Tutorial: User Registration and Login System
******************************/
// start the session before any output.
session_start();

// Set the folder for our includes
$sFolder = ''; 

/***************
    Database Connection 
        You will need to change the user (user) 
        and password (password) to what your database information uses. 
        Same with the database name if you used something else.
****************/
mysql_connect('localhost', 'myusername', 'mypassword') or trigger_error("Unable to connect to the database: " . mysql_error());
mysql_select_db('tormex') or trigger_error("Unable to switch to the database: " . mysql_error());

/***************
    password salts are used to ensure a secure password
    hash and make your passwords much harder to be broken into
    Change these to be whatever you want, just try and limit them to
    10-20 characters each to avoid collisions. 
****************/
define('SALT1', '24859f@#$#@$');
define('SALT2', '^&@#_-=+Afda$#%');

// require the function file
require_once 'functions.php';

// default the error variable to empty.
$_SESSION['error'] = "";

// declare $sOutput so we do not have to do this on each page.
$sOutput="";
?>

functions.php – has multiple functions (login, createRide, Register etc.). Most of the functions purpose is to get the values from the submitted HTML forms and then maintain the required actions – I will only mentioned my searchRide function (which in my guess has the error or atleast, has to do something with it) and the createRide function, which is working properly.

<?php ...

unction searchRide($pWhen_min, $pWhen_max, $pFrom, $pTo){
    if (!empty($pWhen_min) && !empty($pWhen_max) && !empty($pFrom) && !empty($pTo)) {
        global $sql2, $query2;
        $sql2 = "SELECT * FROM ride WHERE `from` ='$pFrom' AND `to` = '$pTo' AND `when` >= '$pWhen_min' AND `when` <= '$pWhen_max' ";
        $query2 = mysql_query($sql2) or trigger_error("Query Failed: " . mysql_error());
    }
}
function createRide($pFrom, $pTo, $pWhen, $pSeats, $pPrice, $pCar){
    if (!empty($pFrom) && !empty($pTo) && !empty($pWhen) && !empty($pSeats) && !empty($pPrice) && !empty($pCar)){
        $sql = "SELECT id FROM users WHERE username= '" . $username . "' LIMIT 1";
        $result = mysql_query($sql);
        if(!$result) {
            trigger_error("ELKURTAD " . mysql_error());
        }
        $row = mysql_fetch_array($result);
        $sql = "INSERT INTO ride (`from`, `to`, `when`, `seats`, `price`, `car`, `u_id`)
        VALUES ('" . $pFrom . "', '" . $pTo . "', '" . $pWhen . "', 
        '" . $pSeats . "', '" . $pPrice . "', '" . $pCar . "', '" . $result . "');";


        $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error());

        if ($query) {
            return TRUE;
        } 
    }
    return FALSE;
}

...?>

searchRide.php – checks if the variables which are dedicated to get the search filter values have any values; (in the else statement) if there are no values, the form wasn’t submitted and displays the searchRide form and after result passes the variables for the searchRide.php ( $_SERVER[‘PHP_SELF’] )

<?php
require_once 'config.php';

$sOutput .= '<div id="searchRide-body">';

if (isset($_GET['action'])) {
    switch (strtolower($_GET['action'])) {
        case 'searchride':
        if (isset($_POST['when_min']) && isset($_POST['when_max']) && isset($_POST['from']) && isset($_POST['to'])) {
            if (searchRide($_POST['when_min'], $_POST['when_max'], $_POST['from'], $_POST['to'])) {
                while($row = mysql_fetch_array($query2)){
                    $sOutput .= "' ID: '" .$row['id'] . "' <br />
                    When: '" . $row['when'] . "' <br />
                    From: '" . $row['from'] . "' <br />
                    To: '" . $row['to'] . "' <br />
                    Seats left: '" . $row['seats'];

                }
            }
        }
    }
}else{
    if (isset($_SESSION['error'])) {
        $sError = '<span id="error">' . $_SESSION['error'] . '</span><br />';
    }

    $sOutput .= '<h2>Search for rides</h2>
        ' . $sError . '
        <form name="searchride" method="post" action="' . $_SERVER['PHP_SELF'] . '?action=searchride">
            From: <input type="text" name="from" value=* /><br />
            To: <input type="text" name="to" value=* />
            When_min: <input type="text" name="when_min" value=* />
            When_max: <input type="text" name="when_max" value=* />
            <br /><br />
            <input type="submit" name="submit" value="Search" />
        </form>
        <br />
        <h4>Would you like to <a href="index.php">Go back?</a></h4>';
}   
echo $sOutput . "<br />";

echo "TEST string" . "<br />";
echo $query2 . " query2<br /> ";
echo $sql2 . " sql2<br />";
echo $row . "<br />";
?>

At the end of this code You can see some printed variables, which are used to check their values after searRide form is submitted.
I updated my database with the following data and checked with phpMyAdmin for the exact values so I can test the search with existing data:

From: TEST01
To: TEST02
When: 500
Seats: 5
Price: 7
Car: volvo

Test data submitted with the searchRide form:
From: TEST01
To: Test02
When_min: 1
Whn_max: 3000

After is press Search button on the searchRide form these are the following results (what the browser shows):

(sOutput variable

TEST WRITE TEXT

Resource id #5 (query2 variable

SELECT * FROM ride WHERE from =’TEST01′ AND to = ‘TEST02’ AND when >= ‘1’ AND when <= ‘5000’ (sql2 variable

(row variable

After this I inserted the SQL query in the phpMyAdmin SQL command line and resulted the data I was searching for.

Was trying many times to figure out what could be the problem, with my own knowledge and varius searches on google, php.net and w3chools.com.
My guess is that i’m using the MYSQL_FETCH_ARRAY wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:01:01+00:00Added an answer on June 15, 2026 at 1:01 pm

    following condition will not work

    if (searchRide($_POST['when_min'], $_POST['when_max'], $_POST['from'], $_POST['to'])) {
    

    as you have not return any value from searchRide function you need to return true to go into the condition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello everyone my problem is very simple. Using entity framework code first I want
(Very detailed problem report -- tl;dr at the bottom!) I really prefer GLFW to
We are currently facing the following problem: We have an application that needs to
Possible Duplicate: Can main function call itself in C++? I found this problem very
My problem is very simple $('#button').removeAttr('type'); triggers an error on firebug type property can't
This problem seems very simple to me, but I've been unable to fix it,
This problem is very strange and I'm hoping someone can help me. For the
The problem seems very strange. I have a AJAX helper function within a same
My problem is very simple, yet I feel lost while looking at it ...
I have a big problem with very simple code. I need to get a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.