Reply to Re: query *seems* to work but no results [1]

Your name:

Reply:


Posted by desmond on 06/28/07 18:17

shimmyshack <matt.farey@gmail.com> wrote:

> On Jun 28, 2:53 pm, desmond <desm...@zeouane.org> wrote:
>> .. by 'works', I mean that thera are no errors. Unfortunately, there's no
>> output either. :-(
>>
>> Here is the HTML that I have in 'test.php' ...
>>
>> http://www.flickr.com/photo_zoom.gne?id=649529794&size=o
>>
>> Here is the php code in the file select.php ...
>>
>> http://www.flickr.com/photo_zoom.gne?id=649529810&size=o
>>
>> When i call up test.php' from my webbrowser, I enter say 'tom' and I get no
>> results. $dbname _is_ populated and there _is_ a user in there called
>> 'tom'.
>>
>> Can someone advise..? Thanks
>>
>> [1] I hope this is the right forum..
>
> your markup is incorrect you need
> name="first_name" rather than
> id=....
> same goes for them all
>
> also you have {['country']} rather than {$row['country']}
>
> also where are you getting $first_name from in the query?
> do you set it to
>
> $first_name = mysql_string_real_escape( $_GET['first_name'] );
>
> you know the form uses GET if you dont specify otherwise.
>
> your code is shall we say not quite all there yet, I would look at
> some examples online and then adjst them to suit your needs.

OK, typos corrected, the code looks like this (no more screenshots)..

--- test.php (this is the HTML one) ---
<form action="select.php" method="post">

<h6>

<label for="first_name">First Name: </label>
<input type="text" name="first_name"><br>
<label for="second_name">Second Name: </label>
<input type="text" name="second_name"><br>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</form>
---------------------------------------

And this is the php code (corrected according to your comments) ...

--- select.php ---
<?php

$dbhost='localhost';
$dbuser='toto';
$dbpass='password';
$dbname='adbname';

$conn = mysql_connect($dbhost, $dbuser, $dbpass)
or die ('Cannot connect to DB!!');

mysql_select_db($dbname);

$query="SELECT user_id, login, first_name, email, country FROM
users WHERE first_name='$first_name'";

$result = mysql_query($query);

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

echo "Name: {$row['first_name']} <br>" .
"Login: {$row['login']} <br>" .
"Client Number: {$row['user_id']} <br>" .
"Email: {$row['email']} <br>" .
"Country: {$row['country']} <br><br>" ;
}
?>
----------------

If anyone wants to see the table I'm trying to access ..

mysql> describe users;
+-------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+----------------+
| user_id | int(11) | NO | PRI | NULL | auto_increment |
| login | varchar(8) | NO | | | |
| password | varchar(8) | NO | | | |
| first_name | varchar(25) | NO | | | |
| second_name | varchar(25) | NO | | | |
| email | varchar(25) | NO | | | |
| sex | varchar(1) | YES | | NULL | |
| dob | date | NO | | | |
| address1 | varchar(25) | YES | | NULL | |
| address2 | varchar(25) | YES | | NULL | |
| postcode | varchar(10) | YES | | NULL | |
| state | varchar(10) | YES | | NULL | |
| country | varchar(15) | YES | | NULL | |
| landline | varchar(10) | NO | | | |
| fax | varchar(10) | YES | | NULL | |
| mobile | varchar(10) | YES | | NULL | |
| website | varchar(25) | YES | | NULL | |
| quote | varchar(50) | YES | | NULL | |
+-------------+-------------+------+-----+---------+----------------+
18 rows in set (0.11 sec)

Now if I enter say 'john' in the first field of my form and his Submit, I
get 'Resource id #3' (to be fair, I also get this if I enter nothing before
hitting Submit), yet if I execute the query manually ..

myql> SELECT user_id, login, first_name, email, country FROM
-> users WHERE first_name='john';
+---------+---------+------------+-----------------------+-----------+
| user_id | login | first_name | email | country |
+---------+---------+------------+-----------------------+-----------+
| 2 | john | John | john12@gmail.com | Australia |
+---------+---------+------------+-----------------------+-----------+
1 row in set (0.00 sec)

So something's not right with the code, obviously..... :-(

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация