1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Unknown column 'gaby' in 'field list'

Discussion in 'PHP' started by jpgalea, Jan 21, 2009.

  1. #1
    hi i am having a problem performing an insert from my php code. Here is the code i am using

    	$q = "UPDATE tbl_users
    		  SET username=$username, password=$password
    		  WHERE user_ID = $user_ID";
    	mysql_query($q, $connection) or die(mysql_error());
    Code (markup):
    now i am getting the error Unknown column 'gaby' in 'field list'.

    I cannot understand why i get this error as far as i can see i have used the correct syntax for an update and now it is telling me that gaby doesnt exist, which in this case is the data not the field name. any help pls?
     
    jpgalea, Jan 21, 2009 IP
  2. yoavmatchulsky

    yoavmatchulsky Member

    Messages:
    57
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #2
    add single quotation marks around $username and $password

    SET username='$username'
     
    yoavmatchulsky, Jan 21, 2009 IP
  3. jpgalea

    jpgalea Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ok thanks solved that however the fields in my db are still not being updated, I think I need some futher help, here is the code i am using at the moment:

    
    <?php
    
    require_once("config.php");
    
    
    // if data has been submitted save it in db and redirect to user listing
    if ($_POST["submit"]) {
    	$user_ID = $_POST["user_ID"];
    	$username = $_POST["username"];	
    	$password = $_POST["password"];
    
    	$q = "UPDATE tbl_users
    		  SET username='$username', password='$password'
    		  WHERE user_ID = '$user_ID'";
    	mysql_query($q, $connection) or die(mysql_error());
    	//$id = mysql_insert_id($connection);
    	header("Location: users.php");	
    
    // if user_ID present in URL search for that record and display page in edit format
    } else if ($_GET["user_ID"]) {
    	$user_ID = $_GET["user_ID"];
    	$q = "SELECT * FROM tbl_users 
    		 WHERE user_ID = '$user_ID'";	
    	$result = @mysql_query($q, $connection) or die(mysql_error());
    	$user = mysql_fetch_array($result);
    	$smarty->assign('user', $user);
    	$smarty->display("users-edit.tpl");
    
    }
    
    ?>
    
    Code (markup):
     
    jpgalea, Jan 22, 2009 IP
  4. t3nt3tion

    t3nt3tion Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You need to check your table structure. You could possibly make it dump mysql_error when it tries to insert.
    One trick I use is writing the insert queries, and then try them in phpmyadmin.
     
    t3nt3tion, Jan 22, 2009 IP