Page 1 of 1

PHP 5 problem with issuing mysql commands from browser.

Posted: Mon Mar 29, 2004 4:11 pm
by wyattk
howdy gents,

I've hit a php roadblock--I've asked a few php-experienced friends and it has stumped them all.

I've got a php file that should insert given variables into a database (much like a guestbook script). When I run the file from an SSH client (replacing posted variables with internal ones, of course), it parses perfectly and modifies the database as desired. From a browser, however, it will not load anything after the mysql commands (it won't even die when the command fails).

Here is the code:

Code: Select all

<?php
error_reporting(E_ALL);

$data = "howdy";
$query = "INSERT INTO guests ";
$query .= "(guest_name)";
$query .= " values ('$data')";

echo "$query";
mysql_pconnect('localhost' , 'user' , 'password');
mysql_select_db("guestbook");

echo "$query";
mysql_query($query) or die ("Error: " . mysql_error());

?>
It echoes the first time but not the second.

(note: the mysql command was force installed rather than mysqli because the mysqli package was corrupt on the installer. I haven't yet tried to reinstall mysqli, mainly because the admin is out of town :roll: )

Apache server, btw

cheers,
wyatt

Posted: Mon Mar 29, 2004 6:06 pm
by markl999
Anything show up if you add some more error checking, like:

mysql_pconnect('localhost' , 'user' , 'password') or die(mysql_error());
mysql_select_db("guestbook") or die(mysql_error());

?

Posted: Mon Mar 29, 2004 6:13 pm
by wyattk
nope, tried it :-/

Posted: Mon Mar 29, 2004 6:16 pm
by markl999
Hmm, you say it doesn't work with posted vars, so unless you're server has register_globals On (or the code shown is just part of a bigger script) then you'll need to use $query .= " values ('{$_POST['data']}')";
</clutching at straws> ;)

Posted: Mon Mar 29, 2004 6:22 pm
by wyattk
well it actually *does* work with posted variables, but when running the php script alone (from ssh), no variables are posted, so I just made them internal variables for troubleshooting :)

Either way, when I run that bit of script from the ssh it works, but from the browser it does not.

Posted: Mon Mar 29, 2004 6:26 pm
by markl999
Hmm..well the only thing i can think of that might cause it is the pconnect, does an ordinary mysql_connect() make any difference ?
Also have you checked apaches's error log, that might give some clues.

Posted: Mon Mar 29, 2004 6:35 pm
by wyattk
tried using a regular connect, no dice. I can't access the error log, but I'll find someone who can. :)

thanks for the help, man
wyatt