Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP (Database Help)

  • 12-03-2007 06: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,991 ✭✭✭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,384 ✭✭✭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