Skip to content
Advertisement

How to refresh page and send variable

i have a php page where i press a button to edit on another page the mysql db records: page name ‘distintaBase.php’ here there is a list of names that are products name. Each product cointains a list of components. When i press the edit button for one product i’m redirect to the new page ‘modifDistBase.php’.

JavaScript

the $dist_base variable is passed to the new page. I use it on the page title

JavaScript

and then to load the mysql db

JavaScript

pressing ADD button i add a new component

JavaScript

there is something wrong probably on the javascript.

JavaScript

the new component is added to the database (for example with #5 id) but do not appear on the page modifDistBase.php

if i press refresh on the browser or f5 now i can see the new component (#5 id) but on the database a new one is added #6 with the same items as #5

PS – header is already sent by menù page – have tried window.location.href with same result

Advertisement

Answer

there are some thing to fix on your code

Note the javascript you output with

JavaScript

will be precisely

JavaScript

Without checking the correctness of the js related to your goal, it’s immediate to see you should write instead

JavaScript

to inject the php value into the javascript string. (you’ve also forgot a double quote b.t.w)

If you have doubts regarding your javascript, you can inspect the page on the browser and look at it (right click and “inspect element” or “analyse element”).

Mind it is not recommended that you take the user input and use it as it is in an SQL instruction. You should do some sanification and use a prepared statement or escape the values before putting them in the sql.

That said, the javascript redirection you do looks a bit odd, maybe you can redirect from the php script without asking the client to do so. Look at the header php function for instruction about redirection done server side.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement