i'm trying to transmit a textbox value to a function using the $_GET method and then adding it to an mysql database via query. I've searched multiple similar questions and edited my previous attempts accordingly but happen to not find the error in my current code. The file is database.php on which i want to add a value to a mysql database on button click. I suspect the error to be in the if($_GET) clause as an echo for $ep in the function or even in the if-part does not return anything and as such, only an empty entry with its UID is added into the database no matter what i input into the textfield before hitting the "Insert EP" button. Maybe im just missing or fail to see something trivial.
<title> Database </title>
<body>
<form action="database.php">
<input type="text" name="setEp" id="ep" value="" />
<input type="submit" class="button" name="setEp" value="Insert EP" />
</form>
</body>
<?php
//Getting the content of the textbox
if($_GET){
if(isset($_GET['setEp'])){
$ep = isset($_GET['ep']);
setEp($ep); //calling the desired function with the retrieved variable
}
}
//The function declaration
function setEp($ep){
//DB connection
$db_host = "127.0.0.1:6543";
$db_username = "root";
$db_pass = "root";
$db_name = "endpoints";
$conn = mysql_connect("$db_host","$db_username","$db_pass") or die ("Could not connect to MySQL");
//Table "enpoint" consists only of names and autoincrement UID
$ep = mysql_real_escape_string($ep);
$query = "INSERT INTO endpoint (name) VALUES ('$ep')";
mysql_query($query);
echo " SetEP called"; //echo function to see if it was called
echo "$ep"; // this will never create an input no matter what i did
?>