Jump to content

maltech

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Everything posted by maltech

  1. OK After slapping myself and drinking coffee I found the solution. Thank you to everyone who was attempting to come up with one for me, As always I appreciate any help even if its not seen. This was the solution: if (empty($row['level'])) { mysql_query("UPDATE Usertable SET level = '1' WHERE userid = '$user_id'"); } I was trying to set a new row instead of update the existing one.
  2. First of all everything else is working fine. Yes I am learning, I am doing this project to learn, and it is fun to me to learn new things. All of your help and advice is greatly appreciated! Now here is the code I am trying to use: // Load User into Database if they do not exist mysql_query("INSERT INTO Usertable (userid, name) VALUES ('$user_id', '<fb:name uid=\"$user_id\" useyou=\"false\" />')"); // Query the Usertable for Information $query = "SELECT * FROM Usertable WHERE userid = '$user_id'"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo '<div id="stats">'; echo "Thanks for Stoping By {$row['name']} "; // If they have no value in level add level 1 to the Usertable if (empty($row['level'])) { mysql_query("INSERT INTO Usertable (level) VALUES ('1')"); } echo "<br>"; echo "Your Level Is {$row['level']} "; echo '</div>'; } // Close the Database mysql_close(); The problem I am having it it seems the level is not being set to 1 or anything else for that matter, because this is my output on the page: Thanks for Stoping By Chuck Cagle Your Level Is Thanks in advance!
  3. OK That was a doh solution, for other readers I will post what I figured out I did wrong. If the column needs to be unique don't forget to add PRIMARY KEY (columname); into your table when you create it.
  4. I read the article about why not to use individual tables for each user. I understand why, gotcha, thanks. However what I need to do is not have duplicate entries, I need for at least my userid column to be unique. I tried using this to validate but it is not working.... $sql_username_check = mysql_query("SELECT userid FROM User WHERE userid='$user_id'"); $username_check = mysql_num_rows($sql_username_check); if ($username_check = 0) { mysql_query("INSERT INTO User (userid, name) VALUES ('$user_id', '<fb:name uid=\"$user_id\" useyou=\"false\" />')"); } When I just use the mysql_query and none of the rest, everything works fine, but it keeps adding multiple entries. comes with an output like this 776823045 Chuck Cagle 776823045 Chuck Cagle See where that can be a problem when I attempt to pull information about the userid 776823045 its going to have 2 entries. All help greatly appreciated.
  5. So in your example the following should work fine then mysql_connect("localhost", "$dbuser", "$dbpass"); mysql_select_db("$dbname") or die( "Unable to select database"); mysql_query("CREATE TABLE IF NOT EXISTS $user_id( name varchar(100))"); mysql_close(); is that the correct format? Also I do not understand why having a seperate table for each user_id would be so bad, the $user_id is different for each person, but will always be the same for an individual when they connect in the situation I am using it. My attempt is to use the table as a variables list for each user. I need to call the fields with more than just php and in all clients, php flash etc etc the $user_id will be the same because it comes from one source.
  6. Everytime I load the page it tells me "created it" as in it never actually creates it, or it is not checking if it exists properly. What I need it to do is see if the user (which is allready defined with $user_id earlier in the page) has a table created for them already. If they do not, create a table with their user id. mysql_connect("localhost", "$dbuser", "$dbpass"); mysql_select_db("$dbname") or die( "Unable to select database"); function table_exists($user_id, $dbname) { $exists = mysql_query("SELECT 1 FROM `$user_id` LIMIT 0"); if ($exists) return true; else return false; } if (table_exists($user_id, $dbname)) { printf("Table found"); } else { mysql_query("CREATE TABLE $user_id()"); echo "created it"; }
×
×
  • 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.