Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Error In Select Statement


I have the following SELECT statement which aims to select data from the database for a month ago today however im getting an error message as shown below. SELECT STATEMENT

$dbQuery="SELECT * FROM data WHERE ReportedDate BETWEEN date("Y-m-d", strtotime("-12months")) AND date("Y-m-d", strtotime("-11 months"))";

ERROR MESSAGE: Parse error: parse error, unexpected T_STRING




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Multiple Select From Listbox And Execute A Sql Query Select Statement
Supposing i have a html form with 2 listbox and i name it status and resolution.

So it goes <select name='status[]'>... <select name='resolution[]'>

Then i have a another php page.
$status = $_POST['status'];
$resolution = $_POST['resolution'];

Now my question is, how do i do the sql query statement?

mysql_query("SELECT * from bugs where status=$status and resolution=$resolution");

The problem is, i select 3 options form the status listbox eg. new, closed, duplicate. And from the resolution, i chose fixed, invalid.

Select Statement - Select Random ID #
I have made up a page that pull info on 13 branches of stores onto one main page. It's basically there to display all the branches on one page... then you click on the one you're interested in and then you go to a more detailed page.

Back to the main page. On the top, there's kind of a featured branch that has a bigger picture and bigger title but it's still getting pul pulled from the same table etc etc etc.

In order for me to avoid favortism to one branch (and for other branches to start complaining) I want to ramdomized the order every time someone came to page but I have no idea how.

right now I have a super simple select statement.

SELECT Error: No Database Selectedin Query: SELECT * FROM Schedule
I got the above error message after reading FAQ #10 which applied to my first error. The thing is, I thought I had selected a database. This script is copied from a tutorial, and I'm just too new at this to spot my error. PHP Code:

Variable In Select Statement
Hi,

I want to do the following:

Select ID
From tablename
where name='$name'

How do I do this in PHP?

Select Statement Problem
I am having a problem with simple select statement When I run this statement in my PHP program.. no result..

$sql= "select * from zipcodes where zip between $pluszip and $minuszip";

But when I run the below statement I get the results..

$sql= "select * from zipcodes where zip between 12345 and 12456";

I tried this one also, but no result

$sql= "select * from zipcodes where zip between '$pluszip' and '$minuszip'";

I tried echoing pluszip and minuszip and i am getting the values printed. I am having trouble with passing it on to the select statement.

Versatile SELECT Statement
My SELECT statement below works if I have made an actual selection for the area_ID, but when I generate the page initialy no selection has been made yet which results in zero hits for the current version_ID. Do I need to make an additional SELECT statement and remove PHP Code:

Password() And Select Statement
problem in retrieving a row form a table that I created in
mysql db.
I insert these values in the table
'Bell',password(ì«').
But the problem is in my php application I cant retrieve this row
because the password that I pass dosn't match the password value in the
table.
this is the code that I wrote in my php application

$user = $_POST[username];
$pass = $_POST[password];
$q = mysql_query("SELECT * FROM admin WHERE username = '$user' and
password =PASSWORD('$pass')");

if(mysql_num_rows($q)==0){
echo "Acces denied. User not allowed to connect.";
mysql_close();
}
else
{
echo
"<script>window.location.replace('administrator2.php')</script>";
}

Select Distinct Statement
I have a question about the following PHP script - I got it off a web
site tutorial on how to count users logged into your site - my
question is the $PHP_SELF variable - it writes the name of the web
page to the 'file' field in the table - I don't understand why it is
doing that - I mean, isn't the SELECT DISTINCT statement only pulling
those records from that one web page? I guess I just don't follow what
it is doing with that SELECT DISTINCT statement?

$timeoutseconds = 300;
$timestamp = time();
$timeout = $timestamp-$timeoutseconds;

$php_SQL = "INSERT INTO online SET timestamp='$timestamp',
ip='$REMOTE_ADDR', file='$PHP_SELF'";
$php_resultID = mysql_query($php_SQL, $php_linkID);

$php_SQL = "DELETE FROM online WHERE timestamp < $timeout";
$php_resultID = mysql_query($php_SQL, $php_linkID);

$php_SQL = "SELECT DISTINCT ip FROM online WHERE file = '$PHP_SELF'";
$php_resultID = mysql_query($php_SQL, $php_linkID);
$php_users_online = mysql_num_rows($php_resultID);

if ($php_users_online == 1)
{
print "<BR>$php_users_online user is currently online";
}
else
{
print "<BR>$php_users_online users are currently online";
}

Select Statement Not Valid?
I'm doing a search via the passing of values throught the url. I'm having a problem with the select statement. If i enter the values and the match (side1='$valueSide1' AND side2='$valueSide2') portion of the statement the correct values are returned.

But if I reverse the values and the do match (side1='$valueSide2' AND side2='valueSide1') then no match is returned. I've verified through command line that the statement works.
Does it look like my statement if formatted correctly? Code:

Variable Select Statement
I would like to have a form that gives the user choices for selection
parameters for email, printing etc.

A real simple example:

Give me all ______ who ______ when _______ where _______

I can figure this out if all of the selections are filled, but NOT if
they just decide to use only one of the selection choices.

I'm sure this is idiotic, but I'm really new to php and my ideas are
writing checks my programming skills can't cash.

Simple SELECT Statement
I have a dbase with some gigs that has a date field. The SELECT statement currently says...

QuoteSELECT * FROM `Gigs` ORDER BY `Eventdate` ASC LIMIT 3

which works fine but I also want the statement to only show gigs that havent happened yet or that are > than today's day. I tried WHERE Evevntdate > CURRENT_DATE or something along those lines but so far havent got it to work.

Strpos In A Select Statement
I am trying to query a Access database using the following code but I get an SQL error Syntax error (missing operator) in query expression. Is it possible to use strpos in a SQL statement?

pro_id is a field in the database whose value is 489

$valves = 489;

$SQLQuery = "SELECT * FROM Products WHERE strpos(".$valves.",pro_id,1) !== 0";

Maximum Lenght Of Select Statement
Can anyone tell me what the maximium length of a SELECT statement can be. I am coming from Foxpro where 8100 char was the limit. Part of my program is a query builder and I need to build a query from a series of drop down lists users select values from.

Question Regarding A MySQL SELECT Statement
I tried hunting for a MySQL specific NG and didn't find one but I did
see that MySQL questions get asked here. If this isn't appropriate and
you know of an appropriate NG then that would be great.

In one table I have inventory...
table name is "inventory"
columns are..
-----------------------------
item_number item_name
-----------------------------
1 radishes
2 carrots
3 potatoes
4 oranges
etc..etc

Table two is "sold"
------------------------------
date item_number
13Mar 1
14Mar 4
15Mar 2
16Mar 1


What I am querying is the table "sold" for the Unique items (1,4,2)
and then retrieving their names from table 1.

My query below isn't working..
SELECT item_name FROM inventory WHERE inventory.item_number =
sold.item_number;

I am just now starting to get into complicated MySQL queries and
actually the more I learn about it the more I love it.

PHP, ODBC, SQL Server Select Statement
I am having a problem getting results back from a SELECT statement
using the script below. The field names contain decimals and I am not
sure wether or not this is causing the problem or not?? I am
connecting to a SQL server db using ODBC, first time connecting to SQL
server but have been using ODBC to connect to Access db's for years. I
have entered the field names just as they are in the table and I have
tried replacing the spaces and decimals with underscores but still
recieve the same error. Anyway, my simple script and the error that I
am recieveing is below. Any help would be greatly appreciated..

$connect = odbc_connect('cabngsql', '', '');
if (!$connect)
{
echo "couldn't connect";
exit;
}
$query1 = "SELECT fol no FROM Protocol.folder";
$result1 = odbc_exec($connect, $query1);
while (odbc_fetch_row($result1)){
$folder = odbc_result($result1, 1);
echo "$folder";
}
?>

ERROR: SQL error: [Microsoft][ODBC SQL Server Driver][SQL
Server]Invalid object name 'Protocol.folder'., SQL state S0002 in
SQLExecDirect

SELECT Statement Syntax For Variables
the statement below isn't returning the expected results. I've echoed it at runtime and the variables are missing. I presume it's just the syntax?

$query = "SELECT field FROM database.table WHERE email='$e' AND password='$p'";

How Do I Return 10 Results Per Page Using SELECT Statement?
I'm wasn't sure whether to post this under the PHP or under the MySQL section of the forums. Since most people (I'm assuming) who write PHP script, also use MySQL, I thought I'd stick with PHP. I'm rather new to both PHP and MySQL and I'd be very grateful to anyone who can help me solve a problem I'm having at the moment. First, I'll give you an introduction to my little project...

I'm developing a database in MySQL that is used to store the song titles of all the MP3s I have on my PC. I've written a basic search feature that works well. The user has 2 options: Either he can type a special "!ALL" "parameter", that I made up, to return all the songs in the database or the user may enter a few characters in the textbox and select "song title" or "artist" etc. from a dropdown to search for a specific song title or artist etc.. Hope you are following so far? Say for example the user presses submit after typing "!ALL" to return all the song titles - there could be hundreds of results. What I want to do now is display 10 results on a page, then on the next page another 10, etc. (like a real search engine!). I've tried doing it with the LIMIT statement, but like I said I'm new to this and discovered that that is not the right way of going about it. My question is this: how would I go about returning 10 matches per page? Do I use hidden form fields? What would the SELECT statement look like? What would the PHP scripting look like to setup the "back" and "forward" navigation between the result for the search?

Getting Form Info Into A Mysql Select Statement
I'd like to get user input from an html form into a mysql select
statement. Here's where I'm stumped:

$result = mysql_query("SELECT * FROM dept WHERE notes LIKE
'%search-string%'",$db);

I need to get the user's input into the '%search-string%' section, but I
do not understand how to do this. I can hard-code a specific search
string and it will work, but I want the users to be able to dynamically
define the search-string. So, I created a basic html form and used the
post method to grab their input, but now I can't insert that input into
the mysql select statement. Any ideas? I think it should be easy, I just
don't know how to do it. I've tried this:

$result = mysql_query("SELECT * FROM dept WHERE notes LIKE
'%$_POST["search"]%'",$db);

But it doesn't work. Below is the form in html and the php file:

<html>
<title>Search Test</title>
<head>
</head>
<body>
<form action="search-db.php" method="POST">
<p>Enter Your Search: <input type=text name=search></p>
<input type="submit">
</form>
</body>
</html>
-----------------------------------------------------------
<html>
<body>
<?php
$db = mysql_connect("localhost", "Anonymous");
mysql_select_db("computers",$db);
$result = mysql_query("SELECT * FROM dept WHERE notes LIKE
'%surplus%'",$db);
echo "<table border=1>
";
while ($myrow = mysql_fetch_array($result)) {
printf("<tr><td><b>%s</b></td></tr>
", $myrow[notes]);
}
echo "</table>
";
?>
</body>
</html>

Mix Two Tables In A Single SELECT Statement - Not A Join
I have an Intranet with the organisation I work with. In this
organisation there are two departments - community department and press
office. Both the community department and press office have thier own
news system where they can add news in their own admin section that
will appear on their homepages. Both admin section have their own DB
table thus two seperate tables.

I would like to select all the rows from both tables in a single SELECT
statement so when I output them they will be integrated. This is not
the same as a table join as their are no keys and I want the rows from
both to remain seperate. Can this be done? Could someone please post an
example SQL statement demonstrating this if so?

Run A Select Statement Based On Array Values?
I have an array that has x number of values. I want to run a sql statement x number of times using the next array value each time. Basically I have a query that displays results based on a search. The result of the search is a list of names, the trouble is for reasons beyond my control the names are in a single db field as "FirstLast".

I want to take this value and match it up to another table that has the first and last names in separate fields. So far I have extracted the results from the first query using a while loop, the resulting array is called $name_search: Code:

SELECT Statement Results Into Text File
I am trying to create a text file based off the results of a query statement from a database. See code below:

$itemq = "SELECT sdlitm, sddsc1, sduorg, sdlnid, sduncs FROM F4211 WHERE sddoco = $ordernum AND sddcto LIKE '$ordertype' ORDER BY sdlnid";
$result3 = odbc_exec($connect, $itemq);
    while (odbc_fetch_row($result3)){
    $partnum = odbc_result($result3, 1);
    $desc1 = odbc_result($result3, 2);
    $qty = odbc_result($result3, 3)/100;
    $position = odbc_result($result3, 4);
    $uncs = odbc_result($result3, 5);
    $extcost = $uncs*$qty;
    $total = ($total + ($uncs * $qty));
    $filename = "$reportnumber.txt";
    $fp = fopen($filename, "w");
    fwrite($fp, "Activity Number: $reportnumber
");
    fwrite($fp, "Warranty Type: $reason
");
    fwrite($fp, "Customer Name: $custname
");
    fwrite($fp, "$qty $partnum $desc1
");
    fclose($fp);

Everything works fine until I get to the line:

fwrite($fp, "$qty $partnum $desc1
");

This line should actually print multiple lines into the text file as these are the line items from an order. There could be anywhere from 1 to 20 lines written to the text file. As it stands, the only line items written to the text file are those of the last line found on the order. The entrie script dealing with the text file are still within the confines of the while statement curly braces. How do I write these lines out in the text file??

MySQL UNION: Only The First Select Statement Returns A Result.
I am attempting to join multiple select statements into a single query.
However, I am not able to extract the result of any of the UNIONED selects.











$query1 = mysql_query ("
(
SELECT SUM(deposits) AS total_deposits
FROM table1
)

UNION ALL
(
SELECT SUM(withdrawals) AS total_withdrawals
        FROM table1
)
")
or die (mysql_error());

$result1 = mysql_fetch_array($query1);
extract($result1);




When I echo the results of the second select statement I get nothing.


echo  $total_withdrawals;

Select Statement With Changing Tables Base On User Selection
I am trying to make a select statement that would allow me to change the table, base on the user selection from a drop down menu list. I don't know if its possible or my syntax is wrong PHP:

sql = SELECT * FROM "'.$_POST[Tableselection].'" WHERE  "'.$_POST[userid].'" ='1';

Error With Insert Statement
the following code is producing this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '', ipaddress='1.1.1.1'' at line 1 Code:

Elseif Statement Error
I am trying out thid else if statement in my php script and i have entered all of the details manually and in the correct format into the database to test. However each time the script loads, the image says error which is the last else (images/_status_error.jpg).

It is really driving me round the best. The other thing is that i have it working superb on my local host and displays the correct message but now it is on someone elses shared host provider it is not working Code:

How Do I Put SELECT Statement Into "for" Array?
Does anyone know how I can put the SELECT statement below into a for array?

Phpgem Error In Select Count ?
I use phpgem to generate forms. it works fine, just one problem with count, I get error messages like this (from the php-script - NOT when i query mysql directly!):
SQL query: SELECT COUNT(*) FROM hupoterm WHERE (LOWER(gruppe) LIKE '%e%')
Warning: count not found in MySQL result index 2 in sql.php3 on line 255

Could this mean a problem with my table syntax? since 6 days i changed almost all config-parameters in the script, in the table ..... but the error message is still there .

Warning: Stream_select(): Unable To Select [0]: No Error In ...
<?php
while (true) {
$read = array(STDIN);
$write = $except = NULL;
if (stream_select($read, $write, $except, 0)) {
}
}
?>

When I run this in PHP4, I get a "warning: stream select(): unable to
select [0]: No error" error. In PHP5, I don't.

Error In Generating Table From Database Select Statment
I am trying to dynamically create a table with the results from a select statement. Below is the code that is not working. Any help would be oh so greatly appreciated. This is for a final at school which is due in an hour. This is the only thing I can't seem to make work. Code:

Error In Query: SELECT Uid, Uperms From Users WHERE Uname =
I am trying to set up the article from the main page in devshed called money is time
the thing is this, it denies access for this user and pass even though they are in the database 'example' and on table (users)

Error in query: SELECT uid, uperms from users WHERE uname = 'john' AND upass = PASSWORD('john'). Access denied for user: '@localhost' to database 'example' Code:

If Statement Construction Within An Echo Statement
I have a form that is being used to "update" user info and I need the information to be pulled from the users table.  In order to get the variables into the form, I am echoing it in and using an mysql array to place them into the form.

at the t-shirt size part of the form the code is as follows ....

Email Script/Javascript Parse Error: Syntax Error, Unexpected T_STRING
I've made a email script to include javascript. Now what I want to do, is that I want to hide the link in status bar when I hover over it. I've implemented javascript into the code but I keep getting the following error:

Parse error: syntax error, unexpected T_STRING in /home/****/public_html/fbmail/contact.php on line 12

Here is line 12:
$message .= '<a href="http://www.mysite.com/" onMouseOver="window.status='Click here to continue.'; return true;" onMouseOut="window.status=''; ">Click here to continue ..</a>'; The complete code:

Error Reading WWW Server Response (HTTP Header). Error Code: 0
I have been trying out the web based email program on this website to connect to a pop 3 client...it worked ok...but now when i try to logg in all i get is this error message...on the page Error occurred!

Description: Error reading WWW server response (HTTP Header). Error code: 0(0 = client terminated the connection unexpectedly, 2 = too many header lines) Code:

Parse Error: Syntax Error, Unexpected T_ENCAPSED_AND_WHITESPACE, Expecting T_STR
I am having troubles entering this info into my db. Cna someone help? This is the error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/realfina/public_html/ec/testdobaapi.php on line 22 Code:

Parse Error: Syntax Error, Unexpected '?' In /home/**/public_html/website_
Parse error: syntax error, unexpected '?' in /home/realfina/public_html/website_builder/phpcb/filgen.php on line 373

Can someone explain what this means?

Else Statement
Can anyone tell me how to correct this script. I can't get the else statements to work properly.

Here is the script:

IF Else Statement
I'm trying to write a basic IF statement, but I've never really made one from scratch and I'm getting quite stuck.

IF Statement Help
I want to show a series of radio buttons but only if a price field in my database is greater than 0. I've been trying a few things like this PHP Code:

If Else Statement ?
Im currently writing some cart software and have run into a problem which i cant seem to get my head around ... i have been trying to solve this for around 3 weeks now with no luck, and thought someone here might be able to shed some light on this problem for me.

Firstly it needs to check all products in the cart and take the one with the highest primary shipping cost, then subtract that one qty off the total amount.
Then for all additional products or qty's it'll take the additional shipping cost of that product.
If there are no additional products / qty's then it will use the primary shipping price from that product. I think thats how it goes, Here's a couple of real examples of how it should work:

I have 3 products in my database:

Product 1: DVD Player
Product 1 Primary Shipping Cost: $20 (products_ship_price)
Product 1 Additional Shipping Cost: $2 (products_ship_price_two)

Product 2: Digital Camera
Product 2 Primary Shipping Cost: $40 (products_ship_price)
Product 2 Additional Shipping Cost: $1 (products_ship_price_two)

Product 3: Cordless Phone
Product 3 Primary Shipping Cost: $55 (products_ship_price)
Product 3 Additional Shipping Cost: $3.50 (products_ship_price_two)

If I buy 1 DVD player and 3 Digital Camera's, then the shipping price will be: $44 - $40 (highest primary shipping cost of the 2 products) + $1 + $1 (the other 2 qty's of the digital cameras) + $2 (for the 1 DVD player).

If I buy 3 Cordless Phones, 2 DVD players and a Digital Camera, then the shipping price will be: $67 - $55 (highest primary shipping cost of all the products in the cart) + $3.50 + $3.50 (the other 2 qty's of the cordless phones) + $2 + $2 (the 2 qty's of the DVD players) + $1 (the Digital Camera).

If I buy 2 Cordless Phones and 1 Digital camera, then the shipping price will be: $59.50 - $55 (highest primary shipping cost of all the products in the cart) + $3.50 (the remaining cordless phone in the cart) +1 (for the digital camera).

While In Another While Statement
I want to improve the display of my $result3. I'm sure I need to use another
"while" statement inside this one but I don't want to create a infinite loop.

The $result3 look's like that:
-------------------------------------------------------
¦norisk¦descris ¦nomesur ¦descmes ¦
-------------------------------------------------------
¦A ¦high ¦1 ¦use harness ¦
-------------------------------------------------------
¦A ¦high ¦7 ¦be carefull ¦
-------------------------------------------------------
¦B ¦wet ¦3 ¦use boot ¦
-------------------------------------------------------
¦B ¦wet ¦7 ¦be carefull ¦
--------------------------------------------------------

I'dont want to had another query( thise one involve already 3 tables). Here's the code I wrote:

$result3 = mysql_query($sql2) or die("9err");
while ($array2 = mysql_fetch_array($result3))
{

print ("<tr><td>");
print ($array2['descris']) or die("err17");

print ("</td><td>");
print ($array2['descmes']) or die("err17");
print ("</td></tr>");
}

Of course, I don't want to see twice "high" and twice "wet" in the display but want to see all the measures for each risk.

If Statement
This is the code for the main page of our application. We are using sessions so that when users log in, they are authenticated against the user data in the database, a session is started and their team ($team) name is registered with the session, they are then redirected back to the main page (which appears here).

The goal is to have the main page reflect options based on the user's team. For example - members of the "admin" team should see all the options ("Modify Active Information", "Add/Delete/Modify Database Users", etc).

I developed this code on my test platform (PHP 4 on Win98 with Apache) and everything worked great. However, when I moved the code to our production server (Win2k server, PHP4, IIS 5) for final testing and tweaking, this problem cropped up! Everything else is working great.

Here's what happens now: I login as a member of the admin team and get authenticated and redirected to the main page. Only the default options are displayed - there is no option to "Add/Delete/Modify Database Users", and "View" is displayed for customer info.

When I debug this is what I get:
$valid = 1 (this tells me the user is logged in successfully)
$team = admin (correct team)
$action = View (this is the default - should be "Modify")
$audit = noshow (again, the default - should be "show")
$add_access_router = noshow (same as above)

Even stranger is that when I choose to log out, I am redirected to the main page again and the $team variable is still set to "admin" even though I have invoked "session_destroy()", "session_unregister("team")" and "unset($team)" in the logout script!! PHP Code:

If Statement
I have a script name post.php and in it I have the following code. PHP Code:

IF Else Statement
I have a form being submitted from another page and being directed to a second page. In this form is a checkbox called nonprofit. When checked the value is 1.

On the second page I have the following code:

If Statement
I am trying to remember how you write an if statement to check if any value
has been entered. For example seeing if a username has been entered in form.
I have seen the following:

if ($username == '')
{
print ("You've pressed submit without entering your username");
}

However is there another method which uses an exclamation mark? I am sure I
have seen something for where $username has no value but I can't think what
it was.

Where Statement
I want to make a statement that pretty much says this $selecttourdates = "SELECT * FROM bryan WHERE tourdate > todaysdate ORDER BY tourdate;";

but I am using timestamps.. here is what I used later down the script to convert the timestamp. $eventdate=date("l, F jS",mysql_result($result,$i,"tourdate"));

so how can i make it so it will only show tourdates that are today's date and onward.. not before today's date?

If/else Statement
If you look at the script below how can i get the form to display if the confirm_cat is equal to "nil"? At the moment it only displays when confirm_cat isn't equal to 'yes'.
Any ideas? PHP Code:

OR Statement
Can anybody please tell me how I can do a select using OR I know how to use AND - but battling to use OR.

If Statement Within An If Statement
I am a complete novice with php scrip but I am wiling to learn.
I am in need of some help, please.

Can anyone sort this code out for me so that it works correctly and
adjusts the price for the quantity selected on the front end.
__________________________________________________ _____________

if(article_get_field('type')== 'Croclight Candle'){
article_set_field('item_number', 'CRC');
article_set_field('price', 6.99);
}
elseif(article_get_field('type')== 'Spray') {
article_set_field('item_number', 'CRS');
article_set_field('size', &#3950;ml');
article_set_field('price', 6.99);
}
elseif(article_get_field('size')== &#3915;ml') {
article_set_field('item_number', 'CRS');
article_set_field('type', 'Spray');
article_set_field('price', 2.99);
}
elseif(article_get_field('type')== 'Roll-on') {
article_set_field('item_number', 'CRO');
article_set_field('size', &#3950;ml');
article_set_field('price', 6.99);
}
__________________________________________________ ______________

If Statement In Url
I want it to run an if statement to see if you are on that page or not and if you are then it will set that link's class to active. If not, doesn't do anything. Here is what I had to do in my previous site, and I can't get it to work on the new one, could someone assist me? Code:


Copyright © 2005-08 www.BigResource.com, All rights reserved