Jump to content

Date from form.

vorticalbox
Go to solution Solved by keja,

thanks but that doesn't explain why the same code doesn't work here but does somewhere else.

 

this code posts date correctly

if(isset($_POST['addsession'])){	// add username to $user	$user = $_SESSION['username'];	//add form data to variables	$location = $_POST['location'];	$date = $_POST['date'];	$time = $_POST['time'];		//if submitted data is empty	if ($location=='' || $date=='' || $time=='')	{		//display alert 		do_alert("All fields must be filled in");		//redirect to home page		redirect("../index.php");	}else	{		//insert data into database		$sql = "INSERT INTO sessions (createdby, location, date, time)		VALUES ('$user','$location', '$date', '$time')";				//if session as inserted into databe		if ($conn->query($sql) === TRUE) 		{			//display message			do_alert("Session created");			redirect("../index.php");				} else 		{			//diplay error			do_alert("Error could not connect to database");			redirect("../index.php");		}	}}

code is OP doesn't and i can't see for the life on my why, I have a number of forms that post a date and this is the only one that isn't working. I hate PHP sometimes

 

it works there because its treated like a string as you have single quotes wrapped around $date.

-snip-

I care mostly for wanting to know more -.- I hope to me building desktop/mobile apps but always good to have something to fall back on :P

 

never used classes in PHP, didn't even know you could do that.

 

few quests if you don't mind

":p" => hash("sha512", "salt?".$_POST["password"])

this part the salt? is that how you use it or just there in case i use salt?

 

also how would i go about inserting data into the database? something like this?

$adduser = db::query("INSERT into users username=:u && password=:p", array(    ":u" => $_POST["username"],    ":p" => $_POST["password"]));

how would i check that was successfully ran?

 

Thanks for the help ^_^

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

":p" => hash("sha512", "salt?".$_POST["password"])

this part the salt? is that how you use it or just there in case i use salt?

 

it was just a string/placeholder to show where to add the salt :)

 

 

also how would i go about inserting data into the database? something like this?

$adduser = db::query("INSERT into users username=:u && password=:p", array(    ":u" => $_POST["username"],    ":p" => $_POST["password"]));

how would i check that was successfully ran?

 

You would just check with a if statement :)

$adduser = db::query("INSERT INTO users SET username=:u, password=:p", array(    ":u" => $_POST["username"],    ":p" => $_POST["password"]));if($adduser){ echo ":)";}else{ echo ":(";}
Link to comment
Share on other sites

Link to post
Share on other sites

 

it was just a string/placeholder to show where to add the salt :)

 

 

 

You would just check with a if statement :)

$adduser = db::query("INSERT INTO users SET username=:u, password=:p", array(    ":u" => $_POST["username"],    ":p" => $_POST["password"]));if($adduser){ echo ":)";}else{ echo ":(";}

simple as that? lol thanks :) I will change my login script then and then if time permits work on the rest. Hoping the server at college can actually run this stuff good knows how old the software is on that thing.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

simple as that? lol thanks :) I will change my login script then and then if time permits work on the rest. Hoping the server at college can actually run this stuff good knows how old the software is on that thing.

Yup. i think it will work, PDO has been a part of php since 5.1 (released Nov 2005)

Link to comment
Share on other sites

Link to post
Share on other sites

Yup. i think it will work, PDO has been a part of php since 5.1 (released Nov 2005)

sever date is set to 2004 hopfully its from just having a dead battery lol one very last question, i have different levels of users and to do this i added a level table with the values 0-3.

 

is there an easy way to check this without doing another query?  

 

currently i have 

 

SQL to check u/p are correct

 

sql to pull level where u=u

 

if level = * then.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

sever date is set to 2004 hopfully its from just having a dead battery lol one very last question, i have different levels of users and to do this i added a level table with the values 0-3.

 

is there an easy way to check this without doing another query?  

 

currently i have 

 

SQL to check u/p are correct

 

sql to pull level where u=u

 

if level = * then.

 

not sure if i get your question, but cant you just do it with a if, if you already have the user information in a session ?

//i assume you have the session started somewhere else.//login part$login = db::query("SELECT level, username, ... FROM users ....", array(...));$_SESSION["user"] = $login->fetch(PDO::FETCH_ASSOC);//where you wanna check levelif($_SESSION["user"]["level"] > 1) {  echo "yea, your welcome here";}
Link to comment
Share on other sites

Link to post
Share on other sites

 

not sure if i get your question, but cant you just do it with a if, if you already have the user information in a session ?

//i assume you have the session started somewhere else.//login part$login = db::query("SELECT level, username, ... FROM users ....", array(...));$_SESSION["user"] = $login->fetch(PDO::FETCH_ASSOC);//where you wanna check levelif($_SESSION["user"]["level"] > 1) {  echo "yea, your welcome here";}

perfect thanks will give this a go. 

 

Edit: also one more question -.- sorry

 

in the login part how would i pull salt from the DB?

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

in the login part how would i pull salt from the DB?

 

depents, but you dont have to.

 

just make sure that you can recreate the salt from the login data alone.

if(isset($_POST["create_user"]){  if(db::query("INSERT INTO users (username, password) VALUES (:u, )", array(    ":u" => $_POST["username"],    ":p" => sha1("gdfg32fg".$_POST["username"]."342fgd3¤dgd/fdg".$_POST["password"]."hgf%¤2dsg")){    echo "welcome";  }else{    echo "failed to create user";}

just come up with something in the strings, and make sure they dont change, or if you dont want a static salt, you can make a function that generates one based on input arguments (username and password)

Link to comment
Share on other sites

Link to post
Share on other sites

depents, but you dont have to.

 

just make sure that you can recreate the salt from the login data alone.

if(isset($_POST["create_user"]){  if(db::query("INSERT INTO users (username, password) VALUES (:u, )", array(    ":u" => $_POST["username"],    ":p" => sha1("gdfg32fg".$_POST["username"]."342fgd3¤dgd/fdg".$_POST["password"]."hgf%¤2dsg")){    echo "welcome";  }else{    echo "failed to create user";}

just come up with something in the strings, and make sure they dont change, or if you dont want a static salt, you can make a function that generates one based on input arguments (username and password)

 

ok thanks for all the help

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

ok thanks for all the help

no prob, and remember to use the same strings when you wanna login 

$login = db::query("SELECT * FROM users WHERE username=:u && password=:p", array(    ":u" => $_POST["username"],    ":p" => sha1("gdfg32fg".$_POST["username"]."342fgd3¤dgd/fdg".$_POST["password"]."hgf%¤2dsg"));
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×