Running PHP 5 and while attempting to work with database MYSQL I get this error.
"Bad Request (Invalid URL)", the url that shows is http://192.168.1.249:8080/tests/<?=$_SERVER['PHP_SELF']?>" and I am running ISS6, global is off, and below is the code:

<?php

if (!isset($_POST['submit'])) {

?>

<form action="<?=$_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 {

$host = "localhost";
$user = "----";
$pass = "----";
$db = "testdb";


$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']);


$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

mysql_select_db($db) or die ("Unable to select database!");

$query = "INSERT INTO symbols (country, animal) VALUES ('$country', '$animal')";

$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

echo "New record inserted with ID ".mysql_insert_id();

mysql_close($connection);

}
?>

Any help would be appreciated.

    This is your problem, There is a equals sign there that shouldn't be there. Since its right next questionmark PHP does not start processing it.
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">

    Try this
    <form action="<? $_SERVER['PHP_SELF'] ?>" method="post">

      Nah, you're going to need to keep the = sign. Its php short hand for echo.

      Carl, that is odd, it really looks like a server configuration issue or something. Stupid question perhaps, but does a blank page with just <?php echo "test"; ?> work?

        Oh I know why. PHP.INI probably doesn't have short_tags on

          After trying different permutations the end result is that I had to add PHP to the tags because the short tags were off in my ini file. Thanks. Because I may someday distribute I will probably leave them off. Thanks very much. I understand much more now.

            Write a Reply...