Jump to content

update DB method


cikcak

Recommended Posts

Okey Ive tried all ways.

 

I have a form in TPL which gave me a little information and I would like to use it.

 

if (isset($_POST['submitUpdate']))
{

$eid = $cookie->id_employee;
$s1= $_POST['s2'];

$sql = "UPDATE ps_employee
    SET email = ('$s1')
    WHERE id_employee = ('$eid') ";
 
I have checked values, its okey, I only need to update it after form submit. Now page reload, but data in DB not updating.
 
I should do something like this, yes? I select ps_employee table, make condition WHERE id_employee = $eid but how to write correct SET email = $s2 ? 
 
Db::getInstance()->update('ps_employee', 'id_employee = ('$eid')');
}
Edited by cikcak (see edit history)
Link to comment
Share on other sites

You build your sql statement, but it seems you don't execute it:

 

 

Db::getInstance()->execute($sql);
 
 To add var values in the sql text, join them using a dot .
Also good practice to add "back quotes" around it.
 
 
Together something like (Didn't test it though):
 
$sql = 'UPDATE ps_employee
    SET `email
` = '.$s1.'
    WHERE 
`id_employee` = '.$eid;
 
Hope this gives some idea. Also, have a look in some classes/xxxx.php files to get some more examples.
 
pascal
  • Like 1
Link to comment
Share on other sites

Yes, it gave me idea and now it works perfect. As you said I didnt excute it. 

By the way, I have update DB value from BO and how should I solve this?

 

After form submit my page refresh (send info to php script and make DB value update). But I have to reload one more time to see a result. What should I write after DB query to refresh it by script?

 

 
Link to comment
Share on other sites

I did reload with this:

$page = $_SERVER['PHP_SELF'];
echo '<meta http-equiv="Refresh" content="0;">';

Any other ways to refresh it with one time? Now its strange. I click submit form its refresh and after all Its refresh one more time (by this command). But If refresh only after submit form I can`t see new data. How to do it correct with one refresh? Submit data , page refresh and I can see a new data.

Link to comment
Share on other sites

if after the refresh the result is not displayed than the problem is that your code is messed up, you should always process the data before displaying the results, not forcing a reload...

 

you are doing this:

 

1.show result

2.process data

 

and you should do:

 

1.process data (if any)

2. show the results

 

anyway if you are not intrested in optimizing your code you can do the refresh in PHP like this

 

header("location:http://mysite.com/myurl...");

:rolleyes:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...