Jump to content

trinaryoc

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Posts posted by trinaryoc

  1. //if there is, it logs you in and directes you to the members page
    $_POST['username'] = $_SESSION['username'];
    $_POST['password'] = $_SESSION['password'];
    $_SESSION['username'] = $username;
    $_SESSION['password'] = $password;
    

     

    I'm not following your logic here (top of your script)... after checking ISSET $_SESSION variable you set you $_POST variables to the $_SESSION variables.... ok, weird but ok... then you clear them by equating the $_SESSION to the undefined variables $password and $username? This right here might be your problem, your script would allow the user through to index.php but would have cleared out your $_SESSION variables. Looks like you have the same issue later on in your script as well.

     

    Also you only need the one session_start(); at the beginning...

  2. Hi, I am new in PHP World, so please help me with the following problem. I have a HTML form which looks like the following..let’s say diagram. The DAY column is fixed, Sunday, Mondays..are just labels. I want my users to pick IN Time and OUT Time for different days and then select ON from dropdown list if they have picked any time, or otherwise select OFF. After submission I want these information to be saved in a table named "Attendance" and want to display the information later. Now would you please kindly tell me the PHP scripts for this and how would be the database table structure? 

     

    Do you really need the "On" and "Off" flag? seems redundant. If they have entered times shouldn't they be considered "On" already? unless you want to add someone on the schedule with zero hours. Seems to me that a the table should only require Entry Id (instead if a single column Primary Key, you could also do a combination of User and Date to create a unique primary key), User, Date, Time In, Time Out, (breaks???). One thing you need to consider when you design your table is to think of growth. While you might just need a set Sun-Sat calendar at this moment, what happens of you need to change in the future? And if you do change the schedule, wouldn't it be nice to be able to see what the user had as an old schedule?

     

    As to the PHP script... Entry from HTML Forms into SQL is very simple to accomplish, W3schools should have everything you need to create that script. You're looking at maybe a dozen lines of code to be off and running. Start writing it up and post to us what you come up with and we'll guild you in the right direction.

  3. hey change your button type to "type='submit'" and that should fix your issue...

    Edit:

    Yeah just tested it... change your button type.... But now after the submit you're getting :

    Parse error: syntax error, unexpected T_START_HEREDOC in D:\Hosting\7467142\html\spark\contactformprocess.php on line 32
  4. There's a sticky about Headers... but basically... you cant have any output to the user populate before altering a header because once you echo anything a header is automatically generated. you can buffer your output if you'd like but that's kinda dirty....

     

     

  5. try in this way

    echo "<form action='editevent.php' method='get'><input type='hidden' name='eventid' value='{$row['eventid']}'><INPUT TYPE='submit' name='submit' VALUE='Edit'></form>\n";

     

    Thats exactly what i was thinking. But to be honest... why dont you just create a button looking [a] in CSS... obviousily you're only doing this to get the button look.... you could also just create a button and add an onClick() to it. That would be my first choice. ether way you dont need to create a FORM.

     

    echo "<input type=button onClick=\"location.href='editevent.php?eventid=".$row['eventid']."'\" value='Edit'>";

  6. Hi,

     

    How can I get it to show the Username instead of the userid.

     

    The Username is stored in a different Table in the database:

     

    CREATE TABLE `user` (
      userid int(10) unsigned NOT NULL auto_increment,
      username varchar(100) collate utf8_unicode_ci NOT NULL default '',
      PRIMARY KEY  (userid),
      KEY username (username),
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2 ;
    
    --
    -- Dumping data for table 'user'
    --
    
    INSERT INTO `user` (userid, username) VALUES (1, 'Admin');
    

     

    <?php
    
    
    $check = tep_db_query("SELECT t.userid AS 'userid', count(t.ticket) AS 'tick_qty', u.username AS 'username' FROM tickets AS 't' JOIN users AS 'u' ON t.userid = u.userid GROUP BY userid");
    
    while ($ticket = tep_db_fetch_array($check))
    
    {
    ?>
    <div><?php echo $ticket['userid']; ?></div>
    <div><?php echo $ticket['username']; ?></div>
    <div><?php echo $ticket['tick_qty'];?></div>
    <?php
    
    }
    ?>
    

     

    I'm worried that my syntax might be off... i dont know TEP databases at all. But that should work.

  7. Try this out:

     

    SELECT CAST(CONCAT_WS("-", year, day, month) AS DATE) as 'ymd' FROM calendar_event GROUP BY ymd ORDER BY ymd ASC

     

    will give you a date output as a data type DATE and that's easy enough to ORDER BY. there's other ways to do it but that's a quick and dirty one.

     

    persionaly if you cant adjust the table, I'd create a VIEW and with the CASTed CONCAT instead of the year, month, day, so you dont have to run the CAST and CONCAT everytime time you need to sort by dates

  8. Hey all. Kinda new to PHP. Better versed in SQL, Perl, and C++. But started dabling in PHP when my boss tossed a project my way that was already started in PHP. been crawling these forums for the past few months, figured i'd join up.

  9. Why would you loop through the entire $_POST array with the same 'filter', when not all data needs the same sanitization, and some, such as values that will be hashed, needs none at all? and as it appears, each of OP's $_POST variables are user entered data.

    Because it's a single line of very simple code. simpler then singling out each $_POST variable that need filtering. you can design the function however you wish.

     

    a simple filter finction for this application could be something like this:

     

    function filter($data) {
    $data = trim(htmlentities(strip_tags($data)));
    
    if (get_magic_quotes_gpc())
    	$data = stripslashes($data);
    
    $data = mysql_real_escape_string($data);
    
    return $data;
    }
    

     

    What filter would it be that most hosting companies have installed?

    Pre PHP 5.2 you would have had to have installed PECL extention. Post 5.2 it was included within PHP.

     

    What exactly do you feel is wrong with mysql_real_escape_string()?

    mysql_real_escape_string only alters for escape charactors, doesnt touch any code that might have been inserted in the text area. and i didnt say not to use it, i daid not ONLY use it.

     

    Using or die( mysql_error() ) is a bad idea, especially on a live, production server.

    This was for diagnostics... OP thought he was having issues on his INSERTS

  10. Try this:

    <?php
    
    
    $check = tep_db_query("SELECT userid, count(ticket) AS 'tick_qty' FROM tickets GROUP BY userid);
    
    while ($ticket = tep_db_fetch_array($check))
    
    {
    ?>
    <div><?php echo $ticket['userid']; ?></div>
    <div><?php echo $ticket['tick_qty'];?></div>
    <?php
    
    }
    ?>
    

     

    if you're running MySQL replace tep_db_ with mysql_

  11. This might work for you but your folder permissions need to be set to 755.

     

    <?php
    $tmp1 = array();
    $tmp = array();
    
    $AccountNumber = "00040";
    $myFile = "yourfile.xml"
    $fh = fopen($myFile, 'a') or die("can't open file");
    
    
    if ($AccountNumber == 00040)
    {
    $tmp1[] = "<ACCOUNT_NO>";
    $tmp1[] = "Account Number is 00040";
    $tmp1[] = "</ACCOUNT_NO>\r\n";
    }
    else
    {
    $tmp1[] = "<ACCOUNT_NO>";
    $tmp1[] = "Account Number is not 00040";
    $tmp1[] = "</ACCOUNT_NO>\r\n";
    }
    
    $tmp = array();
    
    $AccountName = "Microsoft";
    
    if ($AccountName == "Microsoft")
    {
    $tmp[] = "<ACCOUNT_NAME>";
    $tmp[] = "Account Name is Microsoft";
    $tmp[] = "</ACCOUNT_NAME>\r\n";
    }
    else
    {
    $tmp[] = "<ACCOUNT_NAME>";
    $tmp[] = "Account Name is not Microsoft";
    $tmp[] = "</ACCOUNT_NAME>\r\n";
    }
    
    fwrite($fh, $tmp1);
    fwrite($fh, $tmp);
    
    fclose($fh);
    
    ?>
    
    
    

     

    you also didnt define your second array. using "\r\n" will create your line breaks for ya.

    Questions

     

    Do you need arrays to hold your strings?

    Are you really appending or over-writing your file each time?

  12. two things... one, for your own safty filter your user input:

     

    foreach($_POST as $key => $value) {$data[$key] = filter($value);}

     

    most every hosting service has a filter installed.

    dont just use

    mysql_real_escape_string

     

    two: add a die() at the end of your input statements just to make sure that they are working correctly. not knowing how you have your DB_ setup, cant really tell if they're working correctly.

     

    mysql_query(" -- insert query here--") or die(mysql_error());

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