Results 1 to 4 of 4

Thread: MySQL & PHP

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2008
    Posts
    42

    Re: MySQL & PHP

    Ok if I wanted to create an update form for a page that has been published to the web already, how would i go about doing it so that when a user clicks on update form, enters values that the values entered can be part of the update action.

    can i declare like $textbox1 = textbox1.text

    then do like mysql_query("UPDATE `tablename` SET field2='$textbox1' LIMIT 1");

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: MySQL & PHP

    that code should work just fine
    My usual boring signature: Something

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: MySQL & PHP

    Use the $_GET or $_POST arrays to access form data. For an update form, you should be using POST. Also, ensure that you escape data before inserting it into a SQL query, or your data is exposed to arbitrary attack via SQL injection.

    PHP Code:
    $value $_POST['fieldname']
    # ...
    mysql_query("
      UPDATE tablename
      SET field2='"
    .mysql_real_escape_string($value)."'
    "
    ); 
    The LIMIT clause is usually unnecessary, but you should have some other way of identifying the row you want to update. Usually a primary key is used here.

  4. #4
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: MySQL & PHP

    i misread his post. oops

    sorry
    My usual boring signature: Something

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