Could someone debug some php for me plz
Ok, I was working on the CMS for other challenges, and realized that when it came to SQL I knew very little. My first script here worked, but is bare and doesn't prevent from inserting blank values:
<?php
$username=$_POST['username'];
$password=$_POST['password'];
$con = mysql_connect("localhost:phpmyadmin","censor","censor");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("slpctrl_users", $con);
mysql_query("INSERT INTO users (username, password)
VALUES ('$username', '$password')");
mysql_close($con);
?>
Now as I said, that works. But when I try to add a few extra things, I.E. disallowing blank fields and using addslashes to prevent a SQL injection here:
<?php
$con = mysql_connect("localhost:phpmyadmin","censor","censor");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if( isset( $_POST['username'] ) && isset( $_POST['password'] ) )
{
$password=addslashes($_POST['password']);
$username=addslashes($_POST['username']);
}
else
{
echo ("Username or Password not set");
}
mysql_select_db("slpctrl_users", $con);
mysql_query("INSERT INTO users (username, password)
VALUES ('$username', '$password')");
mysql_close($con);
?>
Anyone see an error I'm missing?
Alright, good shit. I was just wondering about 1 more question that I can't seem to find. Is it possible for me to count the number of columns, so that I can identify the column number with the order in which people 'register'? I.E. In the first column is my info….column 1. Or do I have to add another row for that? Btw mr cheese or any admin, don't accept my first CMS, I did a half assed job on it and tried to hurry through it but now I want to actually make a decent one with an interface :D