Author Topic: PHP question  (Read 823 times)

0 Members and 1 Guest are viewing this topic.

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.
« Last Edit: June 22, 2005, 01:39:31 pm by 2010 »

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
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.
-C

 
All that I have written so far. Do I need more?

  

Offline WMCoolmon

  • Purveyor of space crack
  • 213
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
-C

 

 
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?

 

Offline wojta

  • 25
    • http://fsworld.wz.cz
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        
« Last Edit: June 22, 2005, 04:00:14 pm by 1066 »

 
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?
« Last Edit: June 22, 2005, 04:13:14 pm by 2010 »

 
ITS WORKING NOW!
HALLELUYA

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

Thanks for hte help guys.

 

Offline Taristin

  • Snipes
  • 213
  • BlueScalie
    • Skelkwank Shipyards
Kudos! Registerred.
Freelance Modeler | Amateur Artist