Okay.... Some help is needed here!
I have a problem, and I don't know how to fix it. I just now started with MySQL and PHP togethor, and I can't get MySQL to work right. What I mean is when I have a form and send it to a PHP file that connects to the MySQL DB it says it works. But when I print the stuff in the table it's empty... help please???
I think I was confusing there
[James Logsdon]
nike_guy_man posted this at 03:03 — 4th May 2002.
They have: 840 posts
Joined: Sep 2000
Post the code please so we can see whats wrong...
What versions of PHP and MySQL are you using?
necrotic posted this at 23:54 — 4th May 2002.
He has: 296 posts
Joined: May 2002
The code I use to Read from the DB...
<?php
<html>
<body>
$db = mysql_connect(\"localhost\", \"USERNAME\", \"PASSWORD\");
mysql_select_db(\"testdb\",$db);
$result = mysql_query(\"SELECT * FROM users\",$db);
echo \"<table border=1>\n\";
echo \"<tr><td>Member</td><td>E-Mail</tr>\n\";
while ($myrow = mysql_fetch_row($result)) {
printf(\"<tr><td>%s %s</td><td>%s</td></tr>\n\",
$myrow[1], $myrow[2], $myrow[3]);
}
echo \"</table>\n\";
</body>
</html>
?>
Do you need the one I use to input to the DB?
[James Logsdon]
nike_guy_man posted this at 00:46 — 5th May 2002.
They have: 840 posts
Joined: Sep 2000
Change it to:
<?php
<html>
<body>
$db = mysql_connect(\"localhost\", \"USERNAME\", \"PASSWORD\");
mysql_select_db(\"testdb\",$db);
$query = \"SELECT * FROM users\";
$result = mysql_query($query);
echo \"<table border=1>\n\";
echo \"<tr><td>Member</td><td>E-Mail</tr>\n\";
while ($myrow = mysql_fetch_array($result)) {
print \"<tr><td>%s %s</td><td>%s</td></tr>\n\";
echo \"<tr><td>$myrow[1] $myrow[2]</td><td> $myrow[3]</td></tr>\";
}
echo \"</table>\n\";
?>
Also, show us the code for inputting as well... please
Mark Hensler posted this at 06:13 — 5th May 2002.
He has: 4,048 posts
Joined: Aug 2000
The original printf() statement is ok. I don't see anything wrong with that script. Does it produce any errors?
Have you checked the mySQL DB to make sure that there is data inside the table?
Posting the insert script will help.
Mark Hensler
If there is no answer on Google, then there is no question.
necrotic posted this at 22:45 — 6th May 2002.
He has: 296 posts
Joined: May 2002
The insert script:
<?php
<html>
<body>
if ($submit) {
// process form
$db = mysql_connect(\"localhost\", \"USERNAME\", \"PASSWORD\");
mysql_select_db(\"testdb\",$db);
$sql = \"INSERT INTO users (user,password) VALUES ('$user','$password')\";
$result = mysql_query($sql);
echo \"Thank you! Information entered.\n\";
} else{
// display form
<form method=\"post\" action=\" echo $PHP_SELF\">
Username:<input type=\"Text\" name=\"user\"><br>
Password:<input type=\"Text\" name=\"password\"><br>
<input type=\"Submit\" name=\"submit\" value=\"Register\">
</form>
} // end if
</body>
</html>
?>
I checked the table before and it was empty, so I think it's the insert script.
[James Logsdon]
Mark Hensler posted this at 23:05 — 6th May 2002.
He has: 4,048 posts
Joined: Aug 2000
one thing.. you forgot a semicolon..
<?php
echo $PHP_SELF<strong>;</strong>
?>
I don't see anything else wrong with it.
try testing $result and printing errors...
<?php
$result = mysql_query($sql);
if (!$result) {
echo \"QUERY ERROR: \" . mysql_error() . \"\n\";
echo \"QUERY: $sql\n\";
}
?>
Mark Hensler
If there is no answer on Google, then there is no question.
necrotic posted this at 00:03 — 7th May 2002.
He has: 296 posts
Joined: May 2002
Now I get the error:
<?php
QUERY ERROR: No Database Selected QUERY: INSERT INTO users (user,password) VALUES ('necrotic','darkone')
?>
Mark Hensler posted this at 06:29 — 7th May 2002.
He has: 4,048 posts
Joined: Aug 2000
alright, that's progress..
Make sure that your connection info is correct (username, password, hostname, database name). I believe mySQL is case sensitive.
Mark Hensler
If there is no answer on Google, then there is no question.
necrotic posted this at 20:55 — 7th May 2002.
He has: 296 posts
Joined: May 2002
Now it inserts it into the database but doesn't display with the get script. It shows only the password. You can find both scripts here(insert) and here(get)
[James Logsdon]
Mark Hensler posted this at 06:34 — 8th May 2002.
He has: 4,048 posts
Joined: Aug 2000
Everything is getting inserted ok?
Just the password is being successfully retrieved?
Have you altered the get script?
Can you post the database structure?
Mark Hensler
If there is no answer on Google, then there is no question.
necrotic posted this at 20:50 — 8th May 2002.
He has: 296 posts
Joined: May 2002
It inserts both the Username and Password but only displays the Password... I didn't edit the Get script. What do you mean db structure? Like I said, I'm new to this.
[James Logsdon]
Peter J. Boettcher posted this at 20:52 — 8th May 2002.
They have: 812 posts
Joined: Feb 2000
Database structure means the design and layout of your database. This includes the names of your tables, the field names in those tables as well as the data types of those fields.
PJ | Are we there yet?
pjboettcher.com
necrotic posted this at 21:21 — 8th May 2002.
He has: 296 posts
Joined: May 2002
So.... something like:
<strong>
Table | Field(s) | Type | Attributes | Null | Default | Extra</strong>
--------------------------------------------------------------------
users | user | varchar(20) | | No | | |
users | password | tinytext | | No | | |
--------------------------------------------------------------------
[James Logsdon]
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.