Jump to content

jaikob

Members
  • Posts

    68
  • Joined

  • Last visited

    Never

Everything posted by jaikob

  1. You could just do something like this.... <?php function performMySQLBatchJobs($jobArray) { $jobsPerformed = 0; $isValidResult = true; foreach($jobArray as $job) { if($isValidResult) { $isValidResult = mysql_query($job); $jobsPerformed++; } else { break; } } return ($jobsPerformed - 1); } $batchJobs = array("INSERT INTO `test` (`col`) VALUES 'val';", "INSERT INTO `test` (`col`) VALUES 'val';", "INSERT INTO `test` (`col`) VALUES 'val';"); $numberOfJobsDone = performMySQLBatchJobs($batchJobs); echo $numberOfJobsDone." Out of ".count($batchJobs)." Performed."; ?> In this case you would also need to delete your queries if they are chained like that. Your queries shouldn't break though, that's poor programming. Perform checks before executing the query.
  2. Use stripslashes() http://php.net/manual/en/function.stripslashes.php
  3. jaikob

    Yo!

    <?php session_start(); if(!isset($_SESSION['logged_in'])) { $_SESSION['logged_in'] = false; } if($_SESSION['logged_in'] == false) { if($_SERVER["REQUEST_METHOD"] == "POST") { $username=mysql_real_escape_string($_POST['username']); $password=mysql_real_escape_string($_POST['password']); $password=md5($password); $sql="SELECT xx FROM xx WHERE username='$username' and password='$password'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1) { $_SESSION['logged_in'] = true; header("Location: ".$_SERVER['PHP_SELF']); } else { echo 'Sorry! The details you provided were incorrect, please try again...'; } } } else { // Use it here instead echo 'This part is only visible if logged in!'; } ?> <?php if($_SESSION['logged_in'] == false) { ?> <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'> Username: <input type='text' name='username' class='input'> Password: <input type='password' name='password' class='input'> <input type='submit' value='Login' class='input'> </form> <?php } ?> In theory the above will work. It may need a little modification as I have not tested it.
  4. There is no possible way to separate the data without checking every character and setting standards. You could try a CSV. You can save as a CSV in Excel and PHP has a wide array of functions to natively read CSV files. Edit.... Unless, the excel file is separated by a comma and a tab. in theory I think you can use explode() and use ",\t" as your delimiter.
  5. Are you trying to allow a user to log back in with the old password after they have changed it? If so you are executing a new query, and in turn the query is returning the new password, so your if statement is not going to validate the old password == new password.
  6. jaikob

    unlink()

    Whoops. I got my code mixed up, use this: <?php $row = mysql_fetch_assoc($result); ?><?php do { ?> <?php } while($row = mysql_fetch_assoc($result)); ?>
  7. jaikob

    unlink()

    use $result. The code I posted earlier sets your query to $result, not $result1 or $sql. </tr><?php while($row = mysql_fetch_array($result)) ?> And if you haven't solved your error earlier, use a do while loop. Example: <?php do { ?> // Table code here <?php } while($row = mysql_fetch_assoc($result1)); ?> If you do the above you also need to set $row. Put the variable declaration before your loop. $row = mysql_fetch_assoc($result);
  8. jaikob

    unlink()

    The code you provided was real ugly, try this (replace your header PHP with the below): <?php // Set Global Vars $HOST = "YOUR_HOST_HERE"; $USERNAME = "MYSQL_USERNAME"; $PASSWORD = "MYSQL_PASSWORD"; $DATABASE = "testdocs"; $TABLE = "docs"; // Establish a connection mysql_connect($HOST, $USERNAME, $PASSWORD) or die(mysql_error()); mysql_select_db($DATABASE) or die(mysql_error()); // Query for results if(!isset($_POST['delete'])) { $sql = "select * from `$TABLE` order by `id`;"; } else { $DELETE_ID = mysql_real_escape_string($_POST['delete']); $result1 = mysql_query("select * from `$TABLE` where `id` = '$DELETE_ID';"); $row = mysql_fetch_assoc($result1); mysql_close($result1); // Delete the file on the disk unlink('../admin/docs/'.$row['Download']); // Build your query, kind of weird but alright. $sql = "delete from $TABLE where "); for($i=0;$i<count($_POST['checkbox']);$i++){ if($i != 0) { $sql.= "AND "; } $sql .= " id='" . $_POST['checkbox'][$i] . "'"; } $result = mysql_query($sql); if(isset($_POST['delete'])) { header('Location: index.php'); exit; } } ?>
  9. use rand(). <?php $random_number = rand(); ?> To be specific about the number length, read the manual entry for rand on php.net. What a lot of people do is create an id field and set it as a primary key with auto increment enabled. That way you don't even have to mess with the id. But you have stated you don't want repetition. The reason a lot of others do this is because with rand you always have the slight possibility of trying to insert a number you have already used. Especially if your using a primary key.
  10. I'm fetching files from a directory and searching those with the regex. Yes you have helped me big time and thank you!
  11. Thank you! Sorry if it was a problem.
  12. Works almosttt perfect except if I have a file name of: John, Doe., Ph.D, T, 1.4.11.pdf It does not match it :/ other than that it works perfect!
  13. Yes exactly, I really appreciate your help because I suck at regexp and I have no ambition to learn how to use it correctly haha.
  14. It also doesn't acknowledge if there is punctuation after the file name, and capitalization. Test.css Test, Test.css Will not match.
  15. I'm trying to create a regex to search a blob of files. I have this as regex: $param = "test"; $reg = "\b".$param.".(\w*)(\w|[-.])+$"; It currently will return the result if the filename starts with test, but it does not acknowledge the position of the keyword, and if the filename contains multiple words and spaces. So if I have test1.css test2.css test copy.css test copy with more words.css copy test.css It will only return test1.css, test2.css, and test copy.css. How can I fix this regex to work the way I want it? Thank you.
  16. haha thanks for the refresher.
  17. Maybe I've been away from PHP too long, but my senses tell me this SHOULD work. $ip = $_SERVER['REMOTE_ADDR']; if(($ip != "XX.XXX.XX.XX") || ($ip != "XX.XXX.XX.XX") || ($ip != "XX.XXX.XX.XX")) { mail("....................................."); } The dots represent params in mail function. This somehow returns true everytime. The XX's represent frequent IP's. What is wrong?
  18. I think we are now getting too complicated. A user posts a message, and he says "hello @jaikob how are you?" I want the @usernames to be linked. I don't want to seperate all @usernames and have a different string for each one, I have an original string, and I want to replace all @usernames in that string with @<a href="profile/username">username</a> So If I passed parseShout("hello @jaikob how are you?"); parseShout will return: "hello @<a href="profile/jaikob">jaikob</a> how are you?" Thanks for your assistance, I just keep having issues finding and replacing in a string basically.
  19. Yes, it is a leg further , but I need the original string to be there too. Thanks a lot for helping me out. so it would be like "Hello @<a href="profile/jaikob">jaikob</a> how are you today? @<a href="profile/george">george</a>"
  20. Both the results and the replacements are stored into an array. Yes I would like to replace all @relies with their convertToLink counterparts
  21. Actually... The convertToLink would be this. mysql is not needed. function convertToLink($user) { $profile = "/profile/$user"; return "@<a href=\"".$profile."\">".$user."</a>"; }
  22. I'm trying to craft a function to pull @ replies from a string, and I somehow cant get str_replace to work. Here is my code: <?php function convertToLink($user) { $profile = "/profile/"; $query = "SELECT * FROM users WHERE username = '$user' LIMIT 0,1"; $result = mysql_query($query); $row_user = mysql_fetch_assoc($result); $row_Total = mysql_num_rows($result); return "@<a href=\"".$profile.$row_user['username']."\">".$user."</a>"; mysql_free_result($result); } function parseShout($input) { $val = array(); $tags = array(); $shout = $input; preg_match_all("#@[a-z0-9]+#i", $input, $tags); foreach ($tags as $val) { for ($i=0;$i<count($val); $i++) { // Store our changes into an array $val[$i] = convertToLink(substr($val[$i], 1, 20000000)); }} // $val holds all new replacements // $tags holds old values return str_replace($tags, $val, $shout); } ?> an example usage would be: <?php echo parseShout("Hello @jaikob how are you today?"); ?> But when I execute that, It just returns the string without replacing anything. if I do a print_r($val); and print_r($tags); they print the correct array/values. Any clues as to what I'm doing wrong?
  23. Thank you all for the help!
  24. I'm trying to program @ notation, like twitter does. For now I'm just literally learning about regex, and have no clue on what do do to achieve what I want. I am using preg_match for now until I get my regex right. How can I parse a string and pull out all of the @username's. Ex: preg_match('regex crap', "Hello @jaikob How are you?", $matches); Thanks!
×
×
  • 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.