+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: PHP help with mysql please

  1. #1
    revin is offline x10Hosting Member revin is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    11

    Exclamation PHP help with mysql please

    gah, it feels like i've been trying forever to do this

    the table looks like this


    and the php code is here
    PHP Code:
    ################################################################################
    #------------------------------------------------------------------------------#
    #  Activate Function
    #------------------------------------------------------------------------------#
    ################################################################################
    function Activate(){
    DBconn();
    $code=$_REQUEST['code'];
                
    $result mysql_query("SELECT userid FROM users WHERE code='$code'");
                 if(
    mysql_numrows($result) == 1){
                 
    $row=mysql_fetch_row($result);
                       
    $query mysql_query("UPDATE users SET isactive='1',code='0' WHERE userid='$row[userid]'") or die('Could not connect: ' mysql_error());
                       echo 
    'Your account is now active, feel free to login now';
                 }else{
                       echo 
    'You are already activated or error in the database';
           
    }

    i'm not sure what i'm doing wrong here, i am pretty sure i got everything right

    can i get another pair of eyes to look over my code because i'm at the end of my rope here

    its supposed to check whatever variable is placed in my activation url

    xxxx/users.php?maa=Activate&code=xxx

    if it finds a match for xxx then it sets isactive to 1 and code to 0

    but it isn't updating the mysql record

  2. #2
    xmakina's Avatar
    xmakina is offline x10 Lieutenant xmakina is an unknown quantity at this point
    Join Date
    May 2008
    Location
    England
    Posts
    265

    Re: PHP help with mysql please

    Here's a good rule when you're working with SQL.

    Set the SQL query into a variable first.
    If there is an error, echo that variable.
    Use phpMyAdmin to debug the SQL error.

    I've invaribly found that the answer was obvious once I'd seen the SQL output. A fine example is an error I was getting being cause by there being no space between the end of one AND and another. Would *never* have spotted that if I hadn't seen the final SQL that was going to the database.
    IF($this->$post.content() == "SEE SIG"){
    w3Schools and Google
    }

  3. #3
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: PHP help with mysql please

    try making
    PHP Code:
    $query mysql_query("UPDATE users SET isactive='1',code='0' WHERE userid='$row[userid]'") or die('Could not connect: ' mysql_error()); 
    into
    PHP Code:
    $query mysql_query("UPDATE users SET isactive='1',code='0' WHERE userid='".$row['userid']."'") or die('Could not connect: ' mysql_error()); 

  4. #4
    balaji2u's Avatar
    balaji2u is offline x10 Lieutenant balaji2u is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Senthamil Nadu,India
    Posts
    410

    Re: PHP help with mysql please

    Xplozion i think it would be like this isn't it!

    PHP Code:
    $query mysql_query("UPDATE users SET isactive='1',code='0' WHERE userid=$row['userid']") or die('Could not connect: ' mysql_error()); 
    Submit your Site Links Now ! >>> :cool:
    Live Aritlces Free Articles and Links Directory


  5. #5
    revin is offline x10Hosting Member revin is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    11

    Re: PHP help with mysql please

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/revin/public_html/users.php on line 193
    thats the error that comes up now

    that was with this line

    PHP Code:
    $query mysql_query("UPDATE users SET isactive='1',code='0' WHERE userid=$row['userid']") or die('Could not connect: ' mysql_error()); 
    i looked at the database and

    isactive is a TINYINT

    and code is a VARCHAR

  6. #6
    mephis's Avatar
    mephis is offline x10Hosting Member mephis is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    London, UK
    Posts
    39

    Re: PHP help with mysql please

    Quote Originally Posted by balaji2u View Post
    Xplozion i think it would be like this isn't it!
    PHP Code:
    $query mysql_query("UPDATE users SET isactive='1',code='0' WHERE userid=$row['userid']") or die('Could not connect: ' mysql_error()); 
    nope, xplozion got it right the first time:
    Quote Originally Posted by xPlozion View Post
    try making
    PHP Code:
    $query mysql_query("UPDATE users SET isactive='1',code='0' WHERE userid='$row[userid]'") or die('Could not connect: ' mysql_error()); 
    into
    PHP Code:
    $query mysql_query("UPDATE users SET isactive='1',code='0' WHERE userid='".$row['userid']."'") or die('Could not connect: ' mysql_error()); 
    you can't call an array element directly from within a string. you have to concatenate the array element like xplozion said.
    alternatively, you can just use: "{$row['userid']}"

    summarizing:
    PHP Code:
    // sample variables
    $a 1;
    $b['id'] = 1;

    echo 
    "value of a is: $a"// WORKS
    echo "value of b['id'] is: ".$b['id']; // WORKS
    echo "value of b['id'] is: {$b['id']}"// WORKS
    echo "value of b['id'] is: $b['id']"// DOESN'T WORK! 

  7. #7
    revin is offline x10Hosting Member revin is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    11

    Re: PHP help with mysql please

    PHP Code:
    ################################################################################
    #------------------------------------------------------------------------------#
    #  Activate Function
    #------------------------------------------------------------------------------#
    ################################################################################
    function Activate(){
    DBconn();
    $code=$_GET["code"];

                
    $result mysql_query("SELECT userid FROM users WHERE code='".$code."'") or die('select failed' mysql_error());
                
    $checkmysql_numrows($result) or die('Activation code is invalid');
                 if(
    $check == 1){
                 
    $row=mysql_fetch_row($result);
                       
    $query mysql_query("UPDATE users SET isactive='1',code='0' WHERE userid='".$row['userid']."'") or die('Could not connect: ' mysql_error());    
                       echo 
    'Your account is now active, feel free to login now, your user id is '.$row['userid'];
                 }else{
                       echo 
    'You are already activated or error in the database';
           
    }

    code i'm using now shows that its not reading userid from the row :dunno:

  8. #8
    mephis's Avatar
    mephis is offline x10Hosting Member mephis is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    London, UK
    Posts
    39

    Re: PHP help with mysql please

    Quote Originally Posted by revin View Post
    PHP Code:
    ################################################################################
    #------------------------------------------------------------------------------#
    #  Activate Function
    #------------------------------------------------------------------------------#
    ################################################################################
    function Activate(){
    DBconn();
    $code=$_GET["code"];

                
    $result mysql_query("SELECT userid FROM users WHERE code='".$code."'") or die('select failed' mysql_error());
                
    $checkmysql_numrows($result) or die('Activation code is invalid');
                 if(
    $check == 1){
                 
    $row=mysql_fetch_row($result);
                       
    $query mysql_query("UPDATE users SET isactive='1',code='0' WHERE userid='".$row['userid']."'") or die('Could not connect: ' mysql_error());    
                       echo 
    'Your account is now active, feel free to login now, your user id is '.$row['userid'];
                 }else{
                       echo 
    'You are already activated or error in the database';
           
    }

    code i'm using now shows that its not reading userid from the row :dunno:
    hmmmm... I think that if you want to access the $row elements by their field name you need to use mysql_fetch_assoc() instead of mysql_fetch_row().
    mysql_fetch_row() returns an indexed array, whereas mysql_fetch_assoc() returns an associative array.
    read this:
    http://www.php.net/manual/en/functio...etch-assoc.php

  9. #9
    revin is offline x10Hosting Member revin is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    11

    Re: PHP help with mysql please

    Woo!

    thanks, that worked for me ^^

    coding is frustrating sometimes x3

  10. #10
    mephis's Avatar
    mephis is offline x10Hosting Member mephis is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    London, UK
    Posts
    39

    Re: PHP help with mysql please

    not a problem... glad I could help
    (and yes, it can be *very* frustrating sometimes)

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. Places to learn php
    By JaWasabi in forum Scripts & 3rd Party Apps
    Replies: 9
    Last Post: 01-13-2009, 02:03 AM
  3. [Cossacks] PHP Wont Load MYSQL DOWN
    By pasacom in forum Free Hosting
    Replies: 0
    Last Post: 08-26-2008, 12:30 AM
  4. PHP MySQL Question..
    By anuj_web in forum Programming Help
    Replies: 7
    Last Post: 04-26-2008, 05:43 AM
  5. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers