0

I'm creating a website with the option to Login with an administrative account and I want to be able to edit different elements in the HTML set to javascript variables. When you log in, there will be an input box to take a value from the user and apply it to a widget on the page. I haven't yet found a way to save the input value by overwriting the variable set for the widget and have it save to the webhost (GoDaddy) and stay throughout all sessions for anyone who shall be looking. I don't want to use Cookies or localStorage because I would like for the value to not only save on that user's session but all looking at the site. Ideas?

(EDITED CONTENT BELOW) Alright, I've used a database. I've gotten the code below:

<html>
<head>
<title>
MyAccount
</title>
</head>
<body>
<center>
<h1>
Welcome to your account!
</h1>
<input name="alertVal" type="text" placeholder="Alert Value">
<input type="button" text="Save" onclick="<?php saveAlert()?>">
<?php 
 // Connects to your Database
 function saveAlert(){
 mysql_connect("My IP is here.  Not sharing that.", "adminLog", "Yeah, not putting my pass on a forum...") or die(mysql_error()); 
 mysql_select_db("adminLog") or die(mysql_error()); 
 $data = mysql_query("SELECT * FROM Alert") 
 or die(mysql_error()); 
 while($info == mysql_fetch_array( $data )) 
 { 
     mysql_query("Update Alert SET Value = '$cleanURL'")
     INSERT INTO Alert (Value);
     VALUES ($_GET['alertVal']);
 } 
 }
 ?>
 </center>
 </body>
 </html>

And that doesn't work. Raises a T_STRING error. I don't really understand that. Help?

2 Answers2

0

I don't want to use Cookies or localStorage because I would like for the value to not only save on that user's session but all looking at the site. Ideas?

If you don't want to use the various client-side stores stored (such as cookies or localStorage) you might consider storing this information on the server, in a database or a file. Depending on the server side language you are using there might be different approaches to achieve that.

Ry-
  • 218,210
  • 55
  • 464
  • 476
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

You should use some sort of a database or just a simple text file. If you don't want to use a database, I recommend using Yaml.

BTW all GoDaddy plans include MySql. you can use that.

Kash Pourdeilami
  • 488
  • 2
  • 6
  • 24
  • Ok, I have a database created, and I want to use PHP to set a variable that is the equivalent to a javascript variable that is already set. How would I go about doing this? – TreyBrownDEV Jul 06 '14 at 18:17
  • Check this out http://stackoverflow.com/questions/4287357/access-php-variable-in-javascript – Kash Pourdeilami Jul 06 '14 at 18:21
  • I actually want to do the exact opposite from that. I want to get a javascript variable saved under a PHP variable, rather than PHP under javascript. – TreyBrownDEV Jul 06 '14 at 18:23
  • That's not possible. Javascript variables get evaluated on the user's browsers while the PHP ones are evaluated first on the server side. – Kash Pourdeilami Jul 06 '14 at 18:27
  • Now I'm trying to overwrite the value in my database. The database is called: adminLog; Table called: Alert; Value called: Value. I only want one value to be saved in the table, how could I overwrite the first one every time I write to the database? (Using PHP) – TreyBrownDEV Jul 06 '14 at 18:34
  • Use a query to submit the new value to the database. For example: http://example.com/?value=new – Kash Pourdeilami Jul 06 '14 at 22:40