Jump to content

[SOLVED] whats wrong with this string???


djdellux

Recommended Posts

This is the string in question

******

<?php
$query.=" and page ='".$_GET["Page"]."'"," and userCode ='".$_GET["userCode"]."'", 'and time =.$_GET["time"].""';
?>

******

this is the error I recieve.

******

 

Parse error: parse error, unexpected ',' in c:\program files\Apache\htdocs\loggin1.php on line 36

******

A little help please

thanks

 

(edited by kenrbnsn to add


tags for readability)

Link to comment
Share on other sites


if this is any help this is the complete code...

**********

<html>

<head>

<title>Loggin DB</title>

</head>

<body>

<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="User Code">

<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>

</select>

Date:

<input type="text" name="Date">

<p><input type="submit" value="send"/></p></form>

<?php

echo $_GET['Page'];

$db = $_SERVER['DOCUMENT_ROOT']."/../data/log.db"; //connect to sql

$handle = sqlite_open($db);

$query = "SELECT * FROM  log where id > 85076";

if ($_GET["Page"] !="")

{

$query.=" 'and page" =.$_GET["Page"]. "and userCode" =.$_GET["userCode"]."and time" =.$_GET["time"]."";

}

echo $query;

$result = sqlite_query($handle, $query);

$row = sqlite_fetch_array( $result );

echo "<table>";

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
Share on other sites

I did not see where you modified the code to go with PFMa's. So here is another version, that would work also.

 

<?php
$query .= "and page='" . $_GET["Page"] . "' and userCode='" . $_GET["userCode"] . "' and time='" . $_GET["time"] . "'";
?>

 

That is the proper way to use concatenation. In your code about it would have been sql error galore due to no equals sign, no ' and no space between the last statement and "and". As seen above is the correct way to write the sql and use concatenation between variables.

Link to comment
Share on other sites

after inserting the string provided I received this

****************

Notice: Undefined index: userCode in c:\program files\Apache\htdocs\loggin1.php on line 36

 

Notice: Undefined index: time in c:\program files\Apache\htdocs\loggin1.php on line 36

SELECT * FROM log where id > 85076and page='approve.php' and userCode='' and time=''

*********************

holy wow... I'm confused hahaha.

Link to comment
Share on other sites

And the query in the full posted code is not even the same as in the first post in this thread.

 

To program you must first learn the syntax and meaning of the language(s) you are using. You are making a quoted string and assigning it to a php variable. The quoted string happens to be an SQL query statement. To this to work, you must both make the syntax of the quoted string correct and the SQL syntax in that string must be correct.

Link to comment
Share on other sites

Basically your GET data is not getting populated due to not checking if the form has been submitted. Sure you have the form output on that page but it has to be submitted first and you are not checking if it was submitted. To do this I added a hidden input with a name of "submitted" and a value of "yes" to the HTML.

 

<html>
<head>
<title>Loggin DB</title>
</head>
<body>
<body bgcolor="#82CAFA">
<form method="get" action="loggin1.php">
<input type="hidden" name="submitted" value="yes" />
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="User Code">
<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>
</select>
Date:
<input type="text" name="Date">
<p><input type="submit" value="send"/></p></form>
<?php
echo $_GET['Page'];
if (isset($_GET['submitted']) && $_GET["submitted"] == "yes")
{   
    $db = $_SERVER['DOCUMENT_ROOT']."/../data/log.db"; //connect to sql 
    $handle = sqlite_open($db);
    $query = "SELECT * FROM  log where id > 85076";

   $query .= " and page='" . $_GET["Page"] . "' and userCode='" . $_GET["userCode"] . "' and time='" . $_GET["time"] . "'";

    echo $query;
    $result = sqlite_query($handle, $query);
    $row = sqlite_fetch_array( $result );
    echo "<table>";
    while($row = sqlite_fetch_array($result)){
       echo "  <tr>\n";
       echo "    <td> " . $row['id'] . "</td><td>" . $row['page'] . "</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>

 

That way the code that requires the query will only run if the form has been submitted. Also modified the while loop, as how you were pulling the data/calling the data inside the echo statements was wrong. I would read up more on the syntax of PHP and variable usage in echos/strings.

Link to comment
Share on other sites


i am sorry because i am f*cking LOST!!!!!

  <html>

<head>

<title>Loggin DB</title>

</head>

<body>

<h1 align=left>Please enter search Fields</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>

</select>

Date:

<input type="text" name="Date">

<p><input type="submit" value="send"/></p></form>

<?php

echo $_GET['Page'];

$db = $_SERVER['DOCUMENT_ROOT']."/../data/log.db"; //connect to sql

$handle = sqlite_open($db);

$query = "SELECT * FROM  log where id > 85076";

if ($_GET["Page"] !="")

{

$query.=" and page='" .$_GET["Page"];

}

if ($_GET["UserCode"] !="")

{

$query.=" and userCode='" .$_GET["UserCode"];

}

if ($_GET["time"] !="")

{

$query.=" and time='" .$_GET["Time"]."";

}

echo $query;

$result = sqlite_query($handle, $query);

$row = sqlite_fetch_array( $result );

echo "<table>";

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>

 

 

this is what I have done and i am getting errors no matter what adjustments you have all suggested and im getting very frusturated.....

 

these are my errors

 

Notice: Undefined index: Page in c:\program files\Apache\htdocs\loggin1.php on line 31

 

Notice: Undefined index: Page in c:\program files\Apache\htdocs\loggin1.php on line 35

 

Notice: Undefined index: UserCode in c:\program files\Apache\htdocs\loggin1.php on line 39

 

Notice: Undefined index: time in c:\program files\Apache\htdocs\loggin1.php on line 43

SELECT * FROM log where id > 85076

 

I am about to throw this damn computer across the room lol even tho its not the computers fault at all lmao

Link to comment
Share on other sites

Tried helping, it looks like you are not even reading what was written before hand. I suggest you re-read the entire posts in this thread and take out the information that was supplied by the users.

 

I know I posted a clean version of this code and I see non of that code being implemented or used in this version, it looks like you just reverted back to your original bad code.

Link to comment
Share on other sites

actually i attempted to use the code you provided and it also came out with errors and after consulting with my boss i reverted to the old code to attempt to figure out what the problem was.. i am very appreciative of all your guys assistance, TRUST ME!!

Link to comment
Share on other sites

<<PREMISO>>

when implementing you clean code i received the following error

 

Notice: Undefined index: Page in c:\program files\Apache\htdocs\loggin2.php on line 31

 

 

<><><><><>

PLEASE everyone keep in mind that i started learning coding 2wks ago and its the first time i have touched anything like this, be tolerant of my lack of knowledge  :)

Link to comment
Share on other sites

Either way if you revert back to the old code...FIX IT like suggested. If you get an error, look up on what the error is.

 

An undefined index means that you are trying to use a variable that has not been defined. You can check if a variable has been defined with isset

 

Also as suggested earlier, read up on variables/proper usage in echo and print as your code will never work because you are including variables completely wrong. Look at the code posted and see how the usage is done there.

 

Doing your own research is half the battle with coding. You find a problem research it. Why does that cause a problem, what is the issue. I cannot tell you how many hours I have spent at php.net and google researching all my problems I come across and it never seems to fail me as I almost always get the answer I need or something close to it.

 

As stated the version of the code I posted is a lot closer to what you want to achieve, but if you want to do it yourself and find out why do the leg work and research it.

Link to comment
Share on other sites


I have figured it out guys this should look right huh?

 

<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>

</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")

{

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;

$result = sqlite_query($handle, $query);

$row = sqlite_fetch_array( $result );

echo "<table style='border-style: solid; border-width:1px;border-color:red;'>";

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.