|
-
Aug 19th, 2005, 09:55 PM
#1
Thread Starter
Junior Member
Php and MySQL help, please? :(
Hello everyone,
I'm new to the VBForums, and very new to the whole MySQL scripts and database stuff.
I'm sorry if this has been asked before in the forums, but I have a small problem, that I'm sure is very easy to do, although I'm such a nooby.
I've posted this also on the www.weberforums.com (http://www.weberforums.com/ftopic7639.html), but didnt find any of the replies useful, as not many people understood what I was asking...
Well, here goes;
Just wondering if someone can help by letting me know where exactly I should start, or maybe post an example script.
I'm looking to create a form, not an email form, but an invisible one, something that runs when the page is accessed.
... Hmm, might be easier to explain if I let you know why I need it.
Well, mostly, I wanted it so if a page on the site gets accessed, a section in a Mysql database will be updated, just like a MySql/php counter.
Except what I want it to do is edit a table (like make it add 1 or 2 to the number in that table (just like a post count on a forum), and/or take numbers, edit/add/delete text, and stuff like that.
However, alot of the tables in the MySQL database are going to be the same. Well, im not sure if they are called tables, but like a phpbb forum, when you go to edit members post, or details using phpMySQL, and accessing them through the user table...
Im so sorry if Im not explaining this properly, but what I mean is that I want to make a "Register" form (which I'll make a script abit later on), which will add a table in the Users section of the MySQL database, and then a script that, if a page is visited, a section of their table in the User will be editted.
For an example, say someoned signed up with a name like, Test123. The table might include:
Name: Test123
Post Amounts: 15
Description: Description 1
And, if they access a page, like called desciptionPOST.php, then it will update the table, and change it to like, I dont know.. something like this:
Name: Test123
Post Amounts: 16
Description: Description 1
Description 2
Im sorry if that's confusing.
Thankyou to anyone who does help, and if you need me to make it clearer, I'll do my best to do so.
Thanks so much to anyone who has a look or even posts a link to somewhere where I can learn a code something similar to this.
Thanks again, and if you do need to email me, you can do so at [email protected]
Thankyou!!
-
Aug 20th, 2005, 09:59 PM
#2
Hyperactive Member
Re: Php and MySQL help, please? :(
uhh....a......uhh..hmm... wha..????...
explain a lil more clearer...you confused me on
"However, alot...."
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Aug 21st, 2005, 05:38 AM
#3
Thread Starter
Junior Member
Re: Php and MySQL help, please? :(
Actually, I got a script from a nice person who helped me out. Here's the script:
Code:
<?
//you db connection info here
$sql = "insert into tableName(fieldlist)VALUES(valuelist)";
$result = mysql_query($sql);
//desired error reporting based on needs for app
//if its not that important that eveything should stop then don't check for errors
//if its important, then you still don't want stuff to stop, but perhaps send yourself
//an email showing the mysql_error() so you can try to solve the issue
?>
However, I just need to know what exactly the "$sql = "insert into tableName(fieldlist)VALUES(valuelist)";" means.
Like what TableName(fieldlist) is if we use the above example of the table being called "user", and what VALUES(valuelist) means.
Maybe this will explain abit better.
I have a table called "users". I've got a php/html code that allows people to register, which then sends their information into that table. Just say one of the table is called "posts"...
If I want them to access a page, which will have the code I have above in it, how can I change the amount to add "1" into it, but also keep the amount of posts they had before?
Like, for example, if they have 8 posts, how do I edit the script you gave me to add 1 to 8, which will make it 9 posts?
Thanks so much for the reply, and taking the time to look at my post
-
Aug 21st, 2005, 06:44 AM
#4
Hyperactive Member
Re: Php and MySQL help, please? :(
Okay this is an example from my forum script.
PHP Code:
$result= MYSQL_QUERY("INSERT INTO topics (id, cid, Author, Title, Date, Post, lastpost, category).
"VALUES ('NULL', '$tid', '$username', '$Title', '$today', '$Post', '$today', '$cat')");
############
#post counter
$result = @mysql_query("SELECT * FROM members WHERE username = '$username'");
while ($userinfo = mysql_fetch_array($result)){
$postcount = $userinfo['newsposts'] + 1;
@mysql_query("
UPDATE members SET newsposts = \"$postcount\" WHERE username = \"$username\"
");
its accually quite simple really... for the post count... your adding 1 to the current number of posts then updating the table members/user w/e its called there the username/user w/e = the user's name..lol...
if this still confuses you... plz say so.. and i'll try and explain more better.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Aug 22nd, 2005, 02:37 AM
#5
Thread Starter
Junior Member
Re: Php and MySQL help, please? :(
Hmmm..
I still dont really understand.
How about I just right exactly what I want the script to do? Maybe the script I got was wrong?
I've got a table called "Users", in that table, there is going to be many users (which the signup script (already done) will add heir information into).
Now, There's a row in the table called username, and a row called Numbers.
I want it so if a user accesses a page (say addnumber.php), it will see which username they are logged into (by placing the <?php if (!isset($_COOKIE['loggedin'])) die("You are not logged in!"); ?> code ontop of the page, which is linked to the login.php file with: setcookie("loggedin", "TRUE", time()+(3600 * 24)); setcookie("mysite_username", "$username");), and then add "#" to the Numbers row.
So, if there username is TEST123, and it calls their username (so it knows which Column to update), and adds "#" (lets just say 1) to their existing # (lets say 9), and it will then update it to make it 10.
Is there a script to do this (know which column (user) to edit, then add something (+1) to the correct row(Numbers)?
Im sorry if it's confusing..
-
Aug 22nd, 2005, 03:33 AM
#6
Hyperactive Member
Re: Php and MySQL help, please? :(
PHP Code:
#Counter
$result = @mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[loggedin]'");
while ($usr = mysql_fetch_array($result)){
$addtonumbers = $usr['numbers'] + 1;
@mysql_query("UPDATE users SET numbers = '$addtonumbers' WHERE username = '$_COOKIE[loggedin]'");
}
that should work for you. If of coarse those are teh fields used
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Aug 22nd, 2005, 03:40 AM
#7
Hyperactive Member
Re: Php and MySQL help, please? :(
sorry if im confusing you... i just post wut i think your asking.. lol.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Aug 22nd, 2005, 03:47 AM
#8
Thread Starter
Junior Member
Re: Php and MySQL help, please? :(
No No, no confusion at all!
Thankyou for posting this script, it's exactly what I asked!
I will try it out and let you know how it went.. 
Thankyou
-
Aug 22nd, 2005, 04:02 AM
#9
Hyperactive Member
Re: Php and MySQL help, please? :(
wuts loggedin = to... the username.. if not change it to w/e it is..lol
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Aug 22nd, 2005, 04:07 AM
#10
Thread Starter
Junior Member
Re: Php and MySQL help, please? :(
Hey!
Thankyou again for trying to help.
I tried to run the script to see if it updated the row, but i seemed to get this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/hanime07/public_html/RPG/testing/test.php on line 16
Also, just to ask, you know how in the script you wrote "$addtonumbers = $usr['numbers'] + 1;", if I want to edit this, to add 1 somewhere else, do I only change the "$usr['numbers']"? Say the new row is called "Points", do I change it to "$addtonumbers = $usr['points'] + 1;"?
Thanks again for the help!
-
Aug 22nd, 2005, 04:10 AM
#11
Thread Starter
Junior Member
Re: Php and MySQL help, please? :(
 Originally Posted by PlaGuE
wuts loggedin = to... the username.. if not change it to w/e it is..lol
Here's the code from logscript.php (where login.php (a html form) is linked to after submitting):
Code:
setcookie("loggedin", "TRUE", time()+(3600 * 24));
setcookie("mysite_username", "$username");
I guess it's linked to the username?
Im sorry, I'm not too sure about mysql/php. The login/signup code was created by a tutorial I followed...
-
Aug 22nd, 2005, 06:16 AM
#12
Hyperactive Member
Re: Php and MySQL help, please? :(
regarding second last post... yes.
and about that error with teh mysql_fetch_array() error... idk y that happened... lol that was straight from one of my scripts that i made.
ima have ta sleep on it... who knows...the answer may come to me in a dream... just like it did... last night... when it said... MAKE external sql file. so i did it.. and its sweet.
Last edited by PlaGuE; Aug 22nd, 2005 at 06:22 AM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Aug 22nd, 2005, 06:24 AM
#13
Hyperactive Member
Re: Php and MySQL help, please? :(
show me where you use the snippet i gave you... maybe i or you missed sumtin..lol....
i hope it wasnt any of us..
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Aug 23rd, 2005, 01:21 AM
#14
Thread Starter
Junior Member
Re: Php and MySQL help, please? :(
lol..
Here's the code (editted) found in test.php
Code:
<?php if (!isset($_COOKIE['loggedin'])) die("You are not logged in!"); ?>
<?php
include ("config.php");
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
$result = @mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[loggedin]'");
while ($usr = mysql_fetch_array($result)){
$addtonumbers = $usr['level'] + 1;
@mysql_query("UPDATE users SET numbers = '$addtonumbers' WHERE username = '$_COOKIE[loggedin]'");
}
?>
The code can be found at http://www.animefusion.net/RPG/testing/test.php
However, make sure to login with the details I posted before you visit the page, as the "check if loggedin" script is in place..
 Originally Posted by drkelusion
-
Aug 23rd, 2005, 02:32 AM
#15
Hyperactive Member
Re: Php and MySQL help, please? :(
I changed addtonumbers to levelup just cuz it better suited the scripts intentions.
i changed the query's to
PHP Code:
$result = @mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[mysite_username]'");
AND
@mysql_query("UPDATE users SET numbers = '$levelup' WHERE username = '$_COOKIE[mysite_username]'");
PHP Code:
<?php if (!isset($_COOKIE['loggedin'])) die("You are not logged in!"); ?>
<?php
include ("config.php");
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
$result = @mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[mysite_username]'");
while ($usr = mysql_fetch_array($result)){
$levelup = $usr['level'] + 1;
@mysql_query("UPDATE users SET numbers = '$levelup' WHERE username = '$_COOKIE[mysite_username]'");
}
?>
hopefully it works..
If it dont work... eh.. we'll get it.. eventually.lol
Last edited by PlaGuE; Aug 23rd, 2005 at 04:18 AM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Aug 23rd, 2005, 02:57 AM
#16
Thread Starter
Junior Member
Re: Php and MySQL help, please? :(
Hmm.. still seem to get the same error.
The error says: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/hanime07/public_html/RPG/testing/test.php on line 16, maybe it has something to do with "while ($usr = mysql_fetch_array($result)){"?
-
Aug 23rd, 2005, 03:41 AM
#17
Hyperactive Member
Re: Php and MySQL help, please? :(
yeah but the thing is... it shouldnt have that problem... cuz its right from a working script...
mainly a tutorial i got 11 months ago.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Aug 23rd, 2005, 03:51 AM
#18
Thread Starter
Junior Member
Re: Php and MySQL help, please? :(
I dont know at all whats happening.. here's the editted script:
Code:
<?php if (!isset($_COOKIE['loggedin'])) die("You are not logged in!"); ?>
<?php
include ("config.php");
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
$result = @mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[mysite_username]'");
while ($usr = mysql_fetch_array($result)){
$levelup = $usr['level'] + 1;
@mysql_query("UPDATE users SET numbers = '$levelup' WHERE username = '$_COOKIE[loggedin]'");
}
?>
-
Aug 23rd, 2005, 04:19 AM
#19
Hyperactive Member
Re: Php and MySQL help, please? :(
i think you got the b4 edited version... lol.
the
@mysql_query("UPDATE users SET numbers = '$levelup' WHERE username = '$_COOKIE[loggedin]'");
should be
@mysql_query("UPDATE users SET numbers = '$levelup' WHERE username = '$_COOKIE[mysite_username]'");
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Aug 23rd, 2005, 04:47 AM
#20
Thread Starter
Junior Member
Re: Php and MySQL help, please? :(
The same error came 
I editted the code, and added the new line:
Code:
<?php if (!isset($_COOKIE['loggedin'])) die("You are not logged in!"); ?>
<?php
include ("config.php");
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
$result = @mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[mysite_username]'");
while ($usr = mysql_fetch_array($result)){
$levelup = $usr['level'] + 1;
@mysql_query("UPDATE users SET numbers = '$levelup' WHERE username = '$_COOKIE[mysite_username]'");
}
?>
I dont know what Im doing wrong.. I'm so sorry for waisting you're time.
And thankyou so muc hfor helping me...
-
Aug 23rd, 2005, 05:17 AM
#21
Hyperactive Member
Re: Php and MySQL help, please? :(
your not wasting my time... this is boggling me to the brink of insanity... seriously...
if i can get ahold of a friend of mine... he may have the answer...
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Aug 23rd, 2005, 06:02 AM
#22
Hyperactive Member
Re: Php and MySQL help, please? :(
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Aug 23rd, 2005, 08:04 AM
#23
Thread Starter
Junior Member
Re: Php and MySQL help, please? :(
Code:
<?php if (!isset($_COOKIE['loggedin'])) die("You are not logged in!"); ?>
<?php
include ("config.php");
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
$result = mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[mysite_username]'");
while ($usr = mysql_fetch_array($result)){
$levelup = $usr['level'] + 1;
mysql_query("UPDATE users SET numbers = '$levelup' WHERE username = '$_COOKIE[mysite_username]'");
}
?>
I removed the @'s and still no luck.
HOWEVER!
I posted the code at Weberforums.com, and they replied with this:
 Originally Posted by olaf
its in your query, change this code
$result = mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[mysite_username]'") or die(mysql_error());
this will show you the error...
It seems that the error was correct, and it came up with:
Table 'hanime07_RPG.users' doesn't exist
The table name is called "users", and the database is called "hanime07_RPG". It seems that they were somehow called one?
-
Aug 23rd, 2005, 08:54 AM
#24
Lively Member
Re: Php and MySQL help, please? :(
 Originally Posted by drkelusion
Table 'hanime07_RPG.users' doesn't exist
The table name is called "users", and the database is called "hanime07_RPG". It seems that they were somehow called one?
It's referenced, database.tablename So it's saying the table users in the database hanime07_RPG, doesn't exist. Check your database and table names and make sure they are spelt correctly.
-
Aug 23rd, 2005, 03:35 PM
#25
Hyperactive Member
Re: Php and MySQL help, please? :(
lol.... yeah... i forgot to add that to my query.... sorry bout that... that woulda saved alot of time...
We all make mistakes...
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Aug 23rd, 2005, 05:19 PM
#26
Thread Starter
Junior Member
Re: Php and MySQL help, please? :(
 Originally Posted by PlaGuE
lol.... yeah... i forgot to add that to my query.... sorry bout that... that woulda saved alot of time...
We all make mistakes...
Lol.. that's no problem at all! I was just saying that since now we know what the error is , it should be MUCH easier.
Well, the database is called hanime07_RPG and the table is called Users.
It is because Users is capaital that it cant connect to it?
-
Aug 23rd, 2005, 05:27 PM
#27
Thread Starter
Junior Member
Re: Php and MySQL help, please? :(
Sorry about the double post.
It WORKS completely. The script runs through, and I added a Success comment:
Code:
<?php if (!isset($_COOKIE['loggedin'])) die("You are not logged in!"); ?>
<?php
include ("config.php");
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
$result = @mysql_query("SELECT * FROM Users WHERE username =
'$_COOKIE[mysite_username]'") or die(mysql_error());
while ($usr = mysql_fetch_array($result)){
$levelup = $usr['level'] + 01;
@mysql_query("UPDATE Users SET numbers = '$levelup' WHERE username =
'$_COOKIE[mysite_username]'");
}{
echo "You have leveled Up!!";
}
?>
Found at http://www.animefusion.net/RPG/testing/test.php (make sure to login first).
However, I visited the MySQL database.. and the "level" column doesnt seem to be updated on that user.
Any ideas? 
So close too..
Thanks again for helping
-
Aug 23rd, 2005, 05:56 PM
#28
Hyperactive Member
Re: Php and MySQL help, please? :(
Parse error: parse error, unexpected T_LOGICAL_OR in /home/hanime07/public_html/RPG/testing/logscript.php on line 17
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Aug 24th, 2005, 12:54 AM
#29
Thread Starter
Junior Member
Re: Php and MySQL help, please? :(
 Originally Posted by PlaGuE
Parse error: parse error, unexpected T_LOGICAL_OR in /home/hanime07/public_html/RPG/testing/logscript.php on line 17
This error is for the Logscript.php error on the other topic.
I dont see any error posted on the page of the above code, however, it doesn't update the database
-
Aug 25th, 2005, 01:23 AM
#30
Thread Starter
Junior Member
Re: Php and MySQL help, please? :(
Hey!
Sorry if Im bothering you or anything, but just wondering if anyone knows the problem with the script?
Thanks again for helping!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|