Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16

Thread: Mysql problem

  1. #1
    Member
    Join Date
    Jul 2007
    Posts
    64
    Member #
    15493
    I've searched all around these forums but can't seem to get what I'm looking for, so here goes. I'm trying to install a login/profile system, now I have all the code but when I actually try to register and login(and connect to the database)I get this error.

    Parse error: syntax error, unexpected '.', expecting ')' in /edited/businesslinkd.comfunctions.php on line 32

    Now, this doesn't make much sense to me. BECAUSE the only "." in that specific line is the link to the hostname. Here's the code. It goes hostname > username > password > dbname.

    Quote Originally Posted by functions.php

    function MySqlConnect($ukra1.businesslinkd.com,$USERNAME, $PASSWORD,$ukr);
    {

    mysql_connect($ukra1.businesslinkd.com,$USERNAME,$ PASSWORD);
    I don't get this problem. My config.php file has all the correct information with the username, database, host name and whatnot. And if I type in 'ukra2.businesslinkd.com' into my browser, I can login. But I don't know what to put in substitute for the "." in my hostname.(Or if Im even supposed to!) Anyone have any idea what's going on here?


  2.  

  3. #2
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    The problem is that you're referencing a string:

    Code:
    "ukra1.businesslinkd.com"
    As though it were a variable:

    Code:
    $ukra1.businesslinkd.com
    In fact, you're doing that with all your strings. String data should be enclosed in quotes ("string"). Variables are preceded by a dollar sign ($variable).

  4. #3
    Member
    Join Date
    Jul 2007
    Posts
    64
    Member #
    15493
    Okay. Earlier in the script it says


    for ($i=0;$i<strlen($string);$i++)
    {
    $cursym=substr($string,$i,1);
    though. So, that confuses me a bit. Or does that not matter at all?

    and is this the correct format?

    function MySqlConnect(ukra1.businesslinkd.com)($username,$p assword,$ukr);

  5. #4
    ljm
    ljm is offline
    Senior Member ljm's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, England
    Posts
    284
    Member #
    13684
    Liked
    1 times
    The correct format for that MySql connect funtion is:

    PHP Code:
    function MySqlConnect("ukra1.businesslinkid.com"$username$password$ukr); 
    I suggest you read some tutorials on the basics of PHP before you get involved with this. There are plenty on the net: http://pixel2life.com has a lot to offer. You need to know how it works, as you can't alter code if you have no idea how to do it!

  6. #5
    Member
    Join Date
    Jul 2007
    Posts
    64
    Member #
    15493
    Well someone wrote it for me. I'm just installing. Anyway, I put in the right thing and now I get this.

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '&' or T_VARIABLE

  7. #6
    Senior Member tonyf12's Avatar
    Join Date
    Mar 2007
    Posts
    132
    Member #
    14998
    function MySqlConnect("ukra1.businesslinkd.com",$username,$ password,$ukr); is correct.

  8. #7
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Wait, why are you declaring a function with a constant string in the parameter list? Drop the "ukra1.businesslinkd.com" bit altogether, along with the comma after it:

    PHP Code:
    function MySqlConnect($username$password$ukr
    Note that there's also no trailing semicolon on the function declaration. The next line's curly brace is also important.

  9. #8
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Better yet.... let's do this from scratch, because the PHP is pretty foobar...

    Your function should look something like this:
    PHP Code:
    function MySqlConnect($server="localhost"$username="sa"$password=""$catalog="master") {
        
    $link mysql_connect($server$username$password);
        
    mysql_select_db($catalog$link);
        return 
    $link;

    And your calling code should look like this:
    PHP Code:
    $conn MySqlConnect("ukra1.businesslinkd.com""My Username""My Password""My Database Name"); 
    You can then specify $conn as your connection link in your queries.

    Good luck. Read up on PHP

  10. #9
    Member
    Join Date
    Jul 2007
    Posts
    64
    Member #
    15493
    Thanks so much for the help. One question though, the coder says there is a tiny mistake in the code but I'm not sure where it is.

    <?php
    function safe($string, $mode, $size)
    {
    if ($mode=="number")
    {
    $result="";
    for ($i=0;$i<strlen($string);$i++)
    {
    $cursym=substr($string,$i,1);
    if ((ord($cursym)>48)AND(ord($cursym)<58)) $result.=$cursym;
    if ($cursym=="0") $result.="0";
    }
    if (strlen($result)>$size) $result=substr($result,0,$size);

    $result=$result+1-1;
    return $result;
    }
    else
    {
    $result=strip_tags($string);
    $result=htmlentities($result, ENT_QUOTES);
    $result=stripslashes($result);
    if (strlen($result) > $size) $result=substr($result,0,$size);
    return $result;
    }
    }

    function MySqlConnect($HostName,$UserName,$Password,$DBName )
    {

    mysql_connect($HostName,$UserName,$Password);

    if (!mysql_connect($HostName,$UserName,$Password))
    {
    echo "? ??? ???????? ????? ".$DBName."!<br>";
    echo mysql_error();
    exit;
    }

    if (!mysql_select_db($DBName)) echo "Could not connect to $DBName";
    return true;
    }

    function Stop ($string)
    {
    echo $string;
    echo "<br><br>";
    echo "<a href='index.php'> Come back </a>";
    die();
    }


    ?>
    That is the original code.

  11. #10
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    I'm not sure what the point of giving default parameters for the function is if they're not going to be used, but whatever.

    Also, where exactly is the error suposed to be? Just anywhere? I mean, he does try to connect to the database twice (the two mysql_connect calls) where he could do a $link = mysql_connect the first time and then do an if (!$link) the second time.


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:08 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com