|
-
Apr 27th, 2004, 02:04 PM
#1
Thread Starter
PowerPoster
Newbie php addind data to mysql
ok i first tried this.....
Code:
<form action="insert.php" method="post">
UserName: <input type="text" name="username"><br>
Password: <input type="text" name="password"><br>
<input type="Submit">
</form>
and in insert.php....
PHP Code:
<?
$database="users";
mysql_connect() or die ("Problem connecting to DataBase");
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO info VALUES ('$username','$password')";
mysql_query($query);
mysql_close();
?>
i've been looking at these global varible things but they still not making sence to me can anyone tell em how to solve this? all iw ant to do is add data to mysql
-
Apr 27th, 2004, 02:40 PM
#2
Try to change the insert line to:
Code:
$query = mysql_query("INSERT INTO info VALUES('$username','$password')");
BTW what is the error message?
Is there only two fields in that table?
-
Apr 27th, 2004, 02:45 PM
#3
You should also make the password input of type password (makes the stars show).
Oh, and I scan the forums almost daily, there's no need to PM me.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 27th, 2004, 02:49 PM
#4
Thread Starter
PowerPoster
Notice: Undefined variable: username in (document path)insert.php on line 11
Notice: Undefined variable: password in (document path)insert.php on line 11
thanks
sry botut th epm its just i've been trying for nerly 5 days to learn
-
Apr 27th, 2004, 02:53 PM
#5
You're trying to use the deprecated (for security reasons) and by default disabled feature of PHP to offer all passed data as global variables. As of new PHP versions, you can access the data with
$_GET['fieldname'] (if the form has method="get")
and
$_POST['fieldname'] (if the form has method="post")
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 27th, 2004, 02:58 PM
#6
Looks werid...if there is a password or something on the database try to connect to it like this:
PHP Code:
@ $db = mysql_pconnect ("localhost", "name_of_the_user", "password_to_the_database");
if (!$db){
echo 'I cannot connect to the database because: ' . mysql_error();
exit;
}
mysql_select_db ("name_of_the_database");
[Edit]Forget about this: Listen to the man that know this... ..[/Edit]
-
Apr 27th, 2004, 03:06 PM
#7
Thread Starter
PowerPoster
how would i incorperate that into my problem? sorry for i'm still learning
-
Apr 27th, 2004, 03:33 PM
#8
Ex-Super Mod'rater
Ar so thats how you find out what went wrong in a DB call . I've been wondering how to find that out, suppose mysql_error() does kinda make sense .
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Apr 27th, 2004, 03:37 PM
#9
Thread Starter
PowerPoster
where do i put the post thing? im confused please help me!
-
Apr 27th, 2004, 03:43 PM
#10
Rewrite the $query = line like this:
$query = "INSERT INTO info VALUES ('".$_POST['username']."','".$_POST['password']."')";
It's possible to do it without concatenating strings, but in case of arrays I don't like doing this for several reasons, one of which is that it breaks the syntax highlighting of jEdit
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
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
|