Re: [PHP-DB] mysql_query

2011-06-06 Thread Niel Archer
> Hello all,
> 
> Not sure what I am doing wrong.
> 
> I have a simple form that populate the variables in a mysql query. I
> know the selected values are making it to the form porcessing script
> because I can echo them on the processing script as indicated below.
> 
> You Selected Cell_Sect = 1_1
> You Selected Date = 03/10/11 18:15
> You Selected Market = MCI
> 
> For some reason the above is all I am getting when I submit my form.
> 
> I beleive it has somthing to do with my results query below.
> 
> $result = mysql_query("select * FROM evdo WHERE Market like '%$term'
> and Cell_Sect = '$cat' and Date = '$subcat' LIMIT 10");
> 
> Beow is my whole script for processing the form in case it maybe something 
> else.
> 
> Thanks,
> 
> Chris
> 
> 
> 
> 
> 
>  
> // database access parameters
> $dbservertype='mysql';
> $servername= left out for privacy;
> // username and password to log onto db server
> $dbusername='';
> $dbpassword='';
> // name of database
> $dbname='pcmd';
> 
> connecttodb($servername,$dbname,$dbusername,$dbpassword);
> function connecttodb($servername,$dbname,$dbuser,$dbpassword)
> {
> global $link;
> $link=mysql_connect ("$servername","$dbuser","$dbpassword");
> if(!$link){
> die('Could not conect: ' . mysql_error());
> }
> echo 'YOU ARE CONNECTED TO PCMD DATABASE';
> 
> mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}  <- What's this doing here
>  End of connecting to database 
> ?>
>  'http://www.w3.org/TR/xhtml1-transitional.dtd'>
> 
> Demo Multiple drop down list box for PCMD data
> 
>   TABLE {
>  border: 1px solid #98bf21;
>  border-collapse:collapse;
>   }
> 
>   TH {
>  border: 1px solid #98bf21;
>  padding-bottom: 4px;
>  padding-left: 7px:
>  padding-right: 7px;
>  padding-top: 5px;
>  font-size: 1.2em;
>  background-color:limegreen;
>  color: white;
>  text-align: left;
>   }
> 
>   TD {
>  border: 1px solid #98bf21;
>  padding-bottom: 2px;
>  padding-left: 7px:
>  padding-right: 7px;
>  padding-top: 3px;
>  font-size: 1.0em;
>   }
> 
>   TR.alt TD {
>   background-color: #eaf2d3;
> 
>   }
> 
> 
> 
> 
> 
> 
> 
>  $cat=$_POST['cat'];
> $subcat=$_POST['subcat'];
> $term=$_POST['term'];
> 
> $result = mysql_query("select * FROM evdo WHERE Market like '%$term'
> and Cell_Sect = '$cat' and Date = '$subcat' LIMIT 10");
> 
> 
> $firstRow=1;
> $rowNum = 0;
> echo "";
> while($row = mysql_fetch_assoc($result)) {
>if($firstRow == 1) {
>   echo "";
> 
>   foreach($row as $key => $value) {
>   echo "" . $key . "";
>   }
>   echo "";
>   $firstRow=0;
>   $rowNum++;
>}
>else {
>   if(  ($rowNum++ % 2) == 1) {
>  echo "";
>   } else {
>  echo "";
>   }
>}
>foreach($row as $key => $value ) {
>echo "" . $value . ""  ;
>}
>echo "";
> }
> echo "";
> 
> echo "You Selected Cell_Sect = $cat You Selected Date =
> $subcatYou Selected Market = $term";
> 
> 
> ?>
> 
> 
> 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

After your mysql_select_db() there is a closing brace without matching
open. This will be causing an error in that php block.

--
Niel Archer
niel.archer (at) blueyonder.co.uk


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] mysql_query returning empty result after DELETE

2009-09-14 Thread Chris

Stan wrote:

OK.

If I change the test to "if(mysql_num_rows($thisRow) < 1)" it does what I
want.

I guess if I want to understand why False was returned originally (just
after I created the database) I need to start over.


According to the docs mysql_query only returns false if there's an error.


Do I have 4 possible conditions here: 1) the mysql_query() function fails
and I get a PHP error, 2) the query fails at the server and I get False, or
3) the query doesn't fail at the server and I get "a result" that a) is
empty, or b) contains 1 or more rows?  Yes.


1) I'm not sure what you mean. If you try to run a query before having a 
connection (or not checking the connection is valid before running a 
query), then mysql_query will return false and php will throw warnings 
or notices (can't remember which).


2) Correct

3) Also correct.

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] mysql_query returning empty result after DELETE

2009-09-14 Thread Stan
OK.

If I change the test to "if(mysql_num_rows($thisRow) < 1)" it does what I
want.

I guess if I want to understand why False was returned originally (just
after I created the database) I need to start over.

Do I have 4 possible conditions here: 1) the mysql_query() function fails
and I get a PHP error, 2) the query fails at the server and I get False, or
3) the query doesn't fail at the server and I get "a result" that a) is
empty, or b) contains 1 or more rows?  Yes.

Problem solved (my code was naive), understanding increased (my code won't
be naive in the future as regards mysql functions in PHP).

Thank you very much..

"Chris"  wrote in message
news:4aad74e5.3090...@gmail.com...
> Stan wrote:
> > I did a "DELETE FROM picture" where "picture" is a table in my database.
>
> Because this deletes all your records - so doing a select afterwards
> will find nothing.
>
> > Afterward, this piece of code does not generate an error
> > --
> > try
> >   {
> >   $query = "SELECT * FROM picture p " .
> >   "WHERE p.pictureFile='" . $pictureFile . "'";
> >   $thisRow =
> >   mysql_query($query, $pictures_connection);
> >   }
> >   catch(Exception $e)
> >  {
> >  echo 'caught exception: ',  $e->getMessage()."\n";
> >  $result = False;
> >  }
>
> an empty result set is fine - it means no records found. It will not
> generate an exception.
>
> I'm not sure when mysql will generate an exception either, mysql_query
> returns FALSE if the query fails (see http://www.php.net/mysql_query).
> You then have to use mysql_error to get the reason why it failed.
>
> -- 
> Postgresql & php tutorials
> http://www.designmagick.com/
>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] mysql_query returning empty result after DELETE

2009-09-14 Thread Stan
Yes. I deleted all records.

Prior to the DELETE, if I did a SELECT with specific criteria (WHERE
p.pictureFile = "some valid content"), and those criteria were not met,
mysql_query() returned False ... and, conversely, if those criteria were
met, mysql_query() returned "a resource" against which I could use
mysql_fetch() to retrieve the rows returned by the SELECT.

After the DELETE, and as I explained in my original post, the same SELECT
with specific criteria returns, not False as it should, but "a resource"
which contains an empty row.

If I look at the database using MySQL Query Browser, it appears empty.

I do not understand what is happening.

Help understanding what is happening is what I seek. Can you help?

Thanks.


"Chris"  wrote in message
news:4aad74e5.3090...@gmail.com...
> Stan wrote:
> > I did a "DELETE FROM picture" where "picture" is a table in my database.
>
> Because this deletes all your records - so doing a select afterwards
> will find nothing.
>
> > Afterward, this piece of code does not generate an error
> > --
> > try
> >   {
> >   $query = "SELECT * FROM picture p " .
> >   "WHERE p.pictureFile='" . $pictureFile . "'";
> >   $thisRow =
> >   mysql_query($query, $pictures_connection);
> >   }
> >   catch(Exception $e)
> >  {
> >  echo 'caught exception: ',  $e->getMessage()."\n";
> >  $result = False;
> >  }
>
> an empty result set is fine - it means no records found. It will not
> generate an exception.
>
> I'm not sure when mysql will generate an exception either, mysql_query
> returns FALSE if the query fails (see http://www.php.net/mysql_query).
> You then have to use mysql_error to get the reason why it failed.
>
> -- 
> Postgresql & php tutorials
> http://www.designmagick.com/
>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] mysql_query returning empty result after DELETE

2009-09-13 Thread Chris

Stan wrote:

I did a "DELETE FROM picture" where "picture" is a table in my database.


Because this deletes all your records - so doing a select afterwards 
will find nothing.



Afterward, this piece of code does not generate an error
--
try
  {
  $query = "SELECT * FROM picture p " .
  "WHERE p.pictureFile='" . $pictureFile . "'";
  $thisRow =
  mysql_query($query, $pictures_connection);
  }
  catch(Exception $e)
 {
 echo 'caught exception: ',  $e->getMessage()."\n";
 $result = False;
 }


an empty result set is fine - it means no records found. It will not 
generate an exception.


I'm not sure when mysql will generate an exception either, mysql_query 
returns FALSE if the query fails (see http://www.php.net/mysql_query). 
You then have to use mysql_error to get the reason why it failed.


--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] mysql_query

2009-08-10 Thread Phpster





On Aug 10, 2009, at 4:15 AM, "Ron Piggott"  
 wrote:



I have the syntax

mysql_query("INSERT INTO );");

If this is successful I want to do update a column in one of my tables

$query = "UPDATE ... ";
mysql_query($query);

How do I test if the INSERT INTO mysql_query, in order to trigger  
the UPDATE?


Ron


You could use the REPLACE syntax in mysql

http://dev.mysql.com/doc/refman/5.0/en/replace.html

Bastien

Sent from my iPod

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] mysql_query

2004-10-12 Thread Philip Thompson
On Oct 12, 2004, at 7:15 AM, [EMAIL PROTECTED] wrote:
hello,
I have a begining question.
I've got simple html form and php script, but insert doesn' t work. 
What is
wrong in my insert mysql_query?

mysql_query( "insert into obiskovalci (ime, priimek, ulica, hstevilka,
pstevilka, posta) values('$ime', '$priimek', '$ulica', '$hstevilka',
'$pstevilka', '$posta')");
There's a little more you need. First you have to use the connection 
you should have already opened up:

$link = mysql_connect('some_db', 'some_user', 'some_pw');
Then you have to include the `link` whenever you do a query:
mysql_query("your query", $link);
If I recall, you may not actually have to include the link every single 
time if you have already established which one you're using... but it's 
always safe to specify which one you're using. Maybe someone can 
clarify on this.

There is also id, which is auto_increment. After fill form and press 
Submit, id
is writen in table, but there is no other inputs. Nothing, except "id".
Yes, consider using the $_POST["some_variable"] to obtain the values.
thanks for answers
BR, Balo
Hope this helped a tiny bit.
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP-DB] mysql_query

2004-10-12 Thread Murray @ PlanetThoughtful
Hi,

Unless you have 'register globals' on, are you retrieving the value of the
variables passed by your form from the $_GET or $_POST super variables
(whichever is appropriate)?

In other words, at the top of the page that is performing your insert query,
do you have lines such as:

$ime = $_GET['ime']; // (or, if your form is POSTing the data, $ime =
$_POST['ime'];)

>From what limited information you've included below it seems that perhaps
you aren't retrieving these values prior to attempting to insert them into
the table.

Please ignore this if your installation of PHP is running with 'register
globals' on.

Much warmth,

Murray

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Tuesday, 12 October 2004 10:15 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] mysql_query

hello,

I have a begining question.
I've got simple html form and php script, but insert doesn' t work. What is 
wrong in my insert mysql_query?

mysql_query( "insert into obiskovalci (ime, priimek, ulica, hstevilka, 
pstevilka, posta) values('$ime', '$priimek', '$ulica', '$hstevilka', 
'$pstevilka', '$posta')");

There is also id, which is auto_increment. After fill form and press Submit,
id 
is writen in table, but there is no other inputs. Nothing, except "id".

thanks for answers
BR, Balo

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] mysql_query

2004-10-12 Thread bbonkosk
1. place your query string into a variable for easy dumping...
i.e. $query = "insert into obiskovalci (ime, priimek, ulica, hstevilka, 
  pstevilka, posta) values('$ime', '$priimek', '$ulica', 
  '$hstevilka', '$pstevilka', '$posta')";
echo $query;
(See if there are problems that come to light when you dump it out)

2. Print out the debug...
i.e. mysql_query($query) or die(mysql_error());

(If this doesn't help you at the very least it should help the list more in answering 
your question.)

-B



- Original Message -
From: [EMAIL PROTECTED]
Date: Tuesday, October 12, 2004 8:15 am
Subject: [PHP-DB] mysql_query

> hello,
> 
> I have a begining question.
> I've got simple html form and php script, but insert doesn' t 
> work. What is 
> wrong in my insert mysql_query?
> 
> mysql_query( "insert into obiskovalci (ime, priimek, ulica, 
> hstevilka, 
> pstevilka, posta) values('$ime', '$priimek', '$ulica', 
> '$hstevilka', 
> '$pstevilka', '$posta')");
> 
> There is also id, which is auto_increment. After fill form and 
> press Submit, id 
> is writen in table, but there is no other inputs. Nothing, except 
> "id".
> thanks for answers
> BR, Balo
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] mysql_query troubles

2001-07-17 Thread Karl Phillipson

Brad,

Have you defined the database variable you are connecting to?

ie: $DB="your_database_name"; and then connecting:

if(!($testResult = mysql_query($DB, "SELECT * FROM login_table where Pass =
password('$password')")))

try the code snippet below and see if it spits an error at you -  you will
need to define the $DB variable.


%s\n", $message);
}

//begin query 

if(!($testResult = mysql_query($DB, "SELECT * FROM login_table where Pass =
password('$password')")))
//if we get an error print it
{
DisplayErrMsg(sprintf("internal error %d:%s\n",
mysql_errno(), mysql_error()));
exit();
}

$num_rows = mysql_num_rows($testResult);
print "$num_rows";
exit();
mysql_free_result($testResult);

?>







-Original Message-
From: Brad Wright [mailto:[EMAIL PROTECTED]]
Sent: 17 July 2001 06:31
To: [EMAIL PROTECTED]
Subject: [PHP-DB] mysql_query troubles


Hi all',
I have a mysql_query that reads:

 $testResult = mysql_query("SELECT * FROM login_table where Pass =
password('$password')") or die ("ouch");

$num_rows = mysql_num_rows($testResult);


the problem is that I keep getting a value of 0 for $num_rows when I know
the table has 1 entry for PAss which equals password('$password'). The
password I have used is just 'a' (before pasing throught the password
function in the insert).


I DO have a table named login_table
I KNOW that there is an entry that matches 'password('$password)'.. ( i
checked using phpMyAdmin)


can anyone help??


Thanks in advance,
brad


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



RE: [PHP-DB] mysql_query returns nothing?

2001-07-05 Thread Mark Roedel

> -Original Message-
> From: Stefan Siefert [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, July 04, 2001 9:07 AM
> To: PHP Mailingliste
> Subject: [PHP-DB] mysql_query returns nothing?
> 
> 
> Hm, since we are using PHP 4.0.6 we do get sometimes no
> returnvalue...(function mysql_query) I think, this is always 
> then, when we are executing update oder delete syntax hm,
> does anyone know anything about it?

Does mysql_error() tell you anything interesting in those cases?  (A
zero/false result from a mysql_query usually means either a syntax error
in the query or a problem with your database access or connection.)


---
Mark Roedel ([EMAIL PROTECTED])  ||  "There cannot be a crisis next week.
Systems Programmer / WebMaster  ||   My schedule is already full."
 LeTourneau University  ||-- Henry Kissinger


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] mysql_query failure

2001-02-16 Thread Russ Michell

>$con = mysql_connect($DB_SERVER, $DB_USER, $DB_PASS)
>or die ("Cant connect");
>mysql_select_db($DB_NAME);

Try:

$con = mysql_connect($DB_SERVER, $DB_USER, $DB_PASS)
or die ("Cant connect");
mysql_select_db($DB_NAME, $con);

Also try and make your php functions like so: mysql_x() instead of: 
mysql_x () (loose the gap!)

Hope that helps somewhat! ;)

Russ

#---#

 "Believe nothing - consider everything"

  Russ Michell
  Anglia Polytechnic University Webteam
  http://gertrude.sipu.anglia.ac.uk/webteam
  [EMAIL PROTECTED]
  +44 (0)1223 363271 ext 2331
  
  www.theruss.com

#---#


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]