djdellux Posted November 20, 2008 Share Posted November 20, 2008 i need to dynamically use this code to pull query from a db from user inputs suggestions on improvements or anything welcome <html> <head> <title>Loggin DB</title> </head> <body> <h1 align=left>Please enter search feilds:</h1> <body bgcolor="#82CAFA"> <form method="get" action="loggin1.php"> Page: <select name="Page"> <option value="approve.php" >Approve</option> <option value="custquery" >CustQuery</option> <option value="slpnlogin">SlpnLogin</option> </select> User Code: <select name="UserCode"> <option >T3</option> <option >J9</option> <option>BL</option> <option >SC</option> <option >MN</option> <option >CA</option> <option>MW</option> <option >TJ</option> <option >E2</option> <option >D6</option> <option >SS</option> <option >R9</option> <option >GL</option> <option >MP</option> <option >RW</option> </select> Date: <input type="text" name="Date"> <p><input name="submitted" type="submit" value="send"/></p></form> <?php $db = $_SERVER['DOCUMENT_ROOT']."/../data/log.db"; //connect to sql $handle = sqlite_open($db); $query = "SELECT * FROM log where id < 85076"; if(isset($_GET['submitted']) && $_GET["submitted"] == "send")// line check { if ($_GET["Page"] !="") { $query.=" and page='" .$_GET["Page"]."'"; } if ($_GET["UserCode"] !="") { $query.=" and userCode=\"" .$_GET["UserCode"]."\""; } if(isset($_GET["time"])) { $query.=" and time='" .$_GET["Time"].""; } } echo $query;// show the result of the search $result = sqlite_query($handle, $query); $row = sqlite_fetch_array( $result ); echo "<style type='text/css'> table { border-width: 1px; border-spacing:0px ; border-style: double; border-color: black; border-collapse: separate; background-color: #82CAFA; } table th { border-width: 1px; padding: 0px; border-style: solid; border-color: black; background-color: #82CAFA; } table td { border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #82CAFA; } </style> <table class='db'; cellspacing=\"0px\">"; while($row = sqlite_fetch_array($result)){ echo " <tr>\n"; echo " <td> $row[id]</td><td> $row </td> <td> $row[desc] </td><td> $row[userCode] </td><td> $row[codeType] </td><td>". date( "Y-m-d", $row['time'])."</td><td> $row[ipaddr]</td>\n"; echo " </tr>\n"; } echo "</table>"; ?> </html> Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/ Share on other sites More sharing options...
djdellux Posted November 20, 2008 Author Share Posted November 20, 2008 i am having a problem with the date query. no matter what i put in it retrieves what it wants lol Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694343 Share on other sites More sharing options...
revraz Posted November 20, 2008 Share Posted November 20, 2008 I dont see any Date in there, just a time. Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694344 Share on other sites More sharing options...
JonnoTheDev Posted November 20, 2008 Share Posted November 20, 2008 Check your field names. <input type="text" name="Date"> if(isset($_GET["time"])) { $query.=" and time='" .$_GET["Time"].""; } Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694347 Share on other sites More sharing options...
djdellux Posted November 20, 2008 Author Share Posted November 20, 2008 ok i see the issue with the input which i have changed Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694353 Share on other sites More sharing options...
djdellux Posted November 20, 2008 Author Share Posted November 20, 2008 'time' is how the db is stated. i know that it has to be verbatim to actually see it mi sqlite correct?? Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694355 Share on other sites More sharing options...
revraz Posted November 20, 2008 Share Posted November 20, 2008 Depends on how you structure your query. Do you want an exact time? Do you want to search after a time, before a time, between times? You can do it however you like. Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694357 Share on other sites More sharing options...
djdellux Posted November 20, 2008 Author Share Posted November 20, 2008 i would like to do it as you can search a specific date if you would like but if you don't have a date it will still return a request based on the other search criteria Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694359 Share on other sites More sharing options...
revraz Posted November 20, 2008 Share Posted November 20, 2008 Show us an example of the data in the Time field in your DB. Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694361 Share on other sites More sharing options...
djdellux Posted November 20, 2008 Author Share Posted November 20, 2008 its in unix Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694366 Share on other sites More sharing options...
JonnoTheDev Posted November 20, 2008 Share Posted November 20, 2008 convert the user date entry to a unix timestamp strtotime("2008-20-11"); Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694371 Share on other sites More sharing options...
djdellux Posted November 20, 2008 Author Share Posted November 20, 2008 where am i inserting this line at? Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694373 Share on other sites More sharing options...
JonnoTheDev Posted November 20, 2008 Share Posted November 20, 2008 If the date record in your database is stored as a timestamp then you need to convert the user entered date into a timestamp. What is the format users will enter a date? d-m-Y or Y-m-d? Example if(isset($_GET["Date"])) { $date = strtotime($_GET["Date"]); $query.=" and time='" .$date.""; } If users are entering a date to search the database then the field type should be a date and not a unix timestamp. Not used sqllite does it have a FROM_UNIXTIME function that you could use? Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694382 Share on other sites More sharing options...
djdellux Posted November 20, 2008 Author Share Posted November 20, 2008 the format is y-m-d and i am not aware of sqlite having a FROM_UNIXTIME function Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694383 Share on other sites More sharing options...
djdellux Posted November 20, 2008 Author Share Posted November 20, 2008 ok this is what i have and maybe this line of work is not for me... mind you i have only one week experience in this feild.. i was a thc guy never a programer. i would love to get into this feild but i have 3 months to get this shit down and i am frusturated to all hell right now. any suggestions to help me get thru this and move foward to getting this under my belt <html> <head> <title>Loggin DB</title> </head> <body> <h1 align=left>Please enter search feilds:</h1> <body bgcolor="#82CAFA"> <form method="get" action="loggin1.php"> Page: <select name="Page"> <option value="approve.php" >Approve</option> <option value="custquery" >CustQuery</option> <option value="slpnlogin">SlpnLogin</option> </select> User Code: <select name="UserCode"> <option >T3</option> <option >J9</option> <option>BL</option> <option >SC</option> <option >MN</option> <option >CA</option> <option>MW</option> <option >TJ</option> <option >E2</option> <option >D6</option> <option >SS</option> <option >R9</option> <option >GL</option> <option >MP</option> <option >RW</option> </select> Date: <input type="text" name="time"> <p><input name="submitted" type="submit" value="send"/></p></form> <?php $db = $_SERVER['DOCUMENT_ROOT']."/../data/log.db"; //connect to sql $handle = sqlite_open($db); $query = "SELECT * FROM log where id > 85076"; if(isset($_GET['submitted']) && $_GET["submitted"] == "send")// line check { if ($_GET["Page"] !="") { $query.=" and page='" .$_GET["Page"]."'"; } if ($_GET["UserCode"] !="") { $query.=" and userCode=\"" .$_GET["UserCode"]."\""; } if(isset($_GET["time"])) { $time = strtotime($_GET["time"]); $query.=" and time <='" .$time.""; } } echo $query;// show the result of the search $result = sqlite_query($handle, $query); $row = sqlite_fetch_array( $result ); echo "<style type='text/css'> table { border-width: 1px; border-spacing:0px ; border-style: double; border-color: black; border-collapse: separate; background-color: #82CAFA; } table th { border-width: 1px; padding: 0px; border-style: solid; border-color: black; background-color: #82CAFA; } table td { border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #82CAFA; } </style> <table class='db'; cellspacing=\"0px\">"; while($row = sqlite_fetch_array($result)){ echo " <tr>\n"; echo " <td> $row[id]</td><td> $row </td> <td> $row[desc] </td><td> $row[userCode] </td><td> $row[codeType] </td><td>". date( "Y-m-d", $row['time'])."</td><td> $row[ipaddr]</td>\n"; echo " </tr>\n"; } echo "</table>"; ?> </html> Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694430 Share on other sites More sharing options...
djdellux Posted November 20, 2008 Author Share Posted November 20, 2008 ok fuckin sweet thanks Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694447 Share on other sites More sharing options...
djdellux Posted November 20, 2008 Author Share Posted November 20, 2008 .......... no one??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694517 Share on other sites More sharing options...
Maq Posted November 20, 2008 Share Posted November 20, 2008 1) You should use a proper model. Put your PHP code at the top except where you echo out HTML. 2) Of course you're not getting correct results. You are using the GET method but need to use the POST method. 3) What exactly does this mean? What is your input? What is the output? Is there a pattern? i am having a problem with the date query. no matter what i put in it retrieves what it wants lol Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694568 Share on other sites More sharing options...
djdellux Posted November 20, 2008 Author Share Posted November 20, 2008 Maq i have spent the last 3hrs on this and got it worked out...lol...where were u 3 hrs ago hahaha lmao thanks mate i do appreciate the input bro. Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694577 Share on other sites More sharing options...
Maq Posted November 20, 2008 Share Posted November 20, 2008 At work, glad you got everything figured out. Mark it solved next time!!! Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694580 Share on other sites More sharing options...
djdellux Posted November 20, 2008 Author Share Posted November 20, 2008 yeah im also on the daily grind lol being marked now!!!! lol Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694584 Share on other sites More sharing options...
Maq Posted November 20, 2008 Share Posted November 20, 2008 TY Quote Link to comment https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/#findComment-694588 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.