php - Outdated MYSQL database codes failing to fetch data -


i asked previous question data sql database failing fetch data. did database connection server , shows "successfully connected" codes outdated, server failing fetch data sql database. suggested use pdo beginner so, correct codes "search.php":

<?php error_reporting(0); include("config.php"); ?>  <html>  <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>mysql table search</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> <style> body, td { font-family:arial, helvetica, sans-serif; font-size:12px; } </style> </head>   <body>  <form id="form1" name="form1" method="post" action="search.php"> <label for="from">from</label> <input name="from" type="text" id="from" size="10" value="<?php echo $_request["from"]; ?>" /> <label for="to">to</label> <input name="to" type="text" id="to" size="10" value="<?php echo $_request["to"]; ?>"/> <label>hotels:</label> <input type="text" name="string" id="string" value="<?php echo stripcslashes($_request["string"]); ?>" /> <label>city</label> <select name="city"> <option value="">--</option> <?php $sql = "select * ".$settings["data_table"]." group city order city"; $sql_result = mysql_query ($sql, $connection ) or die ('request "could not execute sql query" '.$sql); while ($row = mysql_fetch_assoc($sql_result)) { echo "<option value='".$row["city"]."'".($row["city"]==$_request["city"] ? " selected" : "").">".$row["city"]."</option>"; } ?> </select> <label>star</label> <select name="star"> <option value="">--</option> <?php $sql = "select * ".$settings["data_table"]." group star order star"; $sql_result = mysql_query ($sql, $connection ) or die ('request "could not execute sql query" '.$sql); while ($row = mysql_fetch_assoc($sql_result)) { echo "<option value='".$row["star"]."'".($row["star"]==$_request["star"] ? " selected" : "").">".$row["star"]."</option>"; } ?> </select> <input type="submit" name="button" id="button" value="filter" /> </label> <button><a style="text-decoration:none;" href="search.php">reset</a></button> </form> <br /><br /> <table width="700" border="1" cellspacing="0" cellpadding="4"> <tr> <td width="90" bgcolor="#cccccc"><strong>from date</strong></td> <td width="95" bgcolor="#cccccc"><strong>to date</strong></td> <td width="159" bgcolor="#cccccc"><strong>hotel name</strong></td> <td width="191" bgcolor="#cccccc"><strong>email</strong></td> <td width="113" bgcolor="#cccccc"><strong>city</strong></td> <td width="113" bgcolor="#cccccc"><strong>star</strong></td> <td width="113" bgcolor="#cccccc"><strong>links</strong></td> </tr> <?php if ($_request["string"]<>'') { $search_string = " , (hotel '%".mysql_real_escape_string($_request["string"])."%' or email '%".mysql_real_escape_string($_request["string"])."%')";  } if ($_request["city"]<>'') { $search_city = " , city='".mysql_real_escape_string($_request["city"])."'";    } if ($_request["star"]<>'') { $search_star = " , star='".mysql_real_escape_string($_request["star"])."'";    } if ($_request["links"]<>'') { $search_links = " , links='".mysql_real_escape_string($_request["links"])."'";     } if ($_request["from"]<>'' , $_request["to"]<>'') { $sql = "select * ".$settings["data_table"]." from_date >= '".mysql_real_escape_string($_request["from"])."' , to_date <= '".mysql_real_escape_string($_request["to"])."'".$search_string.$search_city.$search_string.$search_star.$search_string.$search_links; } else if ($_request["from"]<>'') { $sql = "select * ".$settings["data_table"]." from_date >= '".mysql_real_escape_string($_request["from"])."'".$search_string.$search_city.$    search_string.$search_star.$search_string.$search_links; } else if ($_request["to"]<>'') { $sql = "select * ".$settings["data_table"]." to_date <= '".mysql_real_escape_string($_request["to"])."'".$search_string.$search_city.$search_string.$search_star.$search_string.$search_links; } else { $sql = "select * ".$settings["data_table"]." id>0".$search_string.$search_city.$search_string.$search_star.$search_string.$search_links; }  $sql_result = mysql_query ($sql, $connection ) or die ('request "could not execute sql query" '.$sql); if (mysql_num_rows($sql_result)>0) { while ($row = mysql_fetch_assoc($sql_result)) { ?> <tr> <td><?php echo $row["from_date"]; ?></td> <td><?php echo $row["to_date"]; ?></td> <td><?php echo $row["hotel"]; ?></td> <td><?php echo $row["email"]; ?></td> <td><?php echo $row["city"]; ?></td> <td><?php echo $row["star"]; ?></td> <td><?php echo $row["links"]; ?></td> </tr> <?php } } else { ?> <tr><td colspan="7">no results found.</td> <?php    } ?> </table> <script> $(function() { var dates = $( "#from, #to" ).datepicker({ defaultdate: "+1w", changemonth: true, numberofmonths: 2, dateformat: 'yy-mm-dd', onselect: function( selecteddate ) { var option = this.id == "from" ? "mindate" : "maxdate", instance = $( ).data( "datepicker" ), date = $.datepicker.parsedate( instance.settings.dateformat || $.datepicker._defaults.dateformat, selecteddate, instance.settings ); dates.not( ).datepicker( "option", option, date ); } }); }); </script>  </body> </html> 

you need learn use pdo , prepared statements. edited code, have changed mysql_ parts mysqli_. hope $sql , $connection works perfectly

<?php error_reporting(0); include("config.php"); ?>  <html>  <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>mysql table search</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> <style> body, td { font-family:arial, helvetica, sans-serif; font-size:12px; } </style> </head>   <body>  <form id="form1" name="form1" method="post" action="search.php"> <label for="from">from</label> <input name="from" type="text" id="from" size="10" value="<?php echo $_request["from"]; ?>" /> <label for="to">to</label> <input name="to" type="text" id="to" size="10" value="<?php echo $_request["to"]; ?>"/> <label>hotels:</label> <input type="text" name="string" id="string" value="<?php echo stripcslashes($_request["string"]); ?>" /> <label>city</label> <select name="city"> <option value="">--</option> <?php $sql = "select * ".$settings["data_table"]." group city order city"; $sql_result = mysql_query ($connection, $sql) or die ('request "could not execute sql query" '.$sql); while ($row = mysqli_fetch_assoc($sql_result)) { echo "<option value='".$row["city"]."'".($row["city"]==$_request["city"] ? " selected" : "").">".$row["city"]."</option>"; } ?> </select> <label>star</label> <select name="star"> <option value="">--</option> <?php $sql = "select * ".$settings["data_table"]." group star order star"; $sql_result = mysqli_query ($connection, $sql) or die ('request "could not execute sql query" '.$sql); while ($row = mysqli_fetch_assoc($sql_result)) { echo "<option value='".$row["star"]."'".($row["star"]==$_request["star"] ? " selected" : "").">".$row["star"]."</option>"; } ?> </select> <input type="submit" name="button" id="button" value="filter" /> </label> <button><a style="text-decoration:none;" href="search.php">reset</a></button> </form> <br /><br /> <table width="700" border="1" cellspacing="0" cellpadding="4"> <tr> <td width="90" bgcolor="#cccccc"><strong>from date</strong></td> <td width="95" bgcolor="#cccccc"><strong>to date</strong></td> <td width="159" bgcolor="#cccccc"><strong>hotel name</strong></td> <td width="191" bgcolor="#cccccc"><strong>email</strong></td> <td width="113" bgcolor="#cccccc"><strong>city</strong></td> <td width="113" bgcolor="#cccccc"><strong>star</strong></td> <td width="113" bgcolor="#cccccc"><strong>links</strong></td> </tr> <?php if ($_request["string"]<>'') { $search_string = " , (hotel '%".mysql_real_escape_string($_request["string"])."%' or email '%".mysql_real_escape_string($_request["string"])."%')";  } if ($_request["city"]<>'') { $search_city = " , city='".mysql_real_escape_string($_request["city"])."'";    } if ($_request["star"]<>'') { $search_star = " , star='".mysql_real_escape_string($_request["star"])."'";    } if ($_request["links"]<>'') { $search_links = " , links='".mysql_real_escape_string($_request["links"])."'";     } if ($_request["from"]<>'' , $_request["to"]<>'') { $sql = "select * ".$settings["data_table"]." from_date >= '".mysql_real_escape_string($_request["from"])."' , to_date <= '".mysql_real_escape_string($_request["to"])."'".$search_string.$search_city.$search_string.$search_star.$search_string.$search_links; } else if ($_request["from"]<>'') { $sql = "select * ".$settings["data_table"]." from_date >= '".mysql_real_escape_string($_request["from"])."'".$search_string.$search_city.$search_string.$search_star.$search_string.$search_links; } else if ($_request["to"]<>'') { $sql = "select * ".$settings["data_table"]." to_date <= '".mysql_real_escape_string($_request["to"])."'".$search_string.$search_city.$search_string.$search_star.$search_string.$search_links; } else { $sql = "select * ".$settings["data_table"]." id>0".$search_string.$search_city.$search_string.$search_star.$search_string.$search_links; }  $sql_result = mysqli_query ($connection,$sql) or die ('request "could not execute sql query" '.$sql); if (mysqli_num_rows($sql_result)>0) { while ($row = mysqli_fetch_assoc($sql_result)) { ?> <tr> <td><?php echo $row["from_date"]; ?></td> <td><?php echo $row["to_date"]; ?></td> <td><?php echo $row["hotel"]; ?></td> <td><?php echo $row["email"]; ?></td> <td><?php echo $row["city"]; ?></td> <td><?php echo $row["star"]; ?></td> <td><?php echo $row["links"]; ?></td> </tr> <?php } } else { ?> <tr><td colspan="7">no results found.</td> <?php    } ?> </table> <script> $(function() { var dates = $( "#from, #to" ).datepicker({ defaultdate: "+1w", changemonth: true, numberofmonths: 2, dateformat: 'yy-mm-dd', onselect: function( selecteddate ) { var option = this.id == "from" ? "mindate" : "maxdate", instance = $( ).data( "datepicker" ), date = $.datepicker.parsedate( instance.settings.dateformat || $.datepicker._defaults.dateformat, selecteddate, instance.settings ); dates.not( ).datepicker( "option", option, date ); } }); }); </script>  </body> </html> 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -