Jump to content

hitman6003

Members
  • Posts

    1,807
  • Joined

  • Last visited

Everything posted by hitman6003

  1. If you're relating the comments to the original news story by the id of the news story (id_int?) then you don't need to get news_table:id.
  2. If you are going to use mysql_real_escape_string, you must connect to the DB first. <?php error_reporting(E_ALL); mysql_connect("localhost", "root", "private") or die (mysql_error()); mysql_select_db("civilian") or die (mysql_error()); if (isset($_POST['RegistrationSubmission'])) { $TermsOfService = $_POST['TermsOfService']; $Username = mysql_real_escape_string($_POST['Username']); $Password = mysql_real_escape_string($_POST['Password']); $Password2 = mysql_real_escape_string($_POST['Password2']); $Email = mysql_real_escape_string($_POST['EmailRegistration']); $Country = mysql_real_escape_string($_POST['CountryChoice']); $ip = $_SERVER["REMOTE_ADDR"]; $Gender = $_POST['Gender']; if ($Password != $Password2) { echo "Passwords did not match"; if ($TermsOfService == "off") { echo "You must agree to the terms of service before registering!"; $jump2 = 0; } } else { $chkUSERNAME = mysql_query("SELECT * FROM `userregistration` WHERE `Username` = '".$_POST['Username']."'") or die(mysql_error()); $getUSERNAME = mysql_fetch_object($chkUSERNAME); if($_POST['Username'] == $getUSERNAME->Username) { die('Username already registered, please choose a different username!'); } $chkEmail = mysql_query("SELECT * FROM `userregistration` WHERE `Email` = '".$_POST['EmailRegistration']."'") or die(mysql_error()); $getEmail = mysql_fetch_object($chkEmail); if($_POST['EmailRegistration'] == $getEmail->Email) { die('Email already registered, please choose a different username!'); } $query = "INSERT INTO `userregistration` (Username,Password,Email,Country,IP,Gender) Values ('$Username', '$Password', '$Email', '$Country', '$ip', '$Gender')"; echo $query; mysql_query($query) or die(mysql_error()); } } ?>
  3. Without code, there is little help we can provide. Use the javascript "split" to break apart a string...that's the best I can offer with what you've provided.
  4. What field(s) are you getting from the news table in your COUNT query that you need to join it? Why not just use one table? SELECT COUNT(comments) FROM news_comments WHERE related_news_article_id = 1
  5. Means that you're trying to access an element in an array that doesn't exist. More than likely this query failed: $chkUSERNAME = mysql_query("SELECT * FROM `userregistration` WHERE `Username` = '".$_POST['Username']."'"); change it to: $chkUSERNAME = mysql_query("SELECT * FROM `userregistration` WHERE `Username` = '".$_POST['Username']."'") or die(mysql_error()); Then see what the error is.
  6. So use his example and write it....
  7. SELECT count(subject_cmt) FROM comment INNER JOIN news WHERE id_int=1 Why are you joining news? What column are you joining news on?
  8. Check the permissions on your file...make sure that the user that runs the web server (IUSR_servername, I think, on windows, whatever the SA set it to on *nix), has write permission to that file.
  9. Check to see if the value is there before including it into the overall query. $query = "select * from yellowtable "; if (!empty($name)) { $query_parts[] = "name LIKE '%$name%'"; } if (!empt($category)) { $query_parts[] = "category LIKE '%$category%'"; } if (!empty($city)) { $query_parts[] = "city LIKE '%$city%'"; ] if (!empty($state)) { $query_parts[] = "state LIKE '%$state%'"; } if (count($query_parts) > 0) { $query .= implode(" OR ", $query_parts); } $result = mysql_query($query) or die(mysql_error());
  10. Define "corrupted easily". When the database suddenly dies...because the process is killed or the power to the server is cut, etc...it can cause harm to any of the database files. MyISAM has a greater potential for problems because it does table level locking during inserts. That means that if an insert is occurring when the database dies, that table is left in a locked state. It is easily fixed by repairing the table. There is no one engine better than another. If you need transactions however, there is only one choice, at least until MySQL 6 comes out. If you have a read heavy environment, and don't need transactions, then **generally speaking** MyISAM is going to give you better performance. Due to it's table level locking strategy however, in a heavy insert environment, MyISAM is not always the best choice...InnoDB is the better choice of the two major engines.
  11. Notices don't mean anything is really wrong...turn them off by putting error_reporting(E_ALL ^ E_NOTICE); at the top of your page. In this case, you are getting those because it's putting things into an array before the array has been defined. The other error has to do with your database. I can't help you there...the error should be fairly self explanatory.
  12. use sprintf http://www.php.net/sprintf#id3673751
  13. When you copy and pasted the above, did you get all of the query? cause it looks like you didn't. SET @a:=0,@b:=0; SELECT a.url,SEC_TO_TIME(AVG(b.ts-a.ts)) AS "Average Duration",COUNT(*) AS Hits FROM (SELECT url,ip,@a:=@a+1 AS count,ts FROM temp ORDER BY ip,ts) a JOIN (SELECT ip,@b:=@b+1 AS count,ts FROM temp ORDER BY ip,ts) b ON a.ip=b.ip AND b.count=a.count + 1 GROUP BY a.url
  14. Addressing an array element like above $subject[id] causes an additional operation for the php parser. Without quotes around the key name, php will check to see if there is a constant with that name set, if it finds one, it will return the wrong value...if it doesn't then it will check to see if there is an element in the array with that key. It's not wrong per se, but I wouldn't recommend it.
  15. Do the query like normal, but catch the error... $query = "INSERT INTO tablename (col1, col2) VALUES ('a', 'b')"; @mysql_query($query); $error = mysql_errno(); if ($error > 0 && $error == 1022) { echo "Duplicate entry skipped"; } else if ($error > 0 && $error != 1022) { echo mysql_error(); } else { echo "Added!!"; } make sure that column "xy" is a PK or has a unique index.
  16. I suppose that it isn't necessary to declare a function public, since according to the manual a method without a declaration is automatically public (http://us2.php.net/manual/en/language.oop5.visibility.php#language.oop5.visiblity-methods). I do it mostly for consistency, and also because I suppose that I'm slightly OCD. Remove the public / protected from the vars and methods, and change the function named "__construnct" to the name "foo".
  17. Here is the general idea: <?php include 'header.php'; ?> <div id="content"> <div id="columnsC"> <img style="border:0;" src="siteimg/stixy.jpg" alt="stixy"/><Br/> <p> Stixy helps users organize their world on flexible, shareable Web-based bulletin boards called Stixyboards. Unlike most personal productivity or project management software, Stixy doesn't dictate how users should organize their information. Users can create tasks, appointments, files, photos, notes, and bookmarks on their Stixyboards, organized in whatever way makes sense to them. Then they can share Stixyboards with friends, family, and colleagues. </p> </div> <div id="columnsD"> <?php if ($session->logged_in) { $dbh = mysql_connect ("localhost", "my_user", "my_pass") or die (mysql_error()); mysql_select_db ("my_db"); if (base64_decode($_GET['stixy']) != "" && $_GET['delete'] == "true") { $query = "DELETE FROM stixy WHERE stixy = '" . base64_decode($_GET['stixy']) . "'"; mysql_query($query) or die(mysql_error()); echo "Stixy " . base64_deocde($_GET['stixy']) . " was deleted!!"; } if ($_GET['remove'] == '1'){ $sql = "DELETE FROM emailists WHERE stixy = '" . $session->userinfo['email'] . "'"; if (mysql_query($sql)){ echo '<div id="mes"><ul><li>email address removed</li></ul></div>'; } else { echo mysql_error(); } } if (isset($_GET['insert']) && $_GET['insert'] == 1) { $sql = "SELECT count(stixy) FROM emailists WHERE stixy = '" . $session->userinfo['email'] . "'"; if ($result = mysql_query($sql)) { if (mysql_result($result, 0) == 0) { $sql = "INSERT INTO emailists (stixy) VALUES ('" . $session->userinfo['email'] . "')"; if (mysql_query($sql)){ echo '<div id="mes"><ul><li>email address added</li></ul></div>'; } else { echo mysql_error(); } } else { echo "<div id='mes'><ul><li>email address already exists</li></ul></div>"; } } else { echo mysql_error(); } } $result = mysql_query("SELECT COUNT(stixy) FROM emailists WHERE stixy = '" . $session->userinfo['email'] . "'"); if (mysql_result($result, 0) == 0) { echo "<ul><li><a href='stixy.php?remove=1'>Remove yourself from the list</a></li></ul>"; } else { echo "<ul><li><a href='stixy.php?insert=1'>Add yourself to the list</a></li></ul>"; } $sql = "SELECT stixy FROM emailists"; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) > 0) { echo "<ul>"; while ($row = mysql_fetch_assoc($result)) { echo ' <li> ' . $row['stixy'] . ' <a href="' . $_SERVER['PHP_SELF'] . '?stixy=' . base64_encode($row['stixy']) . '&delete=true"' . ' onclick="return confirm(\'Are you sure?!?!\');">Delete</a> </li>'; } echo "</ul>"; } } else { echo ' <p style="border-style: solid; border-width: 3px;">some text here</p>'; } ?> </div> <?php include 'sidebar.php'; ?> <div style="clear: both;"> </div> </div> <?php include 'footer.php'; ?>
  18. If there is a second xy equal to 12, do you want it to update that row? Or change xy to be something unique?
  19. <?php class foo { public var $bar; protected function __construct () { $this->bar = new bar(); } } class bar { public function foo_bar() { return "FUBAR (F'd Up Beyond All Repair)"; } } $blah = new $foo; echo $blah->bar->foo_bar(); ?>
  20. It's calling the function "var()" inside of the object "var" which was created inside of the object "var"
  21. Use javascript This will get you MANY.... http://www.google.com/search?hl=en&safe=off&q=javascript+WYSIWYG+text+editor&btnG=Search
  22. Only MyISAM supports transactions and foreign keys. Locking is a part of any and every database engine.
  23. You're using double quotes inside of double quotes... change $page_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$subject["id"]}",$connection); to $page_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$subject['id']}",$connection);
  24. You aren't listening to what Thorpe, among others, has told you. That 8ms overhead is necessary for your webserver to connect to the db server via the network. It has to send the username/password combo then receive confirmation of successful login. It will always be there. mysql_pconnect is only available if you are using a module version of php. http://us.php.net/manual/en/features.persistent-connections.php I'm guessing that you aren't running php as a module, which means mysql_connect and mysql_pconnect act exactly the same. If you want to reduce that 8ms, which most likely isn't possible, improve your network speed...if your using 100Mbps, go to 1Gb, if your using 1Gb go to 10Gb.
  25. This should get you started. Table structure for my example; categories table: cat_id cat_name users table: user_id user_name user_categories table: cat_id user_id This will display all the users and categories as checkboxes, if the user already has that category, it's already checked... $query = "SELECT * FROM categories"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $cats[$row['cat_id']] = $row['cat_name']; } $query = "SELECT user_name, cat_name " . "FROM user_categories uc " . " LEFT JOIN users u ON u.user_id = uc.user_id " . " LEFT JOIN categories c ON c.cat_id = uc.cat_id " . "ORDER BY user_name, cat_name"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $user_data[$row['user_name']][] = $row['cat_name']; } echo ' <form method="post"> <table>'; foreach ($user_data as $user => $user_cats) { echo ' <tr> <th colspan="' . count($cats) . '">' . $user . '</th> </tr> <tr>'; foreach ($cats as $cat) { echo ' <td> <input type="checkbox" name="user_cats[' . $user . '][]" value="' . $cat . '" ' . (in_array($cat, $user_cats) ? 'checked="checked"' : '') . '> </td>'; } echo ' </tr>'; } echo ' <tr> <td colspan="' . count($cats) . '"><input type="submit" name="submit" value="Save"></td> </tr> </table> </form>'; When the form is posted it will create a multidimensional array that can be looped through and the data saved to the database...in this example, since all users are displayed and updated at the same time, you could truncate the user_categories table, then just do inserts. Alternatively, you'd have to check each users categories, then do updates / deletes as necessary. Do a print_r on $_POST to see what it looks like, which should help with how to do the looping.
×
×
  • 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.