| We hope you enjoy your visit. You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you're already a member please log in to your account to access all of our features: |
- Pages:
- 1
- 2
| Sql row Checking | |
|---|---|
| Tweet Topic Started: May 13 2005, 12:16 AM (679 Views) | |
| Das | May 13 2005, 12:16 AM Post #1 |
![]()
Smells of rich mahogany
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Is there a way to stop infromation from being submitted twice to to the database? Like if I add Bob to the members collum is there a way to stop someone else from adding Bob to the members collum? Also is there a way to see how many times something has appeared within a MySql collum? Like if I submit the info yes to the collum yes_or_no six times is there a way to show that it is there six times, and have it update whenever it changes? Finally are all mysql files hidden from veiwing? More simply is there a way to look at someones source and see there Sql login info? |
![]() |
|
| Rory | May 13 2005, 05:36 AM Post #2 |
|
i;m a mess
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
just do a query to check if there is already a member called bob, if there is then give an error message, otherwise let them do it. here is the logic: validate details entered (ie. no fields missing) $query = "select * from members where membername = '$_POST[membername]'"; $result = mysql_query($query); if ($result) { echo "error, membername already in use"; } else { insert member to database here } for the next one, about seeing howmany times something is entered into a column: "select * from tablename where columnname = '$valueYouWantToCheck'"; echo mysql_num_rows($result) i don;t know if there is a better way of doing this (perhaps using COUNT(*) in your query, but i'm not sure if that would work properly). the MySQL files are hidden from general viewing, as they are stored outside of your public_html folder. If people look at your source on a page, all they will see is HTML, as PHP just generates HTML, and won't show anything else. |
![]() |
|
| Das | May 15 2005, 11:04 PM Post #3 |
![]()
Smells of rich mahogany
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Wouldn't it be if($result == $_Post["Username") { .....
Wouldn't it be echo "mysql.... Also what would this display? Just the number of times it is displayed, or would it show all of the entries (like show yes 78 times in a row)? Also quick question that has nothing to do with php is there a way to change a html form size? |
![]() |
|
| Rory | May 16 2005, 07:04 AM Post #4 |
|
i;m a mess
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
if ($result) ^^ that checks whether the mysql_query actually returned a result (ie. returned at least one row, or if you are updating/deleting something, if the mysql_query updated/deleted a row). So in this case, it checks whether the query actually found anything, and if it did, it prints an error that says the member name is already in use, otherwise it inserts the new user. the second example, about mysql_num_rows(). This function returns the number of rows returned by a query (i think count() is a better function to use within the query... but i'm not sure about that). So when you use the statement: echo mysql_num_rows($result) it would output the number of rows returned. you could alter it to have a bit of text with it too... echo "The number of times that it was found in the database: " . mysql_num_rows($result); |
![]() |
|
| Das | May 22 2005, 08:04 PM Post #5 |
![]()
Smells of rich mahogany
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
It works, but dosn't display an error message. |
![]() |
|
| Das | May 23 2005, 08:18 PM Post #6 |
![]()
Smells of rich mahogany
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Bump. |
![]() |
|
| Dennis | May 24 2005, 10:28 AM Post #7 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Please elaborate. If there's no match, it won't show an error message. Do you get any output? |
![]() |
|
| Das | May 24 2005, 10:47 AM Post #8 |
![]()
Smells of rich mahogany
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
When I try to add something with the same name it appears to add the name, but when I check phpMyAdmin it shows that the script worked and it didn't re-register, but I get no error message when I register. |
![]() |
|
| Rory | May 24 2005, 10:48 AM Post #9 |
|
i;m a mess
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
and you are using the exact same code i wrote? |
![]() |
|
| Das | May 24 2005, 10:49 AM Post #10 |
![]()
Smells of rich mahogany
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
I changed the variables to fit what I was working on, other than that yes. My Code: $query = "select * from members where username = '$user'"; $result = mysql_query($query); if ($result) { echo "error, membername already in use"; } else { insert member to database here } Odviously I have insert member in to database here as an actual code. |
![]() |
|
| Rory | May 24 2005, 10:50 AM Post #11 |
|
i;m a mess
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
my bad.. i think, try this: $query = "select * from members where username = '$user'"; $result = mysql_query($query); if (mysql_num_rows($resul)t) { echo "error, membername already in use"; } else { insert member to database here } |
![]() |
|
| Das | May 24 2005, 10:56 AM Post #12 |
![]()
Smells of rich mahogany
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
I am assuming you meant '$result)'
Row 13 is the row I quoted. |
![]() |
|
| Rory | May 24 2005, 10:56 AM Post #13 |
|
i;m a mess
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
whoops, yeah, my typing sucks at times ![]() if (mysql_num_rows($result)) { |
![]() |
|
| Das | May 24 2005, 10:59 AM Post #14 |
![]()
Smells of rich mahogany
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
No error message displays again. Mabey I am missing something.
|
![]() |
|
| Rory | May 24 2005, 11:02 AM Post #15 |
|
i;m a mess
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
mmm, i am using the exact same code, and it is working fine :s
(ignore the showContent function, it just keeps code duplication down) |
![]() |
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| Go to Next Page | |
| « Previous Topic · Technology Chat · Next Topic » |
- Pages:
- 1
- 2
| Track Topic · E-mail Topic |
10:45 AM Jul 11
|




![]](http://b1.ifrm.com/0/1/0/p601690/pipright.png)




10:45 AM Jul 11