Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP (Database Help)

  • 12-03-2007 5:00pm
    #1
    Closed Accounts Posts: 44


    Need some help with this php code, i have setup a system where when people register and login for my site (its just for a college project so no security issues here) that their username is shown at the top with some account options. Kinda like dailymotion or you tube do

    Anyway a further option people can do is register as a seller, and if they do that there user id is entered into a seller table (hopefully somebody can folloow this)

    What the code below is trying to do is check if the persons username has a corresponding entry in the sellers table (basically check are they registered as a seller - the SQL is correct cause i have that part tested) (if seller_id != 0) and if they have it displays the link to sell a book and if their not registered as a seller they get the option to register as a seller)

    Code keeps throwing up errors and im not sure if the logic is correct either,
    any1 have any pointers?

    Cheers


    <?php
    include("db.php");

    $check1 = mysql_query("SELECT seller_id FROM seller s,user u WHERE u.id = s.seller_id and u.username ='$username'")or die("error");

    while($info1 = mysql_fetch_array( $check1))
    {
    if ($seller_id != 0($info1["seller_id"))
    {
    ?>
    <a href="sell.php">Sell a Book</a>

    <?php
    }

    else {
    ?>
    <a href="register_seller.php">Become a seller</a>

    <?
    }
    }
    ?>

    Regards
    Daryll


Comments

  • Registered Users, Registered Users 2 Posts: 1,987 ✭✭✭Ziycon


    Try changing the query line to this:
    $check1 = mysql_query("SELECT seller_id FROM seller s,user u WHERE u.id = s.seller_id and u.username ='".$username."'")or die("error");
    


  • Closed Accounts Posts: 44 daryllsheridan


    Thanks for the response

    In this case i dont think thats the answer

    Ive used that query in another part (but for a different purpose) and it works fine

    I think its somewhere in the logic below that is the problem

    What im looking for is

    If the query returns a result then

    <a href="sell.php">Sell a Book</a>

    is displayed

    and if the query returns a null set then

    <a href="register_seller.php">Become a seller</a>

    is returned


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    is the error from the query made to the database or after?

    try this:
    [php]
    <?php
    include("db.php");

    $check1 = mysql_query("SELECT seller_id FROM seller s,user u WHERE u.id = s.seller_id and u.username ='$username'")or die("error");


    if ($info1 = mysql_fetch_array( $check1)){
    echo "<a href=\"sell.php\">Sell a Book</a>";
    }else{
    echo "<a href=\"register_seller.php\">Become a seller</a>";
    }
    ?>
    [/php]


  • Registered Users, Registered Users 2 Posts: 6,414 ✭✭✭kdouglas


    if ($seller_id != 0($info1["seller_id"))

    the above line looks suspect??

    id imagine you meant
    if($seller_id != 0 && $seller_id == $info1["seller_id"])

    im gonna guess your writing code in a plain text editor?
    i recently started using the eclipse ide with the phpeclipse plugin, it's pretty good and will pick up on errors similar to above while you type


  • Closed Accounts Posts: 44 daryllsheridan


    louie wrote:
    is the error from the query made to the database or after?

    try this:
    [php]
    <?php
    include("db.php");

    $check1 = mysql_query("SELECT seller_id FROM seller s,user u WHERE u.id = s.seller_id and u.username ='$username'")or die("error");


    if ($info1 = mysql_fetch_array( $check1)){
    echo "<a href=\"sell.php\">Sell a Book</a>";
    }else{
    echo "<a href=\"register_seller.php\">Become a seller</a>";
    }
    ?>
    [/php]


    Genius

    That worked perfect

    Cheers!


  • Advertisement
Advertisement