Jump to content

Write to a database instantly


beennn

Recommended Posts

Id like to be able to change variables from my database, change them and write them back onto the databaseiv tried doing

$showDays = ['days'];echo $showDays<a href="#" onclick="<? $showDays += 1 ?>">Buy</a>

i assumed it would change visibly at least but it seems to work once then not respond to anything and then i dont know how to make it update the databaseany help would be great

Link to comment
Share on other sites

i'm not familiar with the notation: $showDays = ['days'];don't you need an array in front of the brackets? if not, what's this script saying?

Link to comment
Share on other sites

i'm not familiar with the notation: $showDays = ['days'];don't you need an array in front of the brackets? if not, what's this script saying?
Create an ArrayAn array can be defined in three ways.The following code creates an Array object called myCars:
1:var myCars=new Array(); // regular array (add an optional integermyCars[0]="Saab";	   // argument to control array's size)myCars[1]="Volvo";myCars[2]="BMW";2:var myCars=new Array("Saab","Volvo","BMW"); // condensed array3:var myCars=["Saab","Volvo","BMW"]; // literal array

Link to comment
Share on other sites

PHP is a preprocessor - the interpreter works by taking pages about to be served by the web server and evaluating the PHP code contained within it. Thus, PHP is not a 'live', if you like, language - it is run on the server side before the page is sent to the user to interact with. Thus, if you want to execute more PHP afterwards, you will have to make another request to the server - such as through AJAX like Haris S suggests, and you may want to read the AJAX tutorial for more details.P.S.: PHP does not have native JSON support and thus you can't actually write $showDays = ['days'];.

Link to comment
Share on other sites

Then why does this produce an error?$showDays = ['days'];echo var_dump($showDays);

Link to comment
Share on other sites

thank you, ill go through the Ajax tutorials.also i didn't copy the code word for word and left some things out; was just showing the base of what i tried which is why it may not make sensesorry for the misunderstanding----------------------------------------Is it wrong to directly show values from the database through php which i then would like to visibly change as well as updating the database?

Link to comment
Share on other sites

Is it wrong to directly show values from the database through php which i then would like to visibly change as well as updating the database?
no, not if that's the intention of your application. You just need to make sure you are validating and sanitizing any user input before putting it into the database.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...