Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Updating image field

Options
  • 16-02-2009 6:02pm
    #1
    Closed Accounts Posts: 73 ✭✭


    I have a stupid problem.

    every time i update a record in my database the images reset to blank(as in No image at all) how can i have the image form the database record keep.

    this update page has given me more hardship and i just do have the experience to fix it.

    Please advise asap


Comments

  • Registered Users Posts: 2,494 ✭✭✭kayos


    If the field is not actually being updated then dont go near it in your update statement.

    What SQL are you using to update the table?


  • Closed Accounts Posts: 73 ✭✭Protype


    kayos wrote: »
    If the field is not actually being updated then dont go near it in your update statement.

    What SQL are you using to update the table?

    [PHP]
    UPDATE master_info SET Logo_link=%s, Instructor_pic=%s
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "text"),
    [/PHP]

    Don't know if that is what you want


  • Registered Users Posts: 2,494 ✭✭✭kayos


    So Instructor_pic is the image field?

    I could be going down the totally wrong path but....An image datatype is a binary datatype and can not be treated as a string.

    Are you actually storing the Image in the DB or just the path to the image?


  • Closed Accounts Posts: 73 ✭✭Protype


    kayos wrote: »
    So Instructor_pic is the image field?

    I could be going down the totally wrong path but....An image datatype is a binary datatype and can not be treated as a string.

    Are you actually storing the Image in the DB or just the path to the image?


    Just the path


  • Closed Accounts Posts: 73 ✭✭Protype


    What i was thinking, would there be a way of ignoring the field if there is no selection made.


  • Advertisement
  • Registered Users Posts: 2,494 ✭✭✭kayos


    In that case the problem is in your PHP and I'm clueless on that so will leave it to someone who knows it.

    Mods might infract me for backseat modding for say this but. It really would be helpful if you asked your questions in a better way and provided more info. From your posts up to your last I got the impression you were dealing with an image datatype, which leads me down one path. But seeing as its only a string datatype then your problems are totally different.

    Any way if your using SQL Server try using profiler to see exactly what SQL is being sent to the server. If your fields are being blanked its because you are giving a command that blanks them. Possible reason? Maybe $_POST is missing or blank.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    something like this?

    [php]
    $query="UPDATE master_info SET Logo_link = {$_POST}";
    if($_POST > '') { $query.=", Instructor_pic = {$_POST}"; }
    $result=mysql_query($query);
    [/php]


  • Closed Accounts Posts: 73 ✭✭Protype


    kayos wrote: »
    In that case the problem is in your PHP and I'm clueless on that so will leave it to someone who knows it.

    Mods might infract me for backseat modding for say this but. It really would be helpful if you asked your questions in a better way and provided more info. From your posts up to your last I got the impression you were dealing with an image datatype, which leads me down one path. But seeing as its only a string datatype then your problems are totally different.

    Any way if your using SQL Server try using profiler to see exactly what SQL is being sent to the server. If your fields are being blanked its because you are giving a command that blanks them. Possible reason? Maybe $_POST is missing or blank.

    Thanks for your help as it makes a difference when people answer a post. Sorry i ask questions in a vague manner, i do it all the time but i don't mean to.:o:o:o:o:o:o:o:o:o:o:o:o:o:o:o


  • Closed Accounts Posts: 73 ✭✭Protype


    Adam wrote: »
    something like this?

    [php]
    $query="UPDATE master_info SET Logo_link = {$_POST}";
    if($_POST > '') { $query.=", Instructor_pic = {$_POST}"; }
    $result=mysql_query($query);
    [/php]

    Hi Adam i will try to integrate and ill see how it goes, ill be back


  • Closed Accounts Posts: 73 ✭✭Protype


    Adam wrote: »
    something like this?

    [php]
    $query="UPDATE master_info SET Logo_link = {$_POST}";
    if($_POST > '') { $query.=", Instructor_pic = {$_POST}"; }
    $result=mysql_query($query);
    [/php]

    How do i write if both are images
    [PHP]($_POST, "text"),
    ($_POST, "text"), [/PHP]


  • Advertisement
  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Protype wrote: »
    How do i write if both are images
    [PHP]($_POST, "text"),
    ($_POST, "text"), [/PHP]
    do you mean how do you check that both values are not empty?


  • Closed Accounts Posts: 73 ✭✭Protype


    Adam wrote: »
    do you mean how do you check that both values are not empty?
    ye sorry if the two.

    can you give me a steep through the code please


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    well what i was doing there was building the query on a step by step basis.

    lets say you have 4 values you want to put in to the database. you want to check each one to see if its empty, and if it is then skip it. so you build the query with string concatenation. concatention works as follows:

    [php]
    $query="SELECT * FROM";
    $query.=" users WHERE";
    $query.=" user_id = 10";
    [/php]

    now if you were to then type

    [php]
    echo $query;
    [/php]

    you would get:
    SELECT * FROM users WHERE user_id = 10
    

    so using that principle, you can check to see if a variable has a value, and use an if statement to concatenate the next step of the query, as we did in your example:

    [php]
    //start the query off
    $query="UPDATE master_info SET Logo_link = {$_POST}";
    //then check to see if instructor_pic has a value. if it does, we want to concatenate the next part of the query on. if it's empty, this part will be left out
    if($_POST > '') {
    $query.=", Instructor_pic = {$_POST}";
    }
    //then run the query
    $result=mysql_query($query);
    [/php]

    however, if either of the values can be empty, you need to make sure one of them has a value before building a query, so you dont end up running a dud query for nothing. so you could do something like this:

    [php]
    //check that either of them have a new value. if neither of them do, we dont want to run an empty query
    //the || means 'or'
    if($_POST > '' || $_POST > '') {

    //start the query string
    $query="UPDATE master_info SET";

    //check the first value
    if($_POST > '') {
    $query.=" Logo_link = {$_POST}";
    }

    //now if both variables have a new value, we're going to need a comma and space so the the query has correct syntax, so check if they're both greater than blank
    //&& means 'and'
    if($_POST > '' && $_POST > '') {
    $query.=", ";
    }

    //check the second value
    if($_POST > '') {
    $query.=" Instructor_pic = {$_POST}";
    }

    $result=mysql_query($query);

    }
    [/php]

    and obviously you can set anything else at the end, like WHERE, LIMIT etc. if you need to


  • Closed Accounts Posts: 73 ✭✭Protype


    Thank you very much for explaining that as that makes more sense. i will work on that tomorrow and hopefully get it sorted out.

    Thanks again Adam


  • Closed Accounts Posts: 73 ✭✭Protype


    Hi Adam if you there.
    I use dreamweaver and find it very hard to understand the code it writes

    How do i do what you said with this code?

    [PHP]
    $editFormAction = $_SERVER;
    if (isset($_SERVER)) {
    $editFormAction .= "?" . htmlentities($_SERVER);
    }

    if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "Edit_Form")) {
    $updateSQL = sprintf("UPDATE master_info SET Expirey_date=%s, FirstName=%s, SurName=%s, Gender_id=%s, Logo_link=%s, ADI_Number=%s, Business_Name=%s, Address1=%s, Address2=%s, Town=%s, Listing_type=%s, ZipCode=%s, tel_number=%s, Tel_Type=%s, Business_No1=%s, Business_No2=%s, MobileNumber=%s, Mobile_Type=%s, FaxNumber=%s, Fax_Type=%s, Website=%s, email1=%s, email1_Type=%s, email2=%s, email2_Type=%s, personal_notes=%s, Company_info=%s WHERE master_id=%s",
    GetSQLValueString($_POST, "date"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "int"),
    GetSQLValueString($_POST, "text"),//this needs to be checked
    GetSQLValueString($_POST, "text"),//this needs to be checked
    GetSQLValueString($_POST, "int"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "int"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "int"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "int"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "int"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "int"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "int"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "text"),
    GetSQLValueString($_POST, "int"));

    mysql_select_db($database_DI_Directory, $DI_Directory);
    $Result1 = mysql_query($updateSQL, $DI_Directory) or die(mysql_error());
    }[/PHP]

    Please help if you can


Advertisement