Jump to content

bobocheez

Members
  • Posts

    19
  • Joined

  • Last visited

    Never

Posts posted by bobocheez

  1. Hey,

    I'm trying to check if a username is unique, but for some reason none of the methods that I've looked up seem to work.

     

    I'm aiming for the code to check if a username is unique, and if get the user to input the name again.

     

    $get = "SELECT `i` FROM `m` WHERE `i`=\"$r\"";
    $checkResults = mysql_query($getRandomness);
    while(mysql_num_row($checkResults) > 0)
    {
      //some code...
      //check again
    	$get = "SELECT `i` FROM `m` WHERE `i`=$r";
    	$checkResults = mysql_query($get);
    }
    

     

    The error comes from the while line, but it comes up during the first check because the record is empty.

    This is the error:

    "Fatal error: Call to undefined function mysql_num_row()"

  2. That would normally work, but show turns out to be a command of some sort....so it gives out a syntax error

     

    "Definition: The show tables SQL command is used to display all of the tables in a MySQL database and is phrased as: show tables;

    Examples: This would list all of the tables in your database:

     

    show tables;"

    -By Angela Bradley, About.com Guide

     

    So all is needed here is a change in column name.

    Thanks for trying.

  3. Hi,

    I have a piece of code where, $n is a sequential number from 1-20, and $display is from the database with numbers 1-20, but in a random order.

    How can the following code be edited so that $display will equal $n?

     

    $n = 0;
    while ($n < 20) {
    $n++;
    
    $query_d = "SELECT display FROM hits_d WHERE id='$n' ORDER BY display DESC";
    $result_d = mysql_query($query_d) or die('Sorry, could not access the database');
    $row_d=mysql_fetch_array($result_d, MYSQL_BOTH);
    $display = $row_d['display'];
    
    $ad = '$ad'."$n";
    if ($display == $n) {$showad = $ad;}
    echo "n: $n display: $display showad: $showad<br/>";
    }

  4. So I have a random number script, but I'm not sure how to store the array values in once cell. Then query the db again and set individual variables for each number.

    I would just make 5 cells for each number, but more numbers will be added so I don't want the table to get too big.

     

    $max = 5;
    $min = 1;
    $amount = 5;
    $x = 0;
    $numbers[0] = 0;
    
    if (($max - $min) > $amount) die('$amount is larger number than $max - $min');
    
    while (count($numbers) < $amount) {
            $ranvar = rand($min, $max);
            while(in_array($ranvar, $numbers)) {
                    $ranvar = rand($min, $max);
            }
            $numbers[$x] = $ranvar;
            $x++;
    }
    echo "$numbers[0]<br/>";
    echo "$numbers[1]<br/>";
    echo "$numbers[2]<br/>";
    echo "$numbers[3]<br/>";
    echo "$numbers[4]<br/>";
    
    $query_rand = "UPDATE hits WHERE id=2 SET order='something', ";
    mysql_query($query_rand);

  5. How can the following code be altered so that the select options menu shows all of the subcat choices?

     

    This is just a form that queries the database first

     

    <?php
    include('config.php');
    
    $query = "SELECT * FROM subcategories ORDER BY cat_id ASC";
    $result = mysql_query($query) or die('Sorry, could not access the database');
    mysql_num_rows($result);
    $subcat_id = $row['subcat_id'];
    $subcat = $row['subcategorie_name'];
    $cat_id = $row['cat_id'];
    
    ?>
    <form action="addchan2.php" method="post">
    <select name="subcat">
    <?php while($row=mysql_fetch_array($result, MYSQL_ASSOC))
       {
           $cat = $row['cat'];
       	echo "<option value=\"$subcat\">$subcat</option>";
       } ?>
    </select>
    <input type="text" name="chan">
    <input type="text" name="subcat_id" value="<?echo"$subcat_id";?>">
    <input type="text" name="cat_id" value="<?echo"$cat_id";?>">
    <input type="submit" value="Add">
    </form>

  6. Oh

    So, $_SESSION['valid_user'] carries over to all other pages where the session start function is included, and for those pages, $username would have to be set = to the session variable each time.

     

    Therefore

    session_start();
    $username = $_SESSION['valid_user'];
    echo "Hello $username";

     

    Would display Hello bob

     

    Is this correct?

  7. Hi,

    I've looked over a few login tutorials about sessions, but my small brain cannot connect the dots from the different programming styles people have.

     

    What I understand so far, and please correct me if I am wrong,:

     

    1. For logins: after a user logs in and the info is processed through the database session variables are set

    //connect & retrieve database info for bob then:
    $_SESSION['valid_user'] = $username;
    $_SESSION['user_id'] = $user_id;
    //This means that the session array valid_user is = to bob

     

    2. Each page that has the session_start(); function can use those session variables.

    So if $username is echoed, then the valid_user array would carry over and display bob

     

    Therefore if the index page contains the session start function at the beginning, and includes the login form/processor, then any $_REQUEST information should be able to use those stored variables.

     

    Now, I figured I must be missing something because the scraps of code that I put together do not work, or I just suck at writing things correctly.

     

    Any input (good/bad) is appreciated

    Thanks

  8. Hi,

    I have the following code and it will not check to see if a registering user inputs the same data as another user.

     

    The snippet:

    $query = 'SELECT username FROM users WHERE username = "$username"';
    $result = mysql_query($query);
    $row = mysql_fetch_array($result, MYSQL_BOTH);
    if ($row['username'] == $username) {

     

    However, it does insert the entry so it is connected to the database.

    Thoughts?

  9. Ok, so I have this code and I'm getting a wierd error

     

    Table 'tutorial.tutorial' doesn't exist

    The error if from the //TEST below

     

    I'm using xampp if thats of any use

     

    //OPENS CONNECTION TO MYSQL SERVER

    $dbc = mysql_connect('localhost','root','');

    if (!$dbc){

    die('Not connected:' . mysql_error());

    }

     

    //SELECT DATABASE

    $db_selected = mysql_select_db('tutorial', $dbc);

    if (!$db_selected){

    die ('cant connect:' . mysql_error());

    }

     

    //TEST

    $query="UPDATE tutorial SET email='hope_this_works' WHERE username='bobo'";

    $result=mysql_query($query);

    if (!$result){

    die ('update failed ->' . mysql_error());

    }

     

     

  10. 1)

    My social network site recently crashed and I had to upload everything again, but for some reason something is broken.

    I had a referral script implemented into the SN script so that they work as one. However, I don't think that I have the original mod of the referral script that worked with the SN.

     

    The script can be used as a standalone program but when it was integrated, the user only had to login once from the SN. From there on, the referral center could be used just as if it were part of the SN itself. I'm not sure what is wrong with it, and I'm not sure what needs to be done to reverse the effects of the crash, but I do know that it used a database, and the original data is still there, so I'm hoping that can help you somehow.

    Quote?

     

     

    2)

    If the above project is completed then a page where the usernames are displayed along with how many referrals they have. would also be great.

    Depending on how much project number 1 is worth, then I can provide more details on what should be on the page.

     

    Thank You

    P.S. I'll provide more indepth details when you want to do the project.

     

    Email me at bobo_ra@hotmail.com and tell me that you are from here

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.