Need help with my first php script

Discussion in 'PHP' started by krabople, Mar 25, 2007.

  1. #1
    Hi, I have just attempted my first php script. The script is designed to take information passed from a form on the page before it and then append it into a table in a database. However, when I run it I don't get any error messages or anything, just a blank screen. When I check the database it hasn't updated. Could someone please look through my code and tell me where I'm going wrong? Any advice would be greatly appreciated!
     

    Attached Files:

    krabople, Mar 25, 2007 IP
  2. aredhelrim

    aredhelrim Peon

    Messages:
    7
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Line 32
    Usage Insert :
    You must use "SET" for UPDATE queries.

    // aredhelrim
     
    aredhelrim, Mar 25, 2007 IP
    klown likes this.
  3. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I recommend just adding a bit more to your error detect so it tells the error on the page. You could always disable the error later. Change your code as follows:

    
    //error checking code
    $dbcnx = mysql_connect('localhost', 'user', 'password');
    if (!$dbcnx ) {
       die('Connection error: ' . mysql_error());
    }
    
    /*Old Code
    $dbcnx = @mysql_connect('localhost', 'user', 'password');
    if (!$dbcnx) {
    	exit('<p>Unable to connect to the database server at this time.</p>');
    }
    if (!mysql_select_db('mydb')) {
    	exit('<p>Unable to locate the krabople database at this time.</p>');
    }*/
    
    PHP:
    Then again the problem might not be in your connection. So change the code down here..

    
    //Error Detection Code
    $result = mysql_query($sql);
    if (!$result) {
       die('Invalid query: ' . mysql_error());
    }
    
    
    /*
    Old Code
    if(@mysql_query($sql)) {
    	echo '<p>Your registration was successful!</p>';
    	} else {
    	echo '<p>There was an error while processing your registration: ' . mysql_error() . '</p>';
    	}
    }*/
    
    PHP:
    This should allow you to figure it out yourself.. If you still have a problem post a bit more about it along with the error code.
     
    klown, Mar 25, 2007 IP
  4. krabople

    krabople Member

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #4
    Hi, thanks for the advice. However, I have tried changing the code as suggested and nothing happens. The annoying thing is that there is no error message whatsoever, just a blank screen. I know that php is definitely working on my computer as I have tried deleting everything and just displaying variables using the echo command. Any idea why the screen might be completely blank? If I miss a bracket or something it tells me there is an error but it is not doing that so I presume the problem is not with the syntax
     
    krabople, Mar 25, 2007 IP
  5. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #5
    if you changed the code as I suggested you should be getting an error message. Unless you had a PHP error I didn't notice.. You are accessing the php code from within a PHP server right?

    Anyhow I'm sure your doing that so I would advise you to turn on your local error reporting by modifying your php.ini file. You can find documentation on that here at php.net
     
    klown, Mar 25, 2007 IP
  6. Robert Plank

    Robert Plank Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Says who? I avoid VALUES like the plague... SET is more readable and will work for update and insert.
     
    Robert Plank, Mar 25, 2007 IP
  7. krabople

    krabople Member

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #7
    Hi, thanks a lot for your help - the answer did lie in the php.ini file. I just needed to unremark the mysql.dll line - I thought I had done it but I'd done the wrong one. Code works fine now.
     
    krabople, Mar 26, 2007 IP