php-general Digest 1 Oct 2012 04:32:17 - Issue 7988
Topics (messages 319302 through 319303):
Re: relative url and path_info
319302 by: Maciek Sokolewicz
php can't insert data mysql table
319303 by: Tim Dunphy
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
--
---BeginMessage---
On 30-09-2012 14:21, Tom Sparks wrote:
I have created a php script that use $_SERVER['PATH_INFO'], for the different
sub-sections
the links now looks like this
http://localhost/collection/popups.php/models/bttf/car01/
my web browser cant load my images/javascripts/etc because it is trying to use
relative url from http://localhost/collection/popups.php/models/bttf/car01/*
witch is incorrect, but the browser gets a 200 (ok) message from the server
my images/javascripst/etc is relative to http://localhost/collection/*
but my requirement dictate relative url only because I may move the folder
later to a new location
what are my options?
---
tom_a_sparks It's a nerdy thing I like to do
I don't know where you store your images, scripts, etc. but I would
hazard in a different dir. What you could do is check if the path
request you recieve includes those dirs. If so, send a permanent
redirect to the browser with the correct url. Ie. an error 301 Moved
Permanently.
Alternatively, what I prefer. Is to have your paths stored in a
variable, and to simply output that variable's contents as the
base-path. This way, you can still show things relative to that
base-path, and when you move the folder, you only need to update that
one variable (which should be in a config file somewhere).
In other words:
instead of saying go to /absolute/path/to/foo/images/whatever.jpg or
./images/whatever.jpg you do a:
$BASE_PATH = '/absolute/oath/to/foo';
echo $BASE_PATH . '/images/whatever.jpg';
In other words, you're combining the power of relative paths with that
of absolute ones.
- Tul
---End Message---
---BeginMessage---
Hello list,
I'm trying to learn and get comfortable with HTML forms in PHP. In one
example I am trying to include a file upload in one of the forms. I can
connect to the database but for some reason the MySQL query string is bad.
I've been over this for a while now and I think the problem is with the
form. I was hoping to get the esteemed opinion of the list in where I may
be going wrong.
This code:
!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; xml:lang=en lang=en
head
meta http-equiv=Content-Type content=text/html; charset=utf-8 /
titleGuitar Wars - Add Your High Score/title
link rel=stylesheet type=text/css href=style.css /
/head
body
h2Guitar Wars - Add Your High Score/h2
?php
if (isset($_POST['submit'])) {
// Grab the score data from the POST
$name = $_POST['name'];
$score = $_POST['score'];
$screenshot = $_FILES['screenshot']['name'];
if (!empty($name) !empty($score)) {
// Connect to the database
$dbc = mysqli_connect('localhost', 'admin', 'secretsauce', 'gwdb')
or die('Cannot connect to database');
// Write the data to the database
$query = INSERT INTO guitarwars VALUES (0, NOW(), '$name', '$score',
'$screenshot');
mysqli_query($dbc, $query)
or die('Cannot insert query');
// Confirm success with the user
echo 'pThanks for adding your new high score!/p';
echo 'pstrongName:/strong ' . $name . 'br /';
echo 'strongScore:/strong ' . $score . '/p';
echo 'pa href=index.phplt;lt; Back to high scores/a/p';
// Clear the score data to clear the form
$name = ;
$score = ;
mysqli_close($dbc);
}
else {
echo 'p class=errorPlease enter all of the information to add
your high score./p';
}
}
?
hr /
form enctype=multipart/form-data method=post action=?php echo
$_SERVER['PHP_SELF']; ?
input type=hidden name=MAX_FILE_SIZE value=32768 /
label for=nameName:/label
input type=text id=name name=name value=?php if
(!empty($name)) echo $name; ? /br /
label for=scoreScore:/label
input type=text id=score name=score value=?php if
(!empty($score)) echo $score; ? /
br /
label for=screenshotScreenshot:/label
input type=file id=screenshot name=screenshot /
hr /
input type=submit value=Add name=submit /
/form
/body
/html
Results in this output:
Guitar Wars - Add Your High Score Cannot insert query
Thanks again for your help. This is an awesome list!
Tim
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
---End Message---