PHP mysql form Post issue help me please
Results 1 to 5 of 5

Thread: PHP mysql form Post issue help me please

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    7

    PHP mysql form Post issue help me please

    PHP Code:
    if (isset($_POST['field1'])) {
            
            
    $id mysql_real_escape_string($_POST['thisID']);
        
    $field1 mysql_real_escape_string($_POST['one']);
            
    $field2 mysql_real_escape_string($_POST['two']);
        
    $field3 mysql_real_escape_string($_POST['three']);
        
    $field4 mysql_real_escape_string($_POST['four']);
        
        
    $newvariable mysql_query("SELECT id from table2 WHERE columb2 = '" $field1 "'");
        
        
    $sql mysql_query("UPDATE table1 SET column1='$field2', column2='$field3', column3='$field4', column4='$field1', column5='$newvariable' WHERE id='$id'"); 
    Now there is my php code everything works apart from it $newvariable line cannot find the id from table 2 and the mysql update query just places a "0" into my database i have tried many different solutions to this but none have worked. i have tried just putting the variable name within single quotes... '$field1' i have tryed double quotes i have tried putting the mysql escape function within the $newvariable function. nothing has worked hopefully someone can suggest some new solutions that will or may work. ps i have tried running the similar mysql statement direct from phpmyadmin and it works it finds the values needed. i have tryed just putting a number into the $sql statement on the last line of the php code there instead of $newvariable i just places a number there to test and it worked fine. it just doesnt seem to be able to compare the columb2 with the $field1 variable in the where clause :/.

  2. #2
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,885
    Huh?

    Try writing that again when you have less caffeine in your system.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    7
    $newvariable = mysql_query SELECT id from table2 WHERE columb2 = '" . $field1 . "'"

    $sql = mysql_query UPDATE table1 column5='$newvariable' WHERE id='$id'"


    basically that part of my code is not working.
    how do i compare a char or varchar field within a where clause because it does not seem to be able to compare even if i change $field1 to just text it does not seem to work. i have tested the query within phpmyadmin and it works and finds the correct id.

  4. #4
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,885
    If you look at the manual page for mysql_query you'll see (after the bit recommending that you don't use the function) that it returns a resource. You still have to get the data out of that resource:
    The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.
    Do you check for any errors returned by either query?

    What happens if you send the same query to the DBMS (see the first couple of tips in the Debugging thread for suggestions about how to get this)?
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  5. #5
    Senior Member DeadlySin3's Avatar
    Join Date
    Nov 2002
    Location
    Colorado
    Posts
    158
    PHP Code:
    $newvariable mysql_query("SELECT id from table2 WHERE columb2 = '" $field1 "'"); 
    columb2? or column2?

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
  •