Page 1 of 1

Overwrite MySQL database entry problem :(

Posted: Tue Feb 09, 2010 10:17 am
by enter-music
Hey all, this is my first post here as ive only been using php for about a week, and ive come across a minor problem. OK, what i want is one page with a textbox and button for the user to enter their details they want changed (they already have an "account" stored on mysql db. I have another page where the details get sent and (hopefully soon), processed. Im getting a "Unexpected $end" error for the last line, ?> of the second page, i know this means something about brackets, too many or not enough or in the wrong place but i cant figure it out. Any help about general php programming be much appreciated! :)

Page One:

Code: Select all

<html>
<body>
<form id="detailchange" name="detailchange" method="post" action="fnameedit-exec.php">
<?php
 $memid = $_GET["memid"];
 $fname = $_GET["fname"];
 echo "<input type=hidden name=memid value=$memid>";
 echo "<input type=hidden name=fname value=$fname>";
?>
 <p><input type="text" id="detail" name="detail" class="textfield" />&nbsp;<input type="submit" class="button" value="Change"></p>
</form>
 
</body>
</html>
Page Two:

Code: Select all

<?php
    //Start session
    session_start();
    
    //Include database connection details
    require_once('config.php');
    
    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        die('Failed to connect to server:');
    }
    
    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
        die('Unable to select database');
    }
    
    //Sanitize the POST value
    $detail = clean($_POST['detail']);
    $memid = clean($_POST['memid']);
 
                $qry = "UPDATE members SET firstname = '$detail' WHERE member_id = '$memid';
                    session_write_close();
            exit();
?>

Anyone see whats going wrong?

Re: Overwrite MySQL database entry problem :(

Posted: Tue Feb 09, 2010 12:51 pm
by AbraCadaver
Get an editor with syntax highlighting. Also, if you paste it here and set the code tags to code=php, then you should also see your problem:

Code: Select all

    //Start session
    session_start();
   
    //Include database connection details
    require_once('config.php');
   
    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        die('Failed to connect to server:');
    }
   
    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
        die('Unable to select database');
    }
   
    //Sanitize the POST value
    $detail = clean($_POST['detail']);
    $memid = clean($_POST['memid']);
 
                $qry = "UPDATE members SET firstname = '$detail' WHERE member_id = '$memid';
                    session_write_close();
            exit();

Re: Overwrite MySQL database entry problem :(

Posted: Tue Feb 09, 2010 1:10 pm
by enter-music
This may just be me being a bit thick, ive tried what you mentioned but still cant seem to find anything wrong!? I know its just because im new at php but any ideas??

Re: Overwrite MySQL database entry problem :(

Posted: Tue Feb 09, 2010 1:15 pm
by AbraCadaver
enter-music wrote:This may just be me being a bit thick, ive tried what you mentioned but still cant seem to find anything wrong!? I know its just because im new at php but any ideas??
If you look at what I posted and you follow the code, do you see a point at which it seems that the color coding "breaks"? Maybe at session_write_close()? Then look at just before session_write_close(). Check for a semicolon terminating the previous line, and If you have anything that needs to be "matched" in pairs (parentheses, quotes, braces), count those and make sure they are matched.

Re: Overwrite MySQL database entry problem :(

Posted: Tue Feb 09, 2010 1:42 pm
by enter-music
OOOOOOOOOO... I think its finally clicked!!
$qry = "UPDATE members SET firstname = '$detail' WHERE member_id = '$memid';
This starts with an " but not at the end, im gunna try fix this now and let you know how it goes.

many thanks to AbraCadaver for making me work this one out myself

cheers

Re: Overwrite MySQL database entry problem :(

Posted: Tue Feb 09, 2010 1:42 pm
by enter-music
OOOOOOOOOO... I think its finally clicked!!
$qry = "UPDATE members SET firstname = '$detail' WHERE member_id = '$memid';
This starts with an " but not at the end, im gunna try fix this now and let you know how it goes.

many thanks to AbraCadaver for making me work this one out myself

cheers