0

I want to make a PHP form to capture a task and then allow the user to refresh the form to add another task. To keep track of the user, I planned to pass the variable with

<a href="http://mydomain.com/taskform.php?varname1=
myvalue">Continue</a>

and collect it on the next page taskform.php with

<?php

$varname = $_GET['myvalue'];

// other code 

?>

My problem is that I get the user's name and some other information from another .php form that links to the .php task form. The first time I link to the task form, I get a MySQL error because there's no task info being passed. So do I have to use a different form the first time through that only catches the user's name?

Let me know if you need clarification. It's probably obvious that I'm passing the user name value so that it doesn't have to be repeatedly entered for each task form submission. I'm assuming that the task name in each table row will be unique, if you're wondering how I plan to query them. As far as security, I was panning to cross that bridge later but if you have any security tips I'd be glad to hear them.

Thanks in advance.

4

1 回答 1

2

You can just use isset() to make sure the value is present. This will stop the error.

http://php.net/manual/en/function.isset.php

So you'll want something like:

$varname = isset($_GET['myvalue']) ? $_GET['myvalue'] : FALSE;

Which means if it's present you'll get the value, otherwise treat it as FALSE.

于 2012-12-16T19:49:34.427 回答