Code: Select all
<?php
$db = mysql_connect ("localhost", "chalks_learn", "mypass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("chalks_learn");
$sql = "CREATE TABLE IF NOT EXISTS login (userID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(userID), user varchar(15), pass varchar(15))";
mysql_query($sql, $db);
if (isset($_POST['user']) && isset($_POST['pass']))
{
echo mysql_query("DESCRIBE login", $db); //just checking to see if it exists
add();
}
function add()
{
$u = $_POST['user'];
$p = $_POST['pass'];
$sql = "INSERT INTO login (user, pass) VALUES ('$u', '$p')";
//I think my problem is either in the line above or below. Not sure.
if(!mysql_query($sql, $db))
die('Error: ' . mysql_error());
else
echo "It worked.";
}Error:".
I've used echos to make sure the data is formatting correctly (it is), and I've read the MySQL manual page on INSERT about fifty times, and googled, and searched this forum, and the mysql.com forums... I'm going crazy. I spent about 2 hours on this one bug, and I'm sure I'm just using the wrong keyword, but I can't for the life of me figure out what it is. I _know_ the table exists, and I _know_ the database exists. Also, I am positive that I have the correct connect statement. Rescue my sanity, please!
EDIT: my $db variable wasn't global. Heh.
Also EDIT: Don't you hate it when you ask for help after slaving over a problem for awhile, only to figure it out the INSTANT you ask?