Hard Light Productions Forums

Off-Topic Discussion => General Discussion => Topic started by: MatthewPapa on June 22, 2005, 01:26:40 pm

Title: PHP question
Post by: MatthewPapa on June 22, 2005, 01:26:40 pm
Right now I am writing a pilot creation form so that users can create a new PXO pilot to play with. The task invoves inserting like 4 fields of data into an table on a SQL database. This is all done though a HTML form. Here is my code

My HTML form page:
Code: [Select]


 


  Create a new pilot


 
   
     
     
   
   
     
     
   
   
     
     
   
   
     
     
   
   
     
     
   
 

      Username

      Password

      Squadron
Email

      Profile

 

 


 





and my php page that takes care of the insertion:

Quote

$usr = "myusername";
$pwd = "mypassword";
$db = "fs2openpxo";
$host = "localhost";

$cid = mysql_connect($host,$usr,$pwd);
mysql_select_db($db);
if (!$cid) { print "ERROR: " . mysql_error() . "\n"; }

$username = $_POST["username"];
$password = $_POST["password"];
$squadron = $_POST["squadron"];
$email = $_POST["email"];


if ($_SERVER['REQUEST_METHOD'] == "POST") {

$sql = " INSERT INTO useraccounts ";
$sql .= " (UserName, PassWord, Email, Squadron) VALUES ";
$sql .= " ('$username', '$password','$email','$squadron') ";
$result = mysql_query($sql, $cid);
if (mysql_error()) { print "Database ERROR: $sql " . mysql_error(); }
?>

I keep getting a parse error when I try and run this.
An example can be found at http://freespaceserver.cjb.net/fs2netd/newpilot.php

Any help on this is appreciated. Thanks in advance.

EDIT: cant get the HTML to appear as HTML. View page source to see the form's HTML content.
Title: PHP question
Post by: WMCoolmon on June 22, 2005, 01:35:44 pm
Is that the complete source of that file?

Edit: I think (it's been awhile) that you might have to use \' instead of just ' in double-quote strings.
Title: PHP question
Post by: MatthewPapa on June 22, 2005, 01:37:20 pm
All that I have written so far. Do I need more?
Title: PHP question
Post by: WMCoolmon on June 22, 2005, 01:38:39 pm
Well, it's just that there's supposedly a parse error on line 36, but there is no line 36, and according to the source you posted there is no header file :wtf:

Nor is there a
Title: PHP question
Post by: MatthewPapa on June 22, 2005, 01:41:47 pm
http://freespaceserver.cjb.net/pilot/

browse them as text files there
Title: PHP question
Post by: MatthewPapa on June 22, 2005, 02:41:23 pm
Quote
Originally posted by WMCoolmon
Edit: I think (it's been awhile) that you might have to use \' instead of just ' in double-quote strings.


What do u mean?
Title: PHP question
Post by: wojta on June 22, 2005, 03:58:00 pm
Single quotes inside double quoutes are ok.

There is a missing '}' in the last if-statement.


if ($_SERVER['REQUEST_METHOD'] == "POST") {
  $sql = " INSERT INTO useraccounts ";
  $sql .= " (UserName, PassWord, Email, Squadron) VALUES ";
  $sql .= " ('$username', '$password','$email','$squadron') ";
  $result = mysql_query($sql, $cid);
  if (mysql_error()) {
    print "Database ERROR: $sql " . mysql_error();
  }
}  //here        
Title: PHP question
Post by: MatthewPapa on June 22, 2005, 04:10:03 pm
well, it may have helped. I just updated the code. Still a parse error. Check it out.

http://freespaceserver.cjb.net/fs2netd/newpilot.php

What else could it be?
Title: PHP question
Post by: MatthewPapa on June 22, 2005, 04:20:18 pm
ITS WORKING NOW!
HALLELUYA

all it needed was that  } wojta suggested and a ?>

Thanks for hte help guys.
Title: PHP question
Post by: Taristin on June 22, 2005, 04:24:40 pm
Kudos! Registerred.