Click to See Complete Forum and Search --> : MySQL the final frontier


grifter7
08-09-2009, 11:16 AM
I have set up a link between my Microsoft Access Database and myphpadmin server which i know works as i can see the changes being made between them... awesome. But i don't know how i can update my SQL database as no code i try works bearing in mind im trying to edit the server sql not access heres the code im trying very basic but it sdoesnt update and doenst give any error messages D: im really lost

<?php
$username="$_POST('username')";
$password="$_POST('password')";
$con = mysql_connect("localhost:3306","free","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("test",$con);

mysql_query("INSERT INTO accounts(ID, Username, Password, E-mail, Privileges) VALUES ('$auto', 'space', 'cake', 'spacial_cake@hotmail.com', 'Client')");
mysql_close($con);
?>

thraddash
08-09-2009, 11:52 AM
The value '$auto' you are using looks incorrect, PHP will try and translate that value to some internal PHP variable (which probably doesnt exist). Just be careful when using double-quoted strings!
Inserts also don't report errors :)

If ID is set as a primary key then you should not need to specify it during an insert, it should generate a new ID number automatically.

thraddash
08-09-2009, 12:50 PM
After looking again, the E-Mail field is also invalid as mySQL will treat the hyphen as an operator.
You will need to put ` characters around that column name (The quote next to the number 1).

INSERT INTO accounts (Username, Password, `E-mail`, Privileges) VALUES ('space', 'cake', 'spacial_cake@hotmail.com', 'Client')

It would be best if you could rename this field to something else like email or email_address.

grifter7
08-09-2009, 01:27 PM
thank you for the reply ive got it working now it accepts input woot :D.