Overwrite MySQL database entry problem :(

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
enter-music
Forum Newbie
Posts: 4
Joined: Tue Feb 09, 2010 10:08 am

Overwrite MySQL database entry problem :(

Post 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?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Overwrite MySQL database entry problem :(

Post 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();
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
enter-music
Forum Newbie
Posts: 4
Joined: Tue Feb 09, 2010 10:08 am

Re: Overwrite MySQL database entry problem :(

Post 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??
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Overwrite MySQL database entry problem :(

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
enter-music
Forum Newbie
Posts: 4
Joined: Tue Feb 09, 2010 10:08 am

Re: Overwrite MySQL database entry problem :(

Post 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
enter-music
Forum Newbie
Posts: 4
Joined: Tue Feb 09, 2010 10:08 am

Re: Overwrite MySQL database entry problem :(

Post 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
Post Reply