Jump to content

skis

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

skis's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Here's what I'm trying to do: I have a text file with the format password:username and I need to switch it to username:password Sounds simple enough right? Can anyone see what's wrong with the code I wrote below? I'll provide the code and a logical sample of what the output is. #!/usr/bin/php -q <?php if ($argc < 2) { echo "\nusage: $argv[0] inputfilename outputfilename\n\n"; die; } $handle = fopen($argv[1], "r"); $contents = fread($handle, filesize($argv[1])); fclose($handle); $array = explode(":", $contents); $handle = fopen($argv[2], "a"); $i = 0; while ($i < count($array)) { $first = current($array); $second = next($array); next($array); $i = $i+2; fwrite($handle, $second.":".$first."\r\n"); } fclose($handle); ?> Output: user1 password2:password1 user3 password4:user2 password3 user5 password6:user4 and so on... I can't figure out why it's doing this? Can anyone else see the coding error somewhere? Thanks
  2. Nevermind, I got it now. It was because I was sending <html> before the header. Guess I should read stickies...
  3. I cannot find what is wrong here, can someone please help me proofreading my code?
  4. That does work both locally and on the web host. I will continue going over my code to try and figure out why this isn't working.
  5. the exact error is "header didnt work", which is coming from: if ($count == 1 && $admincount == 1) {         $isadmin = "1";         session_register("myusername") or die('session register myusername didnt work');         session_register("mypassword") or die('session register mypassword didnt work');         session_register("isadmin") or die('session register isadmin didnt work');         [b]header("location:queue.php") or die('header didnt work');[/b] } I have tried using an absolute path instead of a relative path for header() and it does the same thing.
  6. I wrote this code and tested it using a local apache install with php5 installed as a module, and I am now trying to use it on my web host's server which uses apache with php4 installed as cgi. On my local server, this code works perfectly fine. When I try it on my webhost's server, it will return "header didnt work" (one of my or die() strings). Does this have something to do with the versions of php or having php running as cgi instead of as an apache module? CODE: correct username and password returns "header didnt work" i only added the or die()'s for debugging. <html> <body bgcolor=#96DCFF> <?php //check if login is correct require('connect.php'); $db_name = "CENSORED"; $tbl_name = "credentials"; $myusername = $_POST['myusername']; $mypassword = $_POST['mypassword']; $sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $checkadminsql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and admin='1'"; $adminresult = mysql_query($checkadminsql); $result = mysql_query($sql); $count = mysql_num_rows($result); $admincount = mysql_num_rows($adminresult); if ($count == 1 && $admincount == 1) {         $isadmin = "1";         session_register("myusername") or die('session register myusername didnt work');         session_register("mypassword") or die('session register mypassword didnt work');         session_register("isadmin") or die('session register isadmin didnt work');         header("location:queue.php") or die('header didnt work'); } elseif ($count == 1) {         session_register("myusername");         session_register("mypassword");         header("location:form.php"); } else {         echo "Wrong Username or Password";         echo "<br><br><a href=\"login.php\">Try Again</a>"; } ?> </body> </html>
  7. thanks a lot, now it all makes sense
  8. I'm beginning to write an IT help request form to better learn how to interact with php and mysql. here is my code: queue.php: <?php //queue for techs require("connect.php"); $query  = "SELECT id, time, username, summary FROM itrequest"; $result = mysql_query($query); while(list($id, $time, $username, $summary)= mysql_fetch_row($result)) {     echo "<tr>" .     "<td><input type=\"checkbox\" value=\"".$id."\" name=\"check".$id."\"></td>" .     "<td>$id</td>" .     "<td>$time</td>" .     "<td>$username</td>" .     "<td>$summary</td>"; } --------------------------------------------------------------- ticket.php (where you go after you check the boxes next to the tickets you want to view and click submit button): <?php //used to view details of ticket(s) require("connect.php"); $_POST = array_flip($_POST); foreach($_POST as $checked => $box){ if($box != "NULL"){ $qid  = "SELECT id FROM itrequest WHERE id = $checked"; $qdate = "SELECT date FROM itrequest WHERE id = $checked"; $qusername = "SELECT username FROM itrequest WHERE id = $checked"; $qsummary = "SELECT summary FROM itrequest WHERE id = $checked"; $qdescription = "SELECT description FROM itrequest WHERE id = $checked"; $id = mysql_query($qid) or die("could not get id from mysql"); $thedate = mysql_query($qdate) or die("could not get date from mysql"); $username = mysql_query($qusername) or die("could not get username from mysql"); $summary = mysql_query($qsummary) or die("could not get summary from mysql"); $description = mysql_query($qdescription) or die("could not get description from mysql"); echo "Ticket ID: $id <br> Date: $thedate <br> Username: $username <br> Summary: $summary <br> Description: $description"; } } ?> ------------------------------------------------------------------ Instead of getting Ticket #: <ticket number here> I am getting Ticket #: Resource #16 and other numbers like that Can anyone see what I am doing wrong?
×
×
  • 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.