Results 1 to 9 of 9

Thread: Why? PHP & SQL almost always doesnt work initially.

  1. #1
    Squeeler Vini's Avatar
    Join Date
    Jul 2003
    Location
    Sheffield
    Posts
    1,769
    Thanks
    44
    Thanked
    8 times in 8 posts

    Why? PHP & SQL almost always doesnt work initially.

    Im testing new codes/scripts. and ive had this problem before, but it just started working without intervention i think... but why is it that when i try and write to a DB in mysql does it never work - first time up.

    ive walked through this and tried to register, and it says:

    Code:
    You have successfully registered with:
    
    Username: 
    Password:
    after username you would expect it to Echo the username ive registered, and password the same. but nothing, and it hasnt written to the DB...

    this has puzzled me before, but i ignored it... but its back again.. why?

  2. #2
    Squeeler Vini's Avatar
    Join Date
    Jul 2003
    Location
    Sheffield
    Posts
    1,769
    Thanks
    44
    Thanked
    8 times in 8 posts
    [quote name='shocker-z' post='350673' date='Mar 1 2006, 11:39 AM']
    just paste the scripts here then and we will have a look thru them for you mate
    [/quote]

    they can be grabbed all together in a rar -> here

    or viewed as textualisation files (.txt ) -> here

  3. #3
    Bigger than Jesus Norky's Avatar
    Join Date
    Feb 2005
    Posts
    1,579
    Thanks
    1
    Thanked
    8 times in 8 posts
    Probably to do with globals

    User Name: <?php echo $Name ?>
    <BR>
    Password: <?php echo $Password ?>

    These variables should all be $_POST['Name'] $_POST['password'] etc., and same with the query

  4. #4
    Squeeler Vini's Avatar
    Join Date
    Jul 2003
    Location
    Sheffield
    Posts
    1,769
    Thanks
    44
    Thanked
    8 times in 8 posts
    Quote Originally Posted by Norky
    Probably to do with globals

    User Name: <?php echo $Name ?>
    <BR>
    Password: <?php echo $Password ?>

    These variables should all be $_POST['Name'] $_POST['password'] etc., and same with the query

    could someone just pop into a little more detail on that? the scripts are still above for viewing if thats of any help... once ive been shown once, im sure i could work therest out.

  5. #5
    Senior Member
    Join Date
    Nov 2005
    Posts
    500
    Thanks
    0
    Thanked
    0 times in 0 posts
    At the top of the page (right at the top of the PHP) put this...

    $Name=$_POST['Name'];
    $Password=$_POST['Password'];
    $News1=$_POST['News1'];
    $News2=$_POST['News2'];
    $Weather=$_POST['Weather'];

    Seriously, even if it's only for internal usage turn register_globals off. Never use it, forget you ever heard about it. Use $_POST or $_GET instead and assign as above.

  6. #6
    Squeeler Vini's Avatar
    Join Date
    Jul 2003
    Location
    Sheffield
    Posts
    1,769
    Thanks
    44
    Thanked
    8 times in 8 posts
    Quote Originally Posted by GDVS
    At the top of the page (right at the top of the PHP) put this...

    $Name=$_POST['Name'];
    $Password=$_POST['Password'];
    $News1=$_POST['News1'];
    $News2=$_POST['News2'];
    $Weather=$_POST['Weather'];

    Seriously, even if it's only for internal usage turn register_globals off. Never use it, forget you ever heard about it. Use $_POST or $_GET instead and assign as above.

    its off. and im working towards fixing it, but... what exactly do i replace?

    ive tried looking at another script ive pieced together which does the above, and got to:

    PHP Code:
    ### Set DB Variables ###
    $db_host 'localhost' ;
    $db_user 'vini' ;
    $db_pass 'ddddddd' ;

    ### Get Form Info and Assign Variables ###
    $frm_name = isset($_POST[name]) ? $_POST[name] : '' ;
    $frm_password = isset($_POST[password]) ? $_POST[password] : '' ;
    $frm_news1 = isset($_POST[news1]) ? $_POST[news1] : '' ;
    $frm_news2 = isset($_POST[news2]) ? $_POST[news2] : '' ;
    $frm_weather = isset($_POST[weather]) ? $_POST[weather] : '' ;
    $frm_friday = isset($_POST[friday]) ? $_POST[friday] : '' ;


    ### Connect to DB ###
    $db_connect mysql_connect($db_host$db_user$db_pass) or die("Unable to connect to database") ;

    ### Select DB ###
    $db_select mysql_select_db('users') or die("unable to select database") ; 
    but im still lost, not sure where it would go in my existing 3 php files, and what i would edit/replace.
    Last edited by Vini; 02-03-2006 at 03:36 PM.

  7. #7
    Senior Member
    Join Date
    Nov 2005
    Posts
    500
    Thanks
    0
    Thanked
    0 times in 0 posts
    As I said, insert the lines I gave you at the top of the page your form submits the data to.

  8. #8
    Squeeler Vini's Avatar
    Join Date
    Jul 2003
    Location
    Sheffield
    Posts
    1,769
    Thanks
    44
    Thanked
    8 times in 8 posts
    Quote Originally Posted by GDVS
    As I said, insert the lines I gave you at the top of the page your form submits the data to.
    it really was that simple.

  9. #9
    Senior Member
    Join Date
    Nov 2005
    Posts
    500
    Thanks
    0
    Thanked
    0 times in 0 posts
    Of course it was

    All that was missing from your version was the 's round the array element names ($_POST[password] should be $_POST['password']).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. unreals WHOLE A-Level Art work collection (56k=kbye)
    By unreal in forum Consumer Electronics
    Replies: 42
    Last Post: 05-07-2011, 05:23 PM
  2. Making PHP and MySQL Talk?
    By Dav0s in forum Software
    Replies: 4
    Last Post: 18-09-2005, 10:53 PM
  3. Replies: 13
    Last Post: 30-07-2005, 06:15 PM
  4. Work so far
    By Maldonado in forum Automotive
    Replies: 43
    Last Post: 11-01-2005, 02:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •