473,789 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Forms...and WHERE in mysql

Hi guys,
I found this script:
http://hvassing.com/2007/simple-php-...#comment-31549

but if I try to recall, in a page I created, the variable "username"
that a user fill in the login page, it does not work.
How could I retrieve the "username", in other pages, using sessions?

I think that the answer is in the last 8 lines of code of
"manage-check.php" but I do not know how....

For example if I fill this code in "members-only.php":

---------------------------------------
<?
$db=mysql_conne ct('XXXX.YYYYYY YYYYYY.ZZZ','us er','123456') or
die(mysql_error ());

mysql_select_db ("XXXX",$db) ;

$result=mysql_q uery("SELECT * FROM members
WHERE username="$_POS T[username]"");
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^
while ($record = mysql_fetch_row ($result)){
echo "id: ".$record[0]."<br />";
echo "NOME: ".$record[1]."<br />";
echo "<br />";
}
---------------------------------------

it does not work!!!
How could I retrieve "username" using "WHERE username="????? ????" ???

TNX in advance!
Dec 28 '07 #1
9 1855
On Dec 28, 12:13*pm, lukk3tt0 <lu...@ghjghjhg .llwrote:
Hi guys,
I found this script:http://hvassing.com/2007/simple-php-...session-and-my...

but if I try to recall, in a page *I created, the variable "username"
that a user fill in the login page, it does not work.
How could I retrieve the "username", in other pages, using sessions?
hmmm cannot quite follow, but a common thing (which even I made when
using sessions first time :-|) is to forget to user start_session()
every time. It does not start the sesstion, just gives you access to
it.
$result=mysql_q uery("SELECT * FROM members
WHERE username="$_POS T[username]"");
Gee... I have been wondering whether the post can be in there, but
*just in case* I have always used it like this

$result=mysql_q uery("SELECT * FROM members WHERE username=\"".
$_POST["username"]."\"");
or
$result=mysql_q uery("SELECT * FROM members WHERE username=\"".
$_SESSTION["username"]."\"");

say
if(isset($_SESS TION["username"]))
$result=mysql_q uery("SELECT * FROM members WHERE username=\"".
$_SESSTION["username"]."\"");
else
$result=mysql_q uery("SELECT * FROM members WHERE username=\"".
$_POST["username"]."\"");

WBR
Sonnich
Dec 28 '07 #2
On Dec 28, 6:13 pm, lukk3tt0 <lu...@ghjghjhg .llwrote:
Hi guys,
I found this script:http://hvassing.com/2007/simple-php-...session-and-my...

but if I try to recall, in a page I created, the variable "username"
that a user fill in the login page, it does not work.
How could I retrieve the "username", in other pages, using sessions?

I think that the answer is in the last 8 lines of code of
"manage-check.php" but I do not know how....

For example if I fill this code in "members-only.php":

---------------------------------------
<?
$db=mysql_conne ct('XXXX.YYYYYY YYYYYY.ZZZ','us er','123456') or
die(mysql_error ());

mysql_select_db ("XXXX",$db) ;

$result=mysql_q uery("SELECT * FROM members
WHERE username="$_POS T[username]"");
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^
while ($record = mysql_fetch_row ($result)){
echo "id: ".$record[0]."<br />";
echo "NOME: ".$record[1]."<br />";
echo "<br />";}

---------------------------------------

it does not work!!!
How could I retrieve "username" using "WHERE username="????? ????" ???

TNX in advance!
The MySQL Select should be like
SELECT `field`, `field` FROM `table` WHERE `field`='value' ;

you need the '' unless the field is kinda int
Dec 28 '07 #3
lukk3tt0 wrote:
Hi guys,
I found this script:
http://hvassing.com/2007/simple-php-...#comment-31549

but if I try to recall, in a page I created, the variable "username"
that a user fill in the login page, it does not work.
How could I retrieve the "username", in other pages, using sessions?

I think that the answer is in the last 8 lines of code of
"manage-check.php" but I do not know how....

For example if I fill this code in "members-only.php":

---------------------------------------
<?
$db=mysql_conne ct('XXXX.YYYYYY YYYYYY.ZZZ','us er','123456') or
die(mysql_error ());

mysql_select_db ("XXXX",$db) ;

$result=mysql_q uery("SELECT * FROM members
WHERE username="$_POS T[username]"");
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^
while ($record = mysql_fetch_row ($result)){
echo "id: ".$record[0]."<br />";
echo "NOME: ".$record[1]."<br />";
echo "<br />";
}
---------------------------------------

it does not work!!!
How could I retrieve "username" using "WHERE username="????? ????" ???

TNX in advance!
Enable display_errors and see what you get for messages.

Also, please cross-post; do not multi-post!

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Dec 28 '07 #4
..oO(jodleren)
>Gee... I have been wondering whether the post can be in there, but
*just in case* I have always used it like this

$result=mysql_q uery("SELECT * FROM members WHERE username=\"".
$_POST["username"]."\"");
or
$result=mysql_q uery("SELECT * FROM members WHERE username=\"".
$_SESSTION["username"]."\"");
Strings in SQL are delimited with single quotes. And you _never_ want to
use a user-submitted value directly in a query without any validation.
Read about SQL injection.

Micha
Dec 28 '07 #5
On Dec 28, 2:13 am, lukk3tt0 <lu...@ghjghjhg .llwrote:
Hi guys,
I found this script:http://hvassing.com/2007/simple-php-...session-and-my...

but if I try to recall, in a page I created, the variable "username"
that a user fill in the login page, it does not work.
How could I retrieve the "username", in other pages, using sessions?

I think that the answer is in the last 8 lines of code of
"manage-check.php" but I do not know how....

For example if I fill this code in "members-only.php":

---------------------------------------
<?
$db=mysql_conne ct('XXXX.YYYYYY YYYYYY.ZZZ','us er','123456') or
die(mysql_error ());

mysql_select_db ("XXXX",$db) ;

$result=mysql_q uery("SELECT * FROM members
WHERE username="$_POS T[username]"");
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^
while ($record = mysql_fetch_row ($result)){
echo "id: ".$record[0]."<br />";
echo "NOME: ".$record[1]."<br />";
echo "<br />";}

---------------------------------------

it does not work!!!
How could I retrieve "username" using "WHERE username="????? ????" ???

TNX in advance!

$result=mysql_q uery("SELECT * FROM members
WHERE username="$_POS T[username]"");

Your quotes are messed up, doing what sskaje said should fix your
problem.

$result = mysql_query("SE LECT * FROM members WHERE username=`
$_POST['username']`");

That should fix your problem.
Dec 28 '07 #6
..oO(jp****@gma il.com)
>$result=mysql_ query("SELECT * FROM members
WHERE username="$_POS T[username]"");

Your quotes are messed up, doing what sskaje said should fix your
problem.

$result = mysql_query("SE LECT * FROM members WHERE username=`
$_POST['username']`");

That should fix your problem.
Nope. It will cause a parse error because of the single-quoted array
index inside of a double-quoted string. Additionally it will cause an
SQL error because a backtick (`) is not a valid string delimiter.

Correct:

$result = mysql_query("
SELECT *
FROM members
WHERE username = '$_POST[username]'
");

or

$result = mysql_query("
SELECT *
FROM members
WHERE username = '{$_POST['username']}'
");

Of course this won't fix the SQL injection problem ...

Micha
Dec 29 '07 #7
Michael Fesser wrote:
Read about SQL injection.
Well, I prefer to laught at it:

http://xkcd.com/327/
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Now listening to: Lamb - The K&D Sessions? (1998) - [10] Trans Fatty Acid
(K&D Session) (8:31) (97.000000%)
Dec 29 '07 #8
On Sat, 29 Dec 2007 01:33:01 +0100, Michael Fesser <ne*****@gmx.de wrote:
.oO(jp****@gmai l.com)
>$result=mysql_ query("SELECT * FROM members
WHERE username="$_POS T[username]"");

Your quotes are messed up, doing what sskaje said should fix your
problem.

$result = mysql_query("SE LECT * FROM members WHERE username=`
$_POST['username']`");

That should fix your problem.

Nope. It will cause a parse error because of the single-quoted array
index inside of a double-quoted string. Additionally it will cause an
SQL error because a backtick (`) is not a valid string delimiter.

Correct:

$result = mysql_query("
SELECT *
FROM members
WHERE username = '$_POST[username]'
");
Which will probably give a notice the constant 'username' is not defined..
or

$result = mysql_query("
SELECT *
FROM members
WHERE username = '{$_POST['username']}'
");
That's the one.
Of course this won't fix the SQL injection problem ...
Very true. And a 'SELECT * ' should never be used in production, only for
testing purposes. Naming the fields you should have will both ease the
load on the server and cause a transparant failure instead of an obscure
one on a table alteration.
--
Rik Wasmus
Dec 31 '07 #9
..oO(Rik Wasmus)
>On Sat, 29 Dec 2007 01:33:01 +0100, Michael Fesser <ne*****@gmx.de wrote:
>$result = mysql_query("
SELECT *
FROM members
WHERE username = '$_POST[username]'
");

Which will probably give a notice the constant 'username' is not defined.
Nope, not in this case. Constants are not resolved in a double-quoted
string (unless you use curly syntax like in the second example).
Whether this syntax is recommended or not is another question, though.

Micha
Dec 31 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2589
by: Charles E. Pelkey | last post by:
Hi all, Got a question for y'all regarding the best way to maintain HUGE forms and linking them to data tables in MySQL. I have a set of forms that were created specifically for a Loan Services Company (ranging from request forms to complex inspection forms with hundreds of input fields (such as room size, item quantity, item quality and costs) the problem I had in the initial setup was how to create the associated data tables for...
1
1959
by: Nona Me | last post by:
Is there a program that can make automatically input forms and views using the table design information in mysql. for example: in mysql you have a table: Customer with the next field: Name, Address, ZipCode, City the 'automatic form creator' should create a input form with the fields Name, Address, ZipCode, City, add a submit and reset button. you should also be able to make new customers and delete customers
3
2191
by: Jim Johnstone | last post by:
Some details of my HOME PC. I am running the following .... Win2000 SP4; IE V6; 512MB RAM; H/Disk Space OK. In the past couple of weeks I have installed/configured from binaries for .. MySQL V4.1.5 Apache V2.0.50 PHP V5.0.2 PHPMYADMIN V2.6.0 OBJECTIVE: To use my HOME PC to run a local APACHE web server on which to
6
2737
by: gonzalo briceno | last post by:
I have been using phplib for a while and I really like the framework except for form creation. Maybe it is me but I in my opinion there isn't a good way to create forms or should I say, everything else is so well done that the way you create forms seems to be too cumbersome, in particular making it so that a pull down menu selects a value that you assign it. In any case, does anyone know of any php based (or other readily accepted web...
6
2784
by: MLH | last post by:
"The following unexpected error occurred in Sub CopyMySQLbttn_Click, line #250, CBF on frmVehicleChooserform. 2465: "Can't find the field 'forms' referred to in your expression. You may have misspelled the field name, or the field may have been renamed or deleted." The above error is returned when running the following click code. I don't understand what the error means. Private Sub CopyMySQLbttn_Click() On Error GoTo...
8
1640
by: Tempo | last post by:
I have been looking around for a few days for ways to use Python with HTML forms. What I am interested in doing is placing the data that is submited through an HTML form and collected by Python into a MySQL database. I initially thought that I was going to be able to do this with ASP, but I found out that my web hosting provider doesn't have ASP support installed into their servers. Also, I couldn't find any dirt cheap hosting providers...
5
1239
by: greg | last post by:
HI, I have an asp page that loops through the forms collection gathering data from input controls that web surfers have entered in. The problem I have is when I get to the submit button, I get the follow error "Type mismatch: '' " "send me the brochure" is the text on the submit button. I don't know how to have the loop skip the submit button. Any help would be appreciated. here is the code:
3
11847
by: elyob | last post by:
Okay, I'm about to add some checkboxes to a form, and then store the data in a column on a MySQL database. Just wanted to know best practice, at the moment I'm writing and thinking .. God that's ungly code ... <input type="checkbox" name="delta" <?php if ($delta==1) { echo "checked"; }?>> Delta<br> <input type="checkbox" name="mastercard" <?php if ($mastercard==1) { echo "checked"; }?>> Mastercard<br> <input type="checkbox" name="solo"...
4
5887
by: dirk | last post by:
Hey, I'm new to php and I'm trying to write some php code so that I can insert data into a mysql database using html forms. I've got two text forms and a submit button. When entering data and selecting 'submit' a new record in my database is created. So far so good... But when I enter data in only one content and hit the enter key a new record is created with one empty field. And that something I don't want to happen.
2
2243
by: klimmer | last post by:
Hello, I'am used to work with PHP and MySQL on webbased application. I have to make for my colleagues a program that have to follow a few dessistions (path) like a flowchart. The result shood be a word document from about, 150-250 pages. The chapters are, depending of the anwsers in the virtuel flowchart. Afterwoods there are more then 100 fields automaticaly filled in from excel tabels. What qind of fields are depending of the flow...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10374
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5539
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2898
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.