beennn Posted July 26, 2011 Share Posted July 26, 2011 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 More sharing options...
[dx] Posted July 26, 2011 Share Posted July 26, 2011 Better option is to send query to database via AJAX and update that row+1 Link to comment Share on other sites More sharing options...
beennn Posted July 26, 2011 Author Share Posted July 26, 2011 would you be able to show me an example of how id go about doing that please? Link to comment Share on other sites More sharing options...
beennn Posted July 26, 2011 Author Share Posted July 26, 2011 or could someone tell me of another way to get around to do this? Link to comment Share on other sites More sharing options...
niche Posted July 26, 2011 Share Posted July 26, 2011 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 More sharing options...
brucemand Posted July 27, 2011 Share Posted July 27, 2011 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 More sharing options...
Synook Posted July 27, 2011 Share Posted July 27, 2011 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 More sharing options...
niche Posted July 27, 2011 Share Posted July 27, 2011 Then why does this produce an error?$showDays = ['days'];echo var_dump($showDays); Link to comment Share on other sites More sharing options...
Ingolme Posted July 27, 2011 Share Posted July 27, 2011 As mentioned in Synook's post, PHP can't interpret that code because it doesn't natively support JSON. Link to comment Share on other sites More sharing options...
beennn Posted July 27, 2011 Author Share Posted July 27, 2011 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 More sharing options...
thescientist Posted July 27, 2011 Share Posted July 27, 2011 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 More sharing options...
beennn Posted July 28, 2011 Author Share Posted July 28, 2011 ok, thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.