This topic is locked
[SOLVED]

 Quiz Template

9/13/2019 12:19:50 AM
PHPRunner General questions
A
aeaton2017 author

I have the quiz template and it works great, but I need to add username to the quiz_reponse table which I add a called username. Here is the before display code
// insert new response

$tblResponse = $dal->Table("quiz_responses");

$tblResponse->Value["testid"]=$_SESSION["testid"];

$tblResponse->Value["startTest"]=runner_date_format("Y-m-d H:i:s");

$tblResponse->Value["username"]=$_SESSION["UserName"];

$tblResponse->Add()
I get no error but when I look at the database I get 0 in the field.
What I am missing?

Tandy 9/13/2019



I have the quiz template and it works great, but I need to add username to the quiz_reponse table which I add a called username. Here is the before display code
// insert new response

$tblResponse = $dal->Table("quiz_responses");

$tblResponse->Value["testid"]=$_SESSION["testid"];

$tblResponse->Value["startTest"]=runner_date_format("Y-m-d H:i:s");

$tblResponse->Value["username"]=$_SESSION["UserName"];

$tblResponse->Add()
I get no error but when I look at the database I get 0 in the field.
What I am missing?



Question. Did you put it as a username as a session?

In events - Login Page - After successful login:

$_SESSION["username"] = $data["username"];

A
aeaton2017 author 9/13/2019



Question. Did you put it as a username as a session?

In events - Login Page - After successful login:

$_SESSION["username"] = $data["username"];


No have not, so i added it and it still gives 0
Here is what I added
{
$_SESSION["username"] = $data["username"];
}
//** Redirect to another page **** Customize this page with employee settings for Sites Dashboard. ***

if ($_SESSION["GroupID"] == 2) {
header("Location: Dashboard_dashboard.php");

exit();
} elseif ($_SESSION["GroupID"] == -1) {
header("Location: Dashboard_Site_dashboard.php");
} elseif ($_SESSION["GroupID"] == -2) {
header("Location: AircraftList_list.php");
} elseif ($_SESSION["GroupID"] == -3) {
header("Location: Dashboard_GSE_dashboard.php");

} elseif ($_SESSION["GroupID"] == -4) {
header("Location: Dashboard_Site_OverSeas_dashboard.php");

exit();
} else
header("Location: menu.php");

exit();
// insert new response

$tblResponse = $dal->Table("quiz_responses");

$tblResponse->Value["testid"]=$_SESSION["testid"];

$tblResponse->Value["startTest"]=runner_date_format("Y-m-d H:i:s");

$tblResponse->Value["username"]=$_SESSION["username"];

$tblResponse->Add()

A
aeaton2017 author 9/13/2019

So I was testing to see if my sessions were working and they are by adding a snippet to a page
echo "User: " . $_SESSION["username"];

N
Nir Frumer 9/13/2019

is quiz_responses.username has a data type that permits storing $_SESSION['USERNAME'] ?

A
aeaton2017 author 9/13/2019



is quiz_responses.username has a data type that permits storing $_SESSION['USERNAME'] ?


Yes, so I get a SQL syntax error for this
SQL syntax update quiz_responses set score=2, points=2 ,username=Aaron Easton where id=49

near username. So this is where I am getting stuck on..
This is the code that is causing this error.
CustomQuery("update ".AddTableWrappers("quiz_responses")." set ".AddFieldWrappers("score")."=".$right_answers.", ".AddFieldWrappers("points")."=".$points."

,".AddFieldWrappers("username")."=".$_SESSION['username']."

where ".AddFieldWrappers("id")."=".$_SESSION["responseid"]);

Sergey Kornilov admin 9/13/2019

Your SQL query misses single quotes around text value Aaron Easton. Should be 'Aaron Easton'.
My suggestion is to use the Database API that will take care of things like this for you:

https://xlinesoft.com/phprunner/docs/db_update.htm

A
aeaton2017 author 9/13/2019



Your SQL query misses single quotes around text value Aaron Easton. Should be 'Aaron Easton'.
My suggestion is to use the Database API that will take care of things like this for you:

https://xlinesoft.com/phprunner/docs/db_update.htm


I figure it out.. Thanks for helping
Here is the correct code:
CustomQuery("update ".AddTableWrappers("quiz_responses")." set ".AddFieldWrappers("score")."=".$right_answers.", ".AddFieldWrappers("points")."=".$points."

,".AddFieldWrappers("userid")."='".$_SESSION['username']."'

where ".AddFieldWrappers("id")."=".$_SESSION["responseid"]);

}