[PHP]Script Help.

Results 1 to 7 of 7
  1. #1
    Account Upgraded | Title Enabled! ManyBlackPpl is offline
    MemberRank
    Mar 2009 Join Date
    CanadaLocation
    336Posts

    [PHP]Script Help.

    Well, I just started doing php on my own (not editing other people's stuff), and I'm trying to make a small ban script. I think I've done everything properly, but I have this one little parse, T_String error, and I can't find any improper semicolons and what not. I may have done something wrong, but anyways, I was just wondering if any of you could point out the problem in this script:

    Code:
    <?php
    
    $conn = mssql_connect('*************', 'sa', '**************');
    
    	if(!$conn)
    	  {
    	    die('Error in connecting to the SQL Server.');
    	  }
    
    mssql_select_db('****************');
    
    $proc1 = mssql_init('dbo.ipbanningscript1', $conn);
    $proc2 = mssql_init('dbo.ipbanningscript2', $conn);
    
    mssql_execute($proc1);
    mssql_execute($proc2);
    
    mssql_query('INSERT INTO dbo.ipbans('UserID','IP') VALUES ('$_POST["username"]', '$_POST["ipaddress"]')');
    
    ?>
    and, I already have another script set up with the form, and the method='POST'. The first textfield's name is username, and the second one is ipaddress (for the $_POST part).

    And here's the error quoted:

    Code:
    Parse error: syntax error, unexpected T_STRING in C:\the folder name which you cannot see O_o\post.php on line 18
    Last edited by ManyBlackPpl; 03-11-09 at 03:29 AM.


  2. #2
    Valued Member LegacyCode is offline
    MemberRank
    Aug 2009 Join Date
    HyruleLocation
    129Posts

    Re: [PHP]Script Help.

    Try replacing line 18 with this.

    PHP Code:
    mssql_query('INSERT INTO dbo.ipbans(\'UserID\',\'IP\') VALUES (\''.$_POST['username'].'\',\''.$_POST['ipaddress'].'\')'); 
    Last edited by LegacyCode; 03-11-09 at 06:01 PM.

  3. #3
    Account Upgraded | Title Enabled! alfredao is offline
    MemberRank
    Jan 2008 Join Date
    Coronel FabriciLocation
    705Posts

    Re: [PHP]Script Help.

    PHP Code:
    <?php

    $conn 
    mssql_connect("*************""sa""**************");

        if(!
    $conn)
          {
            die(
    "Error in connecting to the SQL Server.");
          }

    mssql_select_db("****************");

    $proc1 mssql_init("dbo.ipbanningscript1"$conn);
    $proc2 mssql_init("dbo.ipbanningscript2"$conn);

    mssql_execute($proc1);
    mssql_execute($proc2);

    $username $_POST["username"];
    $ipaddress $_POST["ipaddress"];

    mssql_query("INSERT INTO dbo.ipbans('UserID','IP') VALUES ('$username', '$ipaddress')");

    ?>
    Last edited by alfredao; 03-11-09 at 04:58 PM.

  4. #4
    Account Upgraded | Title Enabled! ManyBlackPpl is offline
    MemberRank
    Mar 2009 Join Date
    CanadaLocation
    336Posts

    Re: [PHP]Script Help.

    Thanks Legacy, that worked perfectly, and I've now gotten rid of that error. It'll definitely be helpful for me if I try to do this without variables. Alfredo, your method also works. But now I have another error.

    Code:
    Warning: mssql_query() [function.mssql-query]: message: Invalid column name 'UserID'. (severity 16) in *filepath* on line 18
    
    Warning: mssql_query() [function.mssql-query]: message: Invalid column name 'IP'. (severity 16) in *filepath* on line 18
    
    Warning: mssql_query() [function.mssql-query]: Query failed in *filepath* on line 18
    -----------------------------------------------------
    EDIT:

    Okay, I realized what might have caused the problem. Before, I didn't have the two stored procedures set up, because I thought it wouldn't be necessary if I was just testing to see if it inserted into the table or not (I got the storedprocedures execution errors of course). I just read through the second query, and saw that it creates the table and columns for you to type in, so I'm guessing that's what's causing my errors. I'll test it out and see if that's the problem.

    and, I've checked my database, properly, and I do have a table called dbo.ipbans, with column names of UserID and IP. Anyone know what else could have gone wrong?

    ----------------------------
    Double Edit:

    Okay, I'm not very good with mssql. I know how to create a new query and execute it, but I have absolutely no idea of how to save a query, so if anybody can quickly mention how I would go about saving it, and how I would link to it, then that would be great. I've also tired googling it, and I couldn't seem to fine the answers I wanted, which is why I'm asking here.
    Last edited by ManyBlackPpl; 04-11-09 at 12:41 AM.

  5. #5
    Valued Member LegacyCode is offline
    MemberRank
    Aug 2009 Join Date
    HyruleLocation
    129Posts

    Re: [PHP]Script Help.

    In alfredos one try replacing line 21 with

    PHP Code:
    mssql_query("INSERT INTO dbo.ipbans(UserID,IP) VALUES ('$username', '$ipaddress')"); 
    the table names had quotes around them because of that
    sql reads them as data and not as field names.
    Last edited by LegacyCode; 04-11-09 at 12:30 PM.

  6. #6

    Re: [PHP]Script Help.

    Quote Originally Posted by LegacyCode View Post
    In alfredos one try replacing line 21 with

    PHP Code:
    mssql_query("INSERT INTO dbo.ipbans(UserID,IP) VALUES ('$username', '$ipaddress')"); 
    the table names had quotes around them and sql because of that
    sql reads them as data and not as field names.
    Good job on spotting the error.

  7. #7
    Account Upgraded | Title Enabled! ManyBlackPpl is offline
    MemberRank
    Mar 2009 Join Date
    CanadaLocation
    336Posts

    Re: [PHP]Script Help.

    Quote Originally Posted by LegacyCode View Post
    In alfredos one try replacing line 21 with

    PHP Code:
    mssql_query("INSERT INTO dbo.ipbans(UserID,IP) VALUES ('$username', '$ipaddress')"); 
    the table names had quotes around them because of that
    sql reads them as data and not as field names.
    yeah, thanks legacy, I also knew that (switched it up a bit). But that's not my problem. Right now, the reason why it can't insert the info into the tables is because I have to run two queries made by ownprox, and the second query sets up the table properly for me to input table data. I need some way of making a stored procedure to get that done.

    I've managed to create a stored procedure after a bit of investigating, but my question is how would I go about modifying details within a stored procedure, because after I created a stored procedure with the steps that I told it to put, and I re-checked it, the mssql procedures that I put weren't there.



Advertisement