goodthenks — 2012-11-26T04:22:30-05:00 — #1
The error is "No database selected". However, there is nothing wrong with the name because the database "forms" exists. When I use the "test" database on phpMyAdmin, it works fine but it doesn't work on an identical database of a different name. I say it is identical because I copied the database in phpyMyAdmin so I could be mistaken.
Here is my code:
$con = mysql_connect("localhost");
die('Could not connect: ' . mysql_error());
$sql="INSERT INTO form_results (Name, Email, Subject, Message)
die('Error: ' . mysql_error());
echo "<p>Your record has been successfully added to the database.</p>";
frank1 — 2012-11-26T05:37:46-05:00 — #2
you would need username and password...and whats about using the short method
plus do sanitize those get. Googling 'sql injection' might help.
My personal suggestion dont try to start learning php as poetry rather first read other how they write it,that would help.(just a suggestion)
goodthenks — 2012-11-26T08:22:36-05:00 — #3
Thanks that worked but I don't want to put the password in plain text inside the document. I think that's quite insecure and I wouldn't think that is normal behaviour.
kylewolfe — 2012-11-26T10:38:44-05:00 — #4
This is actually common practice. You're not supposed to have files such as these in the document root where they can be read by users. if your document root is /var/www/mysite/public, then you would want any php files with sensitive data stored somewhere such as /var/www/mysite/lib.