Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 3 of 3

Thread: Is my update syntax correct in my php code?

  1. #1

    Is my update syntax correct in my php code?

    I can't believe I'm having such a hard time with this but, I'm trying to update code in my database using php here is the code. I don't see any issues, I mean I have a php mysql book in front of me and it looks correct:

    PHP Code:
    $sql "UPDATE info SET firstname='$fn' WHERE user_id='$user'";
    $Result2 mysql_query($sql$dbConnect) or die('Error updating database. Error L1.'); 
    What could be the fricking problem! I've wasted so much time on this simple piece of code.

    I'm connecting fine because before this line I'm doing a select statement which works. I'm using the same mysql_select_db().

    I've also printed out the values for $fn and $user and they both have data.


    Thanks
    ---------------------------------------
    FlashNewby
    "Not really a newby just thought the name was cool ...."

  2. #2
    PHP Code:
    <?php
    $host
    ="yuor host name";
    $dbuser="your db user";
    $pass="your pass";
    $datbase="your db";
    $fn=$_GET['fn'];//form submitted var
    $user=$_GET['user'];//form submitted var
    $conn=mysql_connect($host$dbuser$pass) or die("no connect to database server"); 

    mysql_select_db($database);

    $query="UPDATE info SET firstname='$fn' WHERE user_id='$user'";

    mysql_query($query) or die('Error updating database. Error L1.');

    mysql_close($conn);
    ?>

  3. #3
    I've got all the connection info and I'm connecting but when I check mysql_affected_rows() function it returns 0 which means no rows were updated.
    I also check the database and notice that the row is not getting updated.

    Any other ideas??
    ---------------------------------------
    FlashNewby
    "Not really a newby just thought the name was cool ...."

Thread Information

Users Browsing this Thread

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

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012