djdellux Posted November 18, 2008 Share Posted November 18, 2008 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) Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 18, 2008 Share Posted November 18, 2008 Look at all those comas you have in there. You're opening the string with " and your using " throughout the string. Re-think the logic of your string. Quote Link to comment Share on other sites More sharing options...
djdellux Posted November 18, 2008 Author Share Posted November 18, 2008 I am VERY new to codeing and this is part of my first ever code if you could be a lil more specific that would be great..thanks in advance... Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 18, 2008 Share Posted November 18, 2008 Use the simplest syntax that works. If you are only using php variables in a string, don't use concatenation - $query.=" and page ='{$_GET['Page']}' and userCode ='{$_GET['userCode']}' and time ='{$_GET['time']}'"; Quote Link to comment Share on other sites More sharing options...
djdellux Posted November 18, 2008 Author Share Posted November 18, 2008 actually I am using (page, userCode, and time) from sqlite will this make any kind of a difference?? thanks for your input. Quote Link to comment Share on other sites More sharing options...
djdellux Posted November 18, 2008 Author Share Posted November 18, 2008 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> Quote Link to comment Share on other sites More sharing options...
premiso Posted November 18, 2008 Share Posted November 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
djdellux Posted November 18, 2008 Author Share Posted November 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 18, 2008 Share Posted November 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
premiso Posted November 18, 2008 Share Posted November 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
djdellux Posted November 18, 2008 Author Share Posted November 18, 2008 BAHHHH, lol still no luck my friends this is stressfull lmao Quote Link to comment Share on other sites More sharing options...
revraz Posted November 18, 2008 Share Posted November 18, 2008 What does echo $query produce? You first have to understand what a valid SQL string looks like. Quote Link to comment Share on other sites More sharing options...
djdellux Posted November 18, 2008 Author Share Posted November 18, 2008 echo $query produces the result of the search being performed by the user. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 18, 2008 Share Posted November 18, 2008 Which is what? Copy and paste it.. Quote Link to comment Share on other sites More sharing options...
sasa Posted November 18, 2008 Share Posted November 18, 2008 fields in your forms are named 'Page', 'User Code' and 'Date'. You mast use same names in $_GET index Quote Link to comment Share on other sites More sharing options...
djdellux Posted November 18, 2008 Author Share Posted November 18, 2008 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 Quote Link to comment Share on other sites More sharing options...
premiso Posted November 18, 2008 Share Posted November 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
djdellux Posted November 18, 2008 Author Share Posted November 18, 2008 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!! Quote Link to comment Share on other sites More sharing options...
djdellux Posted November 18, 2008 Author Share Posted November 18, 2008 <<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 Quote Link to comment Share on other sites More sharing options...
revraz Posted November 18, 2008 Share Posted November 18, 2008 Maybe you should learn PHP before taking a job programming it... Quote Link to comment Share on other sites More sharing options...
premiso Posted November 18, 2008 Share Posted November 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
sasa Posted November 18, 2008 Share Posted November 18, 2008 change if ($_GET["Page"] !="") to if (isset($_GET["Page"])) and so on. test isset($_GET) before you proces form btw. you dont have field with name 'Time' or 'time' in your form Quote Link to comment Share on other sites More sharing options...
djdellux Posted November 19, 2008 Author Share Posted November 19, 2008 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> Quote Link to comment 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.