I'm trying to run an Insert query on mysql with php. I get the Error 403 Access forbidden!
Checking the error log, I get the following
- Code: Select all
(20024)The given path is misformatted or contained invalid characters: Cannot map POST /%3Cphp?=$_SERVER[%27PHP_SELF%27]?%3E HTTP/1.1 to file
What am I doing wrong?
I'm pretty new at this and I'm trying for follow an online tutorial. I simply copied what was given.
Php code:
- Code: Select all
<html>
<head>
<basefont face="Arial">
</head>
<body>
<?php
if (!isset($_POST['submit'])) {
// form not submitted
?>
<form action="<php?=$_SERVER['PHP_SELF']?>" method="post">
Country: <input type="text" name="country">
National animal: <input type="text" name="animal">
<input type="submit" name="submit">
</form>
<?php
}
else {
// form submitted
// set server access variables
$host = "localhost";
$user = "superuser";
$pass = "mypw";
$db = "mydb";
// get form input
// check to make sure it's all there
// escape input values for greater safety
$country = empty($_POST['country']) ? die ("ERROR: Enter a country") : mysql_escape_string($_POST['country']);
$animal = empty($_POST['animal']) ? die ("ERROR: Enter an animal") : mysql_escape_string($_POST['animal']);
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// create query
$query = "INSERT INTO symbols (country, animal) VALUES ('$country', '$animal')";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// print message with ID of inserted record
echo "New record inserted with ID ".mysql_insert_id();
// close connection
mysql_close($connection);
}
?>
</body>
</html>
Thanks for your help!