I am new to PHP and having a problem that I cannot find an answer to. When submitting a form and using $_SERVER['PHP_SELF'] for example, http://www.edgdwcs3.com/workfiles/ch14/feedback.php, the URL returned is http://www.edgdwcs3.com/workfiles/ch14/feedback.php/workfiles/ch14/feedback.php? . When I run a phpinfo(); in a file named info.php the PHP variables section shows _SERVER["PHP_SELF"]=/info.php/info.php. Does anyone know if this is normal and I'm missing something or am I doing something, or have something configured, wrong?
Thanks in advance,
gymBob
Bad URL returned by PHP
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Bad URL returned by PHP
Show your code and maybe someone will have more of a chance to determine what's going on.
Re: Bad URL returned by PHP
Here is the code, i'm kinda new to forums and i'm not sure how much code to post so i posted it all.
Code: Select all
<?php require_once('../../Connections/connAdmin.php'); ?>
<?php
// if form has been submitted, convert $_POST subarrays to strings
if (array_key_exists('send', $_POST)) {
if (isset($_POST['interests'])) {
$_POST['interests'] = implode(',', $_POST['interests']);
}
else {
$_POST['interests'] = '';
}
if (isset($_POST['views'])) {
$_POST['views'] = implode(',', $_POST['views']);
}
else {
$_POST['views'] = '';
}
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO feedback (name, email, comments, interests, visited, views, subscribe) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['comments'], "text"),
GetSQLValueString($_POST['interests'], "text"),
GetSQLValueString($_POST['visited'], "text"),
GetSQLValueString($_POST['views'], "text"),
GetSQLValueString($_POST['subscribe'], "text"));
mysql_select_db($database_connAdmin, $connAdmin);
$Result1 = mysql_query($insertSQL, $connAdmin) or die(mysql_error());
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact form</title>
<link href="../styles/contact.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Contact Us</h1>
<p>We welcome feedback from visitors to our site. Please use the following form to let us know what you think about it.</p>
<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1">
<fieldset>
<legend>Your details</legend>
<p>
<label for="name">Name: <?php
if (isset($missing) && in_array('name', $missing)) { ?>
<span class="warning">Please enter your name</span><?php } ?>
</label>
<input name="name" type="text" class="textInput" id="name"
<?php if (isset($missing)) {
echo 'value="'.htmlentities($_POST['name']).'"';
} ?>
/>
</p>
<p>
<label for="email">Email:</label>
<input name="email" type="text" class="textInput" id="email"
<?php if (isset($missing)) {
echo 'value="'.htmlentities($_POST['email']).'"';
} ?>
/>
</p>
</fieldset>
<fieldset>
<legend>Your views</legend>
<p>
<label for="comments">Comments: <?php
if (isset($missing) && in_array('comments', $missing)) { ?>
<span class="warning">Please enter your comments</span><?php } ?>
</label>
<textarea name="comments" id="comments" cols="45" rows="5"><?php if (isset($missing)) {
echo htmlentities($_POST['comments']);
} ?></textarea>
</p>
<p><strong>What aspects of London most interest you?</strong></p>
<div class="chkRad">
<p>
<input type="checkbox" name="interests[]" id="interests-classical" value="Classical concerts"
<?php
$OK = isset($_POST['interests']) ? true : false;
if ($OK && isset($missing) && in_array('Classical concerts', $_POST['interests'])) {
echo 'checked="checked"';
} ?>
/>
<label for="interests-classical">Classical concerts</label>
</p>
<p>
<input name="interests[]" type="checkbox" id="interests-rock" value="Rock/pop"
<?php
if ($OK && isset($missing) && in_array('Rock/pop', $_POST['interests'])) {
echo 'checked="checked"';
} ?>
/>
<label for="interests-rock">Rock/pop events</label>
</p>
<p>
<input name="interests[]" type="checkbox" id="interests-drama" value="Drama"
<?php
if ($OK && isset($missing) && in_array('Drama', $_POST['interests'])) {
echo 'checked="checked"';
} ?>
/>
<label for="interests-drama">Drama</label>
</p>
</div>
<div class="chkRad">
<p>
<input name="interests[]" type="checkbox" id="interests-walks" value="Guided walks"
<?php
if ($OK && isset($missing) && in_array('Guided walks', $_POST['interests'])) {
echo 'checked="checked"';
} ?>
/>
<label for="interests-walks">Guided walks</label>
</p>
<p>
<input name="interests[]" type="checkbox" id="interests-art" value="Art"
<?php
if ($OK && isset($missing) && in_array('Art', $_POST['interests'])) {
echo 'checked="checked"';
} ?>
/>
<label for="interests-art">Art</label>
</p>
</div>
<p class="clearIt">
<label for="visited">How often have you been to London? <?php
if (isset($missing) && in_array('visited', $missing)) { ?>
<span class="warning">Please select a value</span><?php } ?></label>
<select name="visited" id="visited">
<option value="0"
<?php
if (!$_POST || $_POST['visited'] == '0') {
echo 'selected="selected"';
} ?>
>-- Select one --</option>
<option value="Never"
<?php
if (isset($missing) && $_POST['visited'] == 'Never') {
echo 'selected="selected"';
} ?>
>Never been</option>
<option value="1-2 times"
<?php
if (isset($missing) && $_POST['visited'] == '1-2 times') {
echo 'selected="selected"';
} ?>
>Once or twice</option>
<option value="Not yearly"
<?php
if (isset($missing) && $_POST['visited'] == 'Not yearly') {
echo 'selected="selected"';
} ?>
>Less than once a year</option>
<option value="Yearly"
<?php
if (isset($missing) && $_POST['visited'] == 'Yearly') {
echo 'selected="selected"';
} ?>
>I go most years</option>
<option value="Live/work"
<?php
if (isset($missing) && $_POST['visited'] == 'Live/work') {
echo 'selected="selected"';
} ?>
>I live/work there</option>
</select>
</p>
<p>
<label for="views">What image do you have of London?</label>
<select name="views[]" size="6" multiple="multiple" id="views">
<option value="Vibrant/exciting"
<?php
$OK = isset($_POST['views']) ? true : false;
if ($OK && isset($missing) && in_array('Vibrant/exciting', $_POST['views'])) {
echo 'selected="selected"';
} ?>
>A vibrant, exciting city</option>
<option value="Good food"
<?php
if ($OK && isset($missing) && in_array('Good food', $_POST['views'])) {
echo 'selected="selected"';
} ?>
>A great place to eat</option>
<option value="Good transport"
<?php
if ($OK && isset($missing) && in_array('Good transport', $_POST['views'])) {
echo 'selected="selected"';
} ?>
>Convenient transport</option>
<option value="Dull"
<?php
if ($OK && isset($missing) && in_array('Dull', $_POST['views'])) {
echo 'selected="selected"';
} ?>
>Dull, dull, dull</option>
<option value="Bad food"
<?php
if ($OK && isset($missing) && in_array('Bad food', $_POST['views'])) {
echo 'selected="selected"';
} ?>
>The food's rotten</option>
<option value="Transport nightmare"
<?php
if ($OK && isset($missing) && in_array('Transport nightmare', $_POST['views'])) {
echo 'selected="selected"';
} ?>
>A transport nightmare</option>
</select>
</p>
<p><strong>Would you like to receive regular details of events in London?</strong></p>
<div class="chkRad">
<p>
<input type="radio" name="subscribe" id="subscribe-yes" value="y"
<?php
if (isset($missing) && $_POST['subscribe'] == 'y') {
echo 'checked="checked"';
} ?>
/>
<label for="subscribe-yes">Yes</label>
<input name="subscribe" type="radio" id="subscribe-no" value="n"
<?php
if (!isset($missing) || isset($missing) && $_POST['subscribe'] == 'n') {
echo 'checked="checked"';
} ?>
/>
<label for="subscribe-no">No</label>
</p>
</div>
<p> </p>
<p class="clearIt">
<input type="submit" name="send" id="send" value="Send comments" />
</p>
</fieldset>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>
Last edited by Weirdan on Mon Jun 09, 2008 4:36 pm, edited 1 time in total.
Reason: php tags
Reason: php tags
Re: Bad URL returned by PHP
I didn't really read through your code, but it sounds like you are forgetting to write 'http://' at the beginning of the url, causing the browser to add the original base path.
Re: Bad URL returned by PHP
As has been mentioned a million times in the forum. Use Code or PHP BBcode tags when posting your code.