View Full Version : Firefox Javascripting Error

01-09-2008, 06:45 AM
I am very new to coding; however, I have successfully taught myself some PHP to use with MYSQL and I already knew html and css. I do not know very much javascript. I run a website that contains a member's only section in which members may post to a thread. I have compiled this post.php page to insert the content of the post into the database and then forward on some information in a form, while autoloading the user.php page. Basically, it has a hidden form containing the username and password of the user which then will get automatically resubmitted. It works perfectly in both IE and Safari; however, it does not work in Firefox. Rather, it inserts the content into my database; however, it does not execute the javascript to POST the form. Here is my script:

<!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">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
include 'connect.php';
$password = $_POST['password'];
mysql_query("INSERT INTO forum (ip, date, user, comment, forum) VALUES ('$ip', NOW(),'$user','$Message','$forum')");
$action = "Post to $forum";
mysql_query("INSERT INTO log (ip, date, user, password, action) VALUES ('$ip', NOW(), '$user', '$password', '$action')");
<form action="user.php" id="posting" method="post">
<input name="user" type="hidden" value="<? echo $_POST['user'];?>" />
<input name="password" type="hidden" value="<? echo $_POST['password'];?>" />
<script language="JavaScript" type="text/javascript">

<body onLoad="document.form.submit()">

Any help is greatly appreciated,

01-09-2008, 07:05 AM
I'm not sure why are you using javascript to login the user. Why not just use sessions that whole their username. Why do you have to post to user.php anyways? Doing it this way isn't very secure and it also fails if javascript is disabled. Its failing btw because the DOM isn't yet created. You probably get an error in the error console. Its under the tools menu.

01-09-2008, 10:49 AM
Yes, and you can't put a form in the head section of a page, so validity would be very much an issue too

01-09-2008, 04:14 PM
I would have loved to use sessions to hold the username, but unfortunately, I have absolutely no idea how to do that. Any advice?
thanks, Matt

01-09-2008, 06:53 PM
I find it a bit hard to understand that you taught yourself php and mysql but you skipped over something simple like sessions. Tutorial here: http://www.tizag.com/phpT/phpsessions.php