|
|
Viewing Topic: phpNewbie -
Code Not
Working :( |
moonshadow |
Subject: "phpNewbie -
Code Not
Working :("
Posted: @ 2:49 pm on Mar 01 2008 |
|
|
Member #: 597 Rank: user - (4) Since: 02/26/08 Posts: 3 From: Florida
|
Hi, I don't
know what I'm
doing wrong. It
connect, it
read the data
base, But I
can't insert
data from php
page(a user
can't input
data into
MySQL). Can
anyone help me?
This is my
code:
=============[t
est.php]==(inpu
t)========
<html><
;head>
<title>Un
titled</titl
e></head&
gt;<body>
<form
action="my
script.php"
;
method="po
st">
User Name:
<input
type="text
"
name="user
name">&
lt;br>
Password:
<input
type="pass
word"
name="pass
word">&
lt;br>
<input
type="subm
it"
value="Sub
mit">
</form>
</body>&l
t;/html>
===============
===============
===============
===
=========[myscr
ipt.php]===(out
put)===========
===
<html><
;head>
<title>Te
sting</title
></head&g
t;<body><
br />
<p>Testin
g data tranfer
into databse:
</p><u
l>
<?php
$connect=mysql_
connect('databa
se',username','
password'); /*
line ok
mysql_select_db
('mysql')or
die('couldn't
select db');
$query='SELECT
* FROM bin
WHERE 1';
$result=
mysql_query($qu
ery) or
die('Query
failed: '
.mysql_error())
;
INSERT INTO
`mysql` (name,
pass) VALUES
('".$_POST
['username'].&q
uot;',
'".$_POST[
'password'].&qu
ot;');
?>
</ul><
/body></h
tml>
===============
===============
===============
THEN I CHECK MY
MySQL database
and no data
have been
insert, from
$_POST. :( What
can I do? :cp:
I'm using
phpMyAdmin
2.6.3-pl1, and
MySQL 4.1.14
(oh Yahoo
Server)
Thanks in
advance!
Simplify! |
| Viewed: 6,275 Times | |  |
xecu |
Subject: "re: phpNewbie -
Code Not
Working :("
Posted: @ 9:19 pm on Mar 01 2008
|
|
|
Member #: 599 Rank: user - (6) Since: 02/27/08 Posts: 6 From: New York City
|
moonshadow
said...
<
i>
=============
[test.php]
==(input)======
==
<html><
;head>
<title>Un
titled</titl
e></head&
gt;<body>
<form
action="m
yscript.php&qu
ot;
method="p
ost">
User Name:
<input
type="tex
t"
name="use
rname">
;<br>
Password:
<input
type="pas
sword"
name="pas
sword">
;<br>
<input
type="sub
mit"
value="Su
bmit">
</form>
</body>&l
t;/html>
===============
===============
===============
===
=========
[myscript.php]
===(output)====
==========
<html><
;head>
<title>Te
sting</title
></head&g
t;<body>
<p>Testin
g data tranfer
into databse:
</p><u
l>
<?php
$connect=mysql_
connect('datab
ase',username
','password')
; /* line ok
mysql_select_db
('mysql')or
die('couldn't
select db');
$query='SELECT
* FROM bin
WHERE 1';
$result=
mysql_query($qu
ery) or
die('Query
failed: '
.mysql_error())
;
INSERT INTO
`mysql` (name,
pass) VALUES
('".$_PO
ST['username'
]."',
'".$_POS
T['password']
."');
?>
</ul><
/body></h
tml>
===============
===============
===============
Your code
according to
your
database(mysql)
and table(bin),
and I am
asuming you
want to add a
new username
and password to
the table,
while also
checking if
there is a user
like it
already? Than
your code
should look
like this:
Code:
$query =
"SELECT
COUNT(*) FROM
bin WHERE name
=
'$_POST[userna
me]'";
$result =
mysql_query($qu
ery) or
die('Query
failed: '
.mysql_error())
;
if
(@mysql_result(
$result,0,0)>
;0) {
echo 'A
user already
exists with
your chosen
username.';
}
$query =
"INSERT
INTO bin SET
name =
'$_POST[userna
me]',
pass =
'$_POST[passwo
rd]'";
if
(!mysql_query($
query))
echo 'A
database error
occurred in
processing your
query';
You see heaven,
before you see
hell. - Xecu |
Viewed: 6,262 Times | |  |
Viewing Page: 1 of 1 |
|
|
|