PHP Query MYSQL - little help

Hello guys,

I need a little help with some php and MySQL queries. I have one application made by someone from GitHub that I will like to modify a little for my needs. The aplications is a FIAS-PMS from pbxinaflash with witch you can checkin, checkout and set wakeup call for one extension. The goal is to create a different report for extension used by office and guests. For guests is working perfectly.

The code looks like this :

$dbconnection = mysql_connect($dbhost, $dbuser, $dbpass) or die(“Database connection failed”);
mysql_select_db($dbname) or die(“data base Hotel-Rooms open failed”);

     $query = "SELECT `ID`, `Desc` FROM `Rooms` ORDER BY `Desc` ASC";
     $result = mysql_query($query) or die ("Couldn't execute SQL query on Hotel-Users table.") ;
mysql_close($dbconnection);
echo " <SELECT ID=\"RoomsComboBox\" NAME=\"RoomsComboBox\">";
echo "<OPTION VALUE=\"ALL\" SELECTED> ".$SecLab22." </OPTION>";
while ($row = mysql_fetch_array($result))  {
echo "<OPTION VALUE=\"$row[0]\">" . $row[1] . "</OPTION>";
}
echo "</SELECT>";

echo “” ;
echo “

<INPUT TYPE=“SUBMIT” NAME=“SearchButton” VALUE=”".$SecLab21."">\n" ;
echo “\n” ;
echo “\n”;
echo “\n”;

if(isset($_POST[‘SearchButton’])) :

echo

\n” ;
echo “" ;
$dbconnection

= mysql_connect($dbhost, $dbuser, $dbpass) or die(“Database connection failed”);
mysql_select_db($dbname) or die(“data base Hotel-Rates open failed”);

$between = '';
$room = '';

    $query = "SELECT * FROM `Users`";
    $RoomsComboBox = $_POST['RoomsComboBox'];

$FROMD = $_POST['FROMD'] ;
$FROMM = $_POST['FROMM'] ;
$FROMY = $_POST['FROMY'] ;

$TOD = $_POST['TOD'] ;
$TOM = $_POST['TOM'] ;
$TOY = $_POST['TOY'] ;

if ($RoomsComboBox !== 'ALL') {
    $room = " `Room` = '" . $RoomsComboBox . "'";
}

if ($FROMD !== '' AND $FROMM !== '' AND $FROMY !== '') {
    $from = " `Checkout` >= '" . $FROMY . "-" . $FROMM . "-" . $FROMD . "'";
    if ($TOD !== '' AND $TOM !== '' AND $TOY !== '') {
        $to = " AND `Checkout` <= '" . $TOY . "-" . $TOM . "-" . $TOD . "'";
    }
$between = $from . $to;
}


If ($between !== '' OR $room !== '') {
    $query = $query . " WHERE" ;
}

If ($between !== '' AND $room !== '') {
    $query = $query . $between . " AND" . $room;
}

If ($between !== '' AND $room == '') {
    $query = $query . $between;
}

If ($between == '' AND $room !== '') {
    $query = $query . $room;
}

$query = $query . " ORDER BY ID DESC";
//printf($query);

What I did :
From :
$query = “SELECT ID, Desc FROM Rooms ORDER BY Desc ASC” ;
to
$query = “SELECT ID, Desc FROM Rooms WHERE Desc = ‘Frontoffice’ OR Desc = ‘Backoffice’ OR Desc = ‘Manager’ ORDER BY Desc ASC” ;

from :
$query = "SELECT * FROM Users";
to
$query = "SELECT * FROM Users WHERE Desc = ‘Frontoffice’ OR Desc = ‘Backoffice’ OR Desc = ‘Manager’ " ;

Partial is working, I can see in the combobox only office extensions, i can search if i peek " all " from dropdown , but if i choose something else for exemple Frontoffice and click search the page is replaying with one error.

The date search is not working at all. I have to advice you guys, i don`t know php and MySQL just some very basics :slight_smile: Please can someone help me with some syntaxs ? Thanks a lot.

Id ”.$SecLab7." ".$SecLab14." ".$SecLab15." ".$SecLab17." ".$SecLab31." ".$SecLab1."

This code is complete obsolete junk. Stop copy/pasting from the net and learn what you are doing.

Thanks for your replay. Well if you say so i have to trust you because i dont know php. But this junk is working properly it makes a report for all the extension well, the problem it is now when im trying to modify a little but.

By mistake i miss the last part of think junk code :slight_smile:

$query = $query . " ORDER BY ID DESC";
//printf($query);

$result = mysql_query($query) or die("Web site query failed");
mysql_close($dbconnection);
while ($row = mysql_fetch_array($result)) {
echo "<TR><TD><FONT face=verdana,sans-serif>" . $row["ID"] . "</TD><TD>" . $row["Desc"]  . "</TD><TD>" .$row["Name"] ."</TD><TD>" . $row["Checkin"] . "</TD><TD>" . $row["Checkout"] . "</TD><TD>" . $row["Total"] . "</TD><TD><a href=\"ec.php?Ext=" .$row["Ext"] . "&Checkin=" . $row["Checkin"] . "&Checkout=" . $row["Checkout"] ."\">".$SecLab29."</a></TD></TR>\n" ;
}

echo “\n”;
endif;

Try running your junk code in Php 7 and tell me how that works out for you.

Are you trying to be funny or what ?
I dont want to learn PHP is to complicated for me and i do not likeit. I prefer my networking protocols.
Here i was thinking that someone can help me, for sure there is just a syntax wrong, someone who realy knows php…

You said your code works. It won’t work at all in current versions of Php.

Thanks, i know that from php5 is not anymore compatibile, i know that looks like is made 13 years a go.
But do you understand what is there and what could be the problem ?
Because for me is ok, im using the app on a local server witch for the next 1-2 years i will not upgrade.

I know it’s used on a local server, but if you on insist on using obsolete code the odds of you finding help are pretty remote online unless you either get a dinosaur php programmer to help you (it would help stating your case) or you do intensive searches on Google for there is a lot of obsolete code floating around that might solve the problem(s). You might want to even search forums for they have a lot of threads that date years back that might solve you problem.

All I know is I hope you are still around 1-2 years when this needs upgrade, for a new person trying to debug this will probably be pulling out her or his hair. :o To top it off there is no commenting at all to help the poor soul out.

Thank you Strider, that kind of comment i can accept. I got it, the only way is google and google to find something.

Moderators : please close this topic, the problem does not exists anymore.

Sponsor our Newsletter | Privacy Policy | Terms of Service