Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

Session name into database...

Hello all. . .

I have a login system.

I want the users to be able to click a curtain "radio" and then update the database with the users "username" (sessionname).

I use foreach to get both first and last name:
foreach($_SESSION as $key => $value) {
    echo  'Current session variable ' . $key . ' is: ' . $value . '<br />';
}

Open in new window


But if i use $value in a "radio", it will only take the first name and put it into the database:
<td><input type="radio" name ="ny_c10" value = $value ></td>

Open in new window


if(isset($_POST['ansat_kiosk_opdater'])){
$UpdateQuery = "UPDATE ansat_kiosk SET c8='$_POST[ny_c8]', c9='$_POST[ny_c9]', c10='$_POST[ny_c10]'  WHERE ID='$_POST[ID]'";
mysqli_query($link, $UpdateQuery);
};

Open in new window


How can i put both first and last name into the "c10"?
0
Mike Kristensen
Asked:
Mike Kristensen
  • 4
  • 2
1 Solution
 
Mike KristensenIT administratorAuthor Commented:
Oki seemed to fix this in another way......

Instead of "radio" i just made a "update" for each "input type=text", using a "submit".

if(isset($_POST['overtag_c12'])){
$UpdateQuery = "UPDATE ansat_kiosk SET c12='$value' WHERE ID='$_POST[ID]'";
mysqli_query($link, $UpdateQuery);
};

Open in new window


<td><input type="submit" name="overtag_c12" value="Overtag" /> </td>

Open in new window


This not just Works, it will also Work better..... Funny how you often figure Things out as soon you ask someone... (sometimes :))
0
 
Ray PaseurCommented:
This query is almost certain to get your data base destroyed some day

UPDATE ansat_kiosk SET c12='$value' WHERE ID='$_POST[ID]'

It is axiomatic that you must use valid PHP code and you must sanitize your variables before you use them in a query. These articles will help you understand why you want to use quotes around array index names and why you want to avoid using external variables in a query.

Quotes:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12241-Quotation-Marks-in-PHP.html

See Antipractice #18
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12293-AntiPHPatterns-and-AntiPHPractices.html

PHP Security and External Variables:
http://php.net/tut.php
http://php.net/manual/en/tutorial.forms.php
http://php.net/manual/en/language.variables.external.php
http://php.net/manual/en/security.php
0
 
Mike KristensenIT administratorAuthor Commented:
Global and external variables is that the same?

And where I found array index names? Im just not sure what you are talking about, and so its hard to understand what you are trying to tell me :P


UPDATE ansat_kiosk SET c12='$value' WHERE ID='$_POST[ID]'


Do you want me to use double quotes around $value? That is the only thing I seem to understand from your article that im missing?


And for you I explain how I understand it :D
single quotes does not allow more than 1 word? Also called substitution?
Double quotes allows substitution. Again this would be 2 words separated?

I can store a value with more words using single quotes, but i'm not allowed to use it with single quotes? (Still this seems to work, so I might not understand).
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Ray PaseurCommented:
Maybe I assumed too much.  You probably want to step back from this specific application and take some time to get a foundation in how HTML, PHP, Databases work.  This article can help with that part of the background understanding.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

I'll try to explain a bit more of this, but seeing the questions here it tells me that you would be much better off hiring a professional programmer.  It's going to take you too long to get this done by trial and error, and the resulting system is going to be riddled with security flaws.  Better safe than sorry!
Global and external variables is that the same?
These terms have different meanings, but they are related.  PHP global variables exist in every scope and namespace.
http://php.net/language.variables.scope.php

There is also the concept of super-global variables.  External request data from the HTML form is presented to the PHP script in $_GET or $_POST.
http://php.net/language.variables.superglobals.php
And where I found array index names?
There is a 1:1 relationship between the name= attribute in the HTML form input control and the array key in the superglobal request array.
http://php.net/manual/en/tutorial.forms.php

PHP array keys should be quoted.  This is wrong:
$_POST[ID]

Open in new window

and this is right:
$_POST['ID']

Open in new window

 The difference is explained here.  For better or worse, PHP has a very complicated and confusing way of dealing with quotes.  It requires great attention to detail.

HTML has rules about how to express information in forms.  This is wrong:
<td><input type="radio" name ="ny_c10" value = $value ></td>

Open in new window

This is right if you're inside a PHP HEREDOC block:
<td><input type="radio" name="ny_c10" value="$value" /></td>

Open in new window

This is right if you're not inside a HEREDOC, but instead are intermixing HTML with PHP:
<td><input type="radio" name="ny_c10" value="<?php echo $value;" /></td>

Open in new window

PHP has different meanings for single and double quotes.  Please read the article about quotes that I linked above.  Executive summary: Double quotes allow variable substitution inside the quote strings.

This statement is dangerous because it will send external data to the SQL engine without any checks on the content of the external data.  Consider what would happen to your data base if a hacker sent a POST request with ID=1 OR 1=1.  The query would match every row of the data base table.
UPDATE ansat_kiosk SET c12='$value' WHERE ID='$_POST[ID]'

Open in new window


A more sensible idea would be to cast the contents of $_POST['ID'] to be sure that it is an integer, and use a LIMIT clause to reduce the risk of wholesale damage.  PHP Example:
$id = (int)$_POST['id'];
$sql = "UPDATE ansat_kiosk SET c12='$value' WHERE ID=$id LIMIT 1";

Open in new window

I know there is a lot to learn here, and it takes time plus structured education and exercise.  Hopefully the "new to PHP" article can get you on the right path.  Best of luck with it, ~Ray
0
 
Mike KristensenIT administratorAuthor Commented:
Be sure to understand the above before using it :=)
0
 
Mike KristensenIT administratorAuthor Commented:
Starter course PHP today.... Going to be great. :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now