Quick PHP Question

Hi,

Ok so my knowledge of PHP is only small, still learning.

So basically, I want to grab values from a URL, so for example:
www.example.com/new.php?username=“test”

I want to grab the username TEST from the URL and insert it into the database. This is just an example. Using prepared statements and an example from W3Schools, this will be the PHP code:

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDBPDO";

try {
  $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  // set the PDO error mode to exception
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  // prepare sql and bind parameters
  $stmt = $conn->prepare("INSERT INTO MyGuests (username)
  VALUES (:username)");
  $stmt->bindParam(':username', $username);

  // insert a row
  $firstname = "John"; //THIS IS WHERE I WANT THE TEST USERNAME TO GO FROM THE URL
  $stmt->execute();

  echo "New records created successfully";
} catch(PDOException $e) {
  echo "Error: " . $e->getMessage();
}
$conn = null;
?>

I have tried using $_GET[‘’] but it just isn’t having it. Any ideas would be greatly appreciated :slight_smile: :slight_smile: this is making me mad xD

Stay safe

try doing this at the start of the script and seeing the result.

$RobloxUsername = $_GET["username"];
echo($RobloxUsername);

Php is extremely weird and annoying to work with, espcially with SQL and LUA it gets messy quick.

1 Like

No offense but does this relate to Roblox at all?

People here ask questions about Roblox Lua and Lua questions because it has similarities with Roblox Lua not PHP, why are you asking a PHP question here?

You will not get any good answers because people here use Roblox Lua and Lua and this forum is intended for Roblox games not outside of Roblox.

if your question is related to Roblox in someway like using HttpService to get information from your website then I’d say that you can ask this here but I don’t think it is because you’ve never mentioned that in this thread.

Sorry, yes it does. I am using it for a project involving Lua, PHP and MySQL to store data.

2 Likes

Yeah it prints it, thank you.

Does it matter if it has ’ or "?

I assume it does, but I’m not exactly sure because PHP is such a pain to work with. I assume that PHP uses "" to index data from arrays so I guess it matters.

Also if that’s all the questions you have about PHP you should mark this thread as resolved.

1 Like

Thank you,

I thought Lua was bad but working with PHP is really something else.

1 Like