Jump to content

[SOLVED] dynamics in this code


djdellux

Recommended Posts


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>

Link to comment
https://forums.phpfreaks.com/topic/133498-solved-dynamics-in-this-code/
Share on other sites

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?


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>

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.