Jump to content

jaikob

Members
  • Posts

    68
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jaikob's Achievements

Member

Member (2/5)

0

Reputation

  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.
×
×
  • 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.