MyBB Community Forums

Full Version: Help me? PHP/MySQL Trouble!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
And no, it's not for myBB, which is my it's posted here. I'm making a little script, and I'm getting a T_Variable error for these lines:

$query = "insert into phpbase.login 
		(email, username, password, lastaccess, signup, themeID) 
		values('$email', '$username', '$passcrypt', '$now', '$now', '$themeID')";
$result = mysql_query($query);

Can anyone shed some light on that?
Not sure if this will make a difference but this is how I would usually code it:

$query = "INSERT INTO `phpbase.login` 
        (`email`, `username`, `password`, `lastaccess`, `signup`, `themeID`) 
        VALUES ('$email', '$username', '$passcrypt', '$now', '$now', '$themeID')";
$result = mysql_query($query) or die(mysql_error());
Try adding some addslashes() to $email, $username, ect...
Well that would help security wise, although that wouldn't be giving him this error!
Umm.. His input might have some quotes that are messing the query up. Wink
Would not give him a T VARIABLE error though.
Please past the 5 previous lines before those lines too - it could be a problem with them.
function signup($email, $username, $password, $themeID) {
         $server = "localhost";	// server to connect to.
         $database = "ptn_phpbase";	// the name of the database.
         $db_username = "ptn_php";	// mysql username to access the database with.
         $password = "****";	// mysql password to access the database with.
         $table = "users";		// the table that this script will set up and use.         
         $link = mysql_connect($server, $db_username, $password) // connect to the mysql server
         or die ("Could not connect to mysql because ".mysql_error());         
         mysql_select_db($database) // select the database
         or die ("Could not select database because ".mysql_error());
				    $passcrypt = crypt($password);
						$now = date("Y-m-d");
						$query = "insert into login 
							 (email, username, password, lastaccess, signup, themeID) values('$email', '$username', '$passcrypt', '$now', '$now', '$themeID')";
						$result = mysql_query($query);
						mysql_close();
						return $result;
				}


Well, hope that helps. It's the full function.
Copernicus Wrote:Would not give him a T VARIABLE error though.
Your totaly right..hehe I don't know what I was thinkin'. Smile

* Christian was in another mode Big Grin
Missing a couple of ;'s there. Smile
function signup($email, $username, $password, $themeID) {
         $server = "localhost";    // server to connect to.
         $database = "ptn_phpbase";    // the name of the database.
         $db_username = "ptn_php";    // mysql username to access the database with.
         $password = "****";    // mysql password to access the database with.
         $table = "users";        // the table that this script will set up and use.         
         $link = mysql_connect($server, $db_username, $password)[color=red];[/color] // connect to the mysql server
         or die ("Could not connect to mysql because ".mysql_error());         
         mysql_select_db($database)[color=red];[/color] // select the database
         or die ("Could not select database because ".mysql_error());
                    $passcrypt = crypt($password);
                        $now = date("Y-m-d");
                        $query = "insert into login 
                             (email, username, password, lastaccess, signup, themeID) values('$email', '$username', '$passcrypt', '$now', '$now', '$themeID')";
                        $result = mysql_query($query);
                        mysql_close();
                        return $result;
                }
Pages: 1 2