Thread: Php

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    169

    Php

    is there a way to get user input into variables with php using only one file (ie have the form to input the data and process it in one document instead of "POST"ing to a seperate document)

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Yes?

    I don't know the full rhetoric off the top of my head but it's a simple case of dealing with the $_POST superglobal. If there's nothing in it, user hasn't posted, otherwise do the usual cutting up into little bits and enjoy.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Sure. Just POST to yourself. In the document, check either if the request method is POST ($_SERVER['REQUEST_METHOD'] == 'POST') or if the variables are available (isset($_POST['whatever']). Do your processing depending on this.

    But let me tell you, that's not pretty. Separating is better.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    169
    another thing im trying to stab at is this fancy mysql database output im trying to do if anyone thinks they could help (im new at php and mysql). Im trying to make my own automatied FAQ system. theres 4 fields for each row but thats not important
    Code:
    $result = mysql_query("SELECT * FROM faq");
                             if (!$result)
                             {
                               $errorreport="3faq printing out faq";
                               echo($errormessage);
                             }
                             else
                             {
                               $highestID=0;
                               $contentSize=0;
                               $contentPrinted=0;
                               while($row = mysql_fetch_array( $result ))
                               {
                                 if($row['ID'] > $highestID)
                                 {
                                   $highestID=$row['ID'];
                                 };
                                 $contentSize=$contentSize+1;
    
                               }
                                
                               echo($highestID);
    
                               while($row = mysql_fetch_array( $result ))
                               {
                                 echo "<p>Question: ";
                                 echo $row['Question'];
                                 echo "<br>Answer: ";
                                 echo $row['Answer'];
                                 echo "</p><br>";
                               }
    the problem is it only processes the first "while($row = mysql_fetch_array( $result ))" part correctly, the 2nd one doesnt do anything. if i switch them around in order the new first one works but not the 2nd one.
    i think the problem is it doesn't look down through each row starting from the begining on the 2nd while loop, is there some kind of command to "reset" the "cursor"?

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    169
    Quote Originally Posted by CornedBee
    Sure. Just POST to yourself. In the document, check either if the request method is POST ($_SERVER['REQUEST_METHOD'] == 'POST') or if the variables are available (isset($_POST['whatever']). Do your processing depending on this.

    But let me tell you, that's not pretty. Separating is better.
    yeh i guess your right its alot easier to just seperate it

  6. #6
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Quote Originally Posted by MisterSako
    i think the problem is it doesn't look down through each row starting from the begining on the 2nd while loop, is there some kind of command to "reset" the "cursor"?
    Until someone more experienced answers, execute the query again. Perhaps if you just made the first one grab the "ID" field it wouldn't look so damn spaghettio.

    EDIT: mysql_data_seek
    Last edited by SMurf; 02-19-2006 at 02:49 PM.

  7. #7
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    I've got a database script using PHP/MySQL that manages customer information. So far it's about 1,500 lines so I'll just give you a zip link if you think it'll help.

    Here's a preview:

    http://bookmarkhosting.com/tool/

    It is being worked on though so it's a WIP. Can't be much help to offer support, maybe it'll help you somehow. If not, I tried,
    Last edited by Shadow; 02-19-2006 at 07:43 PM.
    The world is waiting. I must leave you now.

  8. #8
    Registered User
    Join Date
    Jul 2004
    Posts
    169
    yes that i think would help alot please zip it up for me :}
    thanks

  9. #9
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    One thing we use on the forum project I'm involved in is seperating data collection with display. So you would gather the information and store it and display it later. When large amounts of data is possible we use a call back function to get one part of it at a time. However its still seperated into the gathering and displaying part.

  10. #10
    Registered User
    Join Date
    Jul 2004
    Posts
    169
    agh what am i doing wrong???

    http://mrsako.gotdns.com/backupwithlogin.php

    right below the body tag i tried to do this

    <?php
    include("loginsystem/include/session.php");
    ?>

    why does it just write it all to the screen? on my faq section (scroll super alot down and click FAQ) i have php embded within my page there (but not a include file) and it works fine so i know i have PHP and mysql installed correcctly. this is whats in the session.php file
    i tried putting php after <? but it just made the entire site not show up except for the include stuff
    PHP Code:
    editi took this code out because it was a waste of 200 lines 
    btw shadow if i'd still muchly appreciate that zip file :}
    Last edited by MisterSako; 02-21-2006 at 01:35 AM.

  11. #11
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Wow, you're that experienced with PHP that you're working with classes straight away? You need groupies, seriously.
    Quote Originally Posted by MisterSako
    i tried putting php after <? but it just made the entire site not show up except for the include stuff
    I think you'll find it's not optional. Please don't try that "Oh but it works... better!" argument.

    It's time you learnt the greatness that is PHP debugging, a.k.a. put echo "Ran to here"; statements EVERYWHERE!

  12. #12
    Registered User
    Join Date
    Jul 2004
    Posts
    169
    nah i got it from here
    http://evolt.org/node/60384

    if someone else made what i need i dont think i should spend the time making my own :-p

    i tried putting <?php where the guy put just <? but it seemed to not like doing that

    i just foud ever <? and made it a <?php

    im getting there
    Last edited by MisterSako; 02-20-2006 at 02:25 PM.

  13. #13
    Registered User
    Join Date
    Jul 2004
    Posts
    169
    edit: i got this all figured out now, it turns out the author is a little bit of an idiot

    i might end up not using his code itll probally just be brining me in the wrong direction
    Last edited by MisterSako; 02-20-2006 at 02:51 PM.

  14. #14
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    <? is allowed in place of <?php if short_open_tag has been enabled in php.ini

    If it has not then you can not use it.

  15. #15
    Registered User
    Join Date
    Jul 2004
    Posts
    169
    alright im stuck once again. i started all over and ditched that other guys login system

    i have finished making my own system in which you can login and register
    ( http://mrsako.gotdns.com/index.php )
    its pretty nifty you can even try it if youd like.

    how it works lets say your logging in you type in the information on login.php and you hit submit and it gets processed in a different .php file. and then it sends you back to the site after logging you in. or it sends you back to login.php if you had a wrong username or password. what i want to do is be able to have some text coming up saying "invalid username or password" is there a way i can do this with variables by having the processing php file assign $errormsg="bad uname or pass"; then have login.php echo(errormsg);
    or do i have to do something like login.php?error=1
    im not going to use cookies though thats just dumb, id rather do the login.php?error=1 method
    Last edited by MisterSako; 02-21-2006 at 01:44 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. combining c php and mysql
    By Thoth in forum C Programming
    Replies: 2
    Last Post: 01-30-2009, 10:55 AM
  2. PHP installation
    By ssharish2005 in forum Tech Board
    Replies: 8
    Last Post: 11-23-2007, 09:42 PM
  3. PHP on my Computer!
    By xxxrugby in forum Tech Board
    Replies: 4
    Last Post: 03-15-2005, 09:34 AM
  4. C++ and PHP communication
    By Korhedron in forum Game Programming
    Replies: 4
    Last Post: 01-12-2004, 06:37 AM
  5. PHP 4.3.0 released
    By codingmaster in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-30-2002, 07:40 AM