Click to See Complete Forum and Search --> : Newbie php addind data to mysql
Pino
Apr 27th, 2004, 02:04 PM
ok i first tried this.....
<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....
<?
$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
NoteMe
Apr 27th, 2004, 02:40 PM
Try to change the insert line to:
$query = mysql_query("INSERT INTO info VALUES('$username','$password')");
BTW what is the error message?
Is there only two fields in that table?
CornedBee
Apr 27th, 2004, 02:45 PM
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.
Pino
Apr 27th, 2004, 02:49 PM
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 :)
CornedBee
Apr 27th, 2004, 02:53 PM
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")
NoteMe
Apr 27th, 2004, 02:58 PM
Looks werid...if there is a password or something on the database try to connect to it like this:
@ $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");
Forget about this: Listen to the man that know this...:D..
Pino
Apr 27th, 2004, 03:06 PM
how would i incorperate that into my problem? sorry for i'm still learning :)
Electroman
Apr 27th, 2004, 03:33 PM
Posted by NoteMe
mysql_error(); Ar so thats how you find out what went wrong in a DB call :D. I've been wondering how to find that out, suppose mysql_error() does kinda make sense :rolleyes:. :D
Pino
Apr 27th, 2004, 03:37 PM
where do i put the post thing? im confused please help me!
CornedBee
Apr 27th, 2004, 03:43 PM
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 :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.