Jump to content

bobocheez

Members
  • Posts

    19
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

bobocheez's Achievements

Newbie

Newbie (1/5)

0

Reputation

  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. Oh, I didn't know that. Thanks. Works like a charm.
  3. 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.
  4. I tried without the second where and it did not work.
  5. How would you format the following so that a row that has both $season and $show in it? $query = "SELECT * FROM episodes WHERE season_no='$season' AND WHERE show='$show'";
  6. 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/>"; }
  7. I'll go with a new table, for now, since I don't know much about the other methods. Thanks
  8. 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);
  9. 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>
  10. You can just use the decimal equivalent: 25% = 0.25 I'm not sure how the math works in php but you might have to define a floating number. And this should be posted in the math section.
  11. 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?
  12. 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
  13. hey retard, this goes in the math section ask an admin to move it
  14. That does not work either. But I figured it out. The variable value has to be in double quotes.... So anyone else reading this, both codes will work if you just change the quotes " change to ' ' change to "
  15. 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?
×
×
  • 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.