Results 1 to 19 of 19

Thread: [RESOLVED] Update Code Help Please

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Resolved [RESOLVED] Update Code Help Please

    Hi guys,

    I need some help if possible.

    On my update code it dosent work can anyone help me get it to update the database.

    This is what i have in the error.log file

    Code:
    [03-Dec-2008 10:15:11] PHP Parse error:  syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/webspace/public_html/_update.php on line 20
    [03-Dec-2008 10:15:26] PHP Parse error:  syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/webspace/public_html/_update.php on line 20
    [03-Dec-2008 10:16:04] PHP Parse error:  syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/webspace/public_html/_update.php on line 20
    [03-Dec-2008 10:16:07] PHP Parse error:  syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/webspace/public_html/_update.php on line 20
    [03-Dec-2008 10:21:07] PHP Parse error:  syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/webspace/public_html/_update.php on line 16
    it just goes straight to this line once i click the button.

    PHP Code:
        echo "<p>record has been updated click </p> <a href=\"index.php\"> here </a> to continue"
    but record dosent change.

    edit.php

    PHP Code:
    <html>
    <?php
      error_reporting
    (0);
              
    $db mysql_connect("localhost","webspace_data","d82f1fc");
              
    mysql_select_db("webspace_data",$db);
              
    $id $_GET['id'];
              
    $result mysql_query("SELECT * FROM clients WHERE id=$id",$db);
              
    $myrow mysql_fetch_array($result);
     
    ?>

    <form action="_update.php" method="post" id="_editform">

    <p><b>First Name:</b>
    <input type="text" value="<?php echo $myrow['first'?>" name="first">
    <br>
    <b>Last Name:</b>
    <input type="text" value="<?php echo $myrow['last'?>" name="last">
    <br>
    <b>Date Got:</b>
    <input type="text" value="<?php echo $myrow['dategot'?>" name="dategot">
    <br>
    <b>Pay Date:</b>
    <input type="text" value="<?php echo $myrow['paydate'?>" name="paydate">
    <br>
    <b>Money Due:</b>
    <input type="text" value="<?php echo $myrow['money'?>" name="money">
    <br>
    <b>Phone Number:</b>
    <input type="text" value="<?php echo $myrow['phone'?>" name="phone">
    <br>
    <br>
    <inpyt type="hidden" name="id" value="<?php echo $id ?>" >
    <input type="submit" name="submit" value="Edit Clients Information ">
    <br>
    <br>
    Click <a href="index.php"> Here </a> to go back
    </form>
    </body>
    </html>

    _update.php

    PHP Code:
    <HTML>
    <BODY>
    <?PHP
    $_lnk 
    mysql_connect("localhost","webspace_data","d82f1fc");
    mysql_select_db("clients",$_lnk);
        
    //    print_r($_POST);

        
    $id $_POST['id'];
        
    $_first $_POST['first'];
        
    $_last $_POST['last'];
        
    $_dategot $_POST['dategot'];
        
    $_paydate    $_POST['paydate'];
        
    $_money   $_POST['money'];
            
    $_phone   $_POST['phone'];
    $_rs ="UPDATE clients 
                            SET clients.first ='
    $_first', 
                              clients.last ='
    $_last', 
                              clients.dategot ='
    $_dategot',
                              clients.paydate ='
    $_paydate', 
                              clients.money ='
    $_money',
                                                      clients.phone='
    $_phone', 
                            WHERE clients.id = '
    $id';";

        
    $query=mysql_query($_rs);
        echo 
    "<p>record has been updated click </p> <a href=\"index.php\"> here </a> to continue";
        
    //header("Location:index.php");

    ?>
    </BODY>
    </HTML>
    Last edited by Jamie_Garland; Dec 3rd, 2008 at 10:42 AM.
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Update Code Help Please

    Can anyone help?
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  3. #3
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Update Code Help Please

    The only thing I really see wrong with the code is that you have a comma before your WHERE clause in your SQL statement. Not sure if that would cause the problem.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Update Code Help Please

    Where do you see that i cant see it?
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  5. #5
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Update Code Help Please

    Right here:

    clients.phone='$_phone', <-- No comma here please
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Update Code Help Please

    I have done what you said and it still dosent update the record.?

    Code:
    <HTML>
    <BODY>
    <?PHP
    $_lnk = mysql_connect("localhost","webspace_data","d82f1fc");
    mysql_select_db("clients",$_lnk);
    	//	print_r($_POST);
    
    	$id = $_POST['id'];
    	$_first = $_POST['first'];
    	$_last = $_POST['last'];
    	$_dategot = $_POST['dategot'];
    	$_paydate    = $_POST['paydate'];
    	$_money   = $_POST['money'];
            $_phone   = $_POST['phone'];
    $_rs ="UPDATE clients 
    						SET clients.first ='$_first', 
    						  clients.last ='$_last', 
    						  clients.dategot ='$_dategot',
    						  clients.paydate ='$_paydate', 
    						  clients.money ='$_money',
                                                      clients.phone ='$_phone' 
    						WHERE clients.id = '$id';";
    
    	$query=mysql_query($_rs);
    	echo "<p>record has been updated click </p> <a href=\"index.php\"> here </a> to continue";
    	//header("Location:index.php");
    
    ?>
    </BODY>
    </HTML>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  7. #7
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Update Code Help Please

    Are the errors gone now?

    If so, chances are that it is your update.

    What happens if you echo all of your $_POST variables? Do they return what you need?

    If you echo $_rs and run the query manually, does it work?

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Update Code Help Please

    When i have run the script it then goes to the main page but it dosent change anything in the database just says that it was updated.

    Have a look View and Delete work fine click edit youll see what i mean.

    http://www.webspace4rent.biz
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  9. #9
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Update Code Help Please

    Not to be rude but

    Quote Originally Posted by kfcSmitty
    What happens if you echo all of your $_POST variables? Do they return what you need?

    If you echo $_rs and run the query manually, does it work?

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Update Code Help Please

    How do i echo them?
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  11. #11
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Update Code Help Please

    Seriously?

    I would also suggest you follow some basic PHP tutorials before continuing on too far with your project.

    PHP Code:
    <HTML>
    <BODY>
    <?PHP
    $_lnk 
    mysql_connect("localhost","webspace_data","d82f1fc");
    mysql_select_db("clients",$_lnk);

        
    $id $_POST['id'];
        
    $_first $_POST['first'];
        
    $_last $_POST['last'];
        
    $_dategot $_POST['dategot'];
        
    $_paydate    $_POST['paydate'];
        
    $_money   $_POST['money'];
            
    $_phone   $_POST['phone'];

    echo 
    "ID: " $id "<br />" "First: " $_first "<br />" "Last: " $_last;
    //and so forth and so on

    $_rs ="UPDATE clients 
        SET clients.first ='
    $_first', 
        clients.last ='
    $_last', 
        clients.dategot ='
    $_dategot',
        clients.paydate ='
    $_paydate', 
        clients.money ='
    $_money',
            clients.phone ='
    $_phone
        WHERE clients.id = '
    $id';";


    echo 
    "Query: " $_rs;

        
    $query=mysql_query($_rs);
        echo 
    "<p>record has been updated click </p> <a href=\"index.php\"> here </a> to continue";

    ?>
    </BODY>
    </HTML>
    Now if you're echoing the entire query, there is really no need to echo all the individual variables unless something is really wrong.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Update Code Help Please

    it now shows this it still dosent change in the database?

    Code:
    ID: 
    First: Mark
    Last: ffgffgQuery: UPDATE clients SET clients.first ='Mark', clients.last ='ffgffg', clients.dategot ='fgfgfgq', clients.paydate ='ghghgqhg', clients.money ='fgfgfg', clients.phone ='fgfgfg' WHERE clients.id = '';
    record has been updated click 
    
    here to continue
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  13. #13
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Update Code Help Please

    The ID seems to be the issue. Do you have someone with an id = ''?

    If not, it will not update the record. A WHERE clause specifies that the query is to run against only those values which match the criteria met in the WHERE clause.

    So since I assume you do not have a record with a blank id (not null, blank) then it will never update anything.

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Update Code Help Please

    it shows in my database that it has an id

    thats the record in the database.

    1 Mark Brodie 28898 98989 89 89898989
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  15. #15
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Update Code Help Please

    I assumed it has an ID.

    Problem is that you're not carrying over the ID properly to your query.

    So your statement
    Code:
    Query: UPDATE clients SET clients.first ='Mark', clients.last ='ffgffg', clients.dategot ='fgfgfgq', clients.paydate ='ghghgqhg', clients.money ='fgfgfg', clients.phone ='fgfgfg' WHERE clients.id = '';
    Is looking for a record with an ID = ''. Since you don't have a record with no ID, it has nothing to update. The query did exactly what it was told to do, problem is you're not specifying an ID.

    E.g) If a record in your database had an id of 5 and you wanted to update it, you would do

    Code:
    Query: UPDATE clients SET clients.first ='Mark', clients.last ='ffgffg', clients.dategot ='fgfgfgq', clients.paydate ='ghghgqhg', clients.money ='fgfgfg', clients.phone ='fgfgfg' WHERE clients.id = '5';

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Update Code Help Please

    How do i sort the problem?
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  17. #17
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Update Code Help Please

    Add an invisible field to your form and post the value of ID to the 2nd page.

    PHP Code:
    <input type="hidden" value="<?php echo $id ?>" name="id">

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Update Code Help Please

    I have doe ne what you said but it dosent change in the database but i does show the ID in the query now aswell?

    PHP Code:
    <html>
    <?php
      error_reporting
    (0);
              
    $db mysql_connect("localhost","webspace_data","d82f1fc");
              
    mysql_select_db("webspace_data",$db);
              
    $id $_GET['id'];
              
    $result mysql_query("SELECT * FROM clients WHERE id=$id",$db);
              
    $myrow mysql_fetch_array($result);
    //    echo "First Name: ".$myrow["firstname"];
     
    ?>

    <form action="_update.php" method="post" id="_editform">
    <input type="hidden" value="<?php echo $id ?>" name="id"> 
    <p><b>First Name:</b>
    <input type="text" value="<?php echo $myrow['first'?>" name="first">
    <br>
    <b>Last Name:</b>
    <input type="text" value="<?php echo $myrow['last'?>" name="last">
    <br>
    <b>Date Got:</b>
    <input type="text" value="<?php echo $myrow['dategot'?>" name="dategot">
    <br>
    <b>Pay Date:</b>
    <input type="text" value="<?php echo $myrow['paydate'?>" name="paydate">
    <br>
    <b>Money Due:</b>
    <input type="text" value="<?php echo $myrow['money'?>" name="money">
    <br>
    <b>Phone Number:</b>
    <input type="text" value="<?php echo $myrow['phone'?>" name="phone">
    <br>
    <br>
    <input type="hidden" name="id" value="<?php echo $id ?>" >
    <input type="submit" name="submit" value="Edit Clients Information ">
    <br>
    <br>
    Click <a href="index.php"> Here </a> to go back
    </form>
    </body>
    </html>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  19. #19

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: [RESOLVED] Update Code Help Please

    Thanks for your help managed to resolve this now.
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

Posting Permissions

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



Click Here to Expand Forum to Full Width