-6

So i am trying to type something in input box which i want to be dynamically stored in a variable. And then there is a hyperlink next to a table of records which will take this variable(.php?S=$inputboxvariable) and go to next php page which will execute a sql statement using this variable's value.

I do not want for submission , _GET or _POST or even SESSION variable in this.

Please help. I know coding would help but i dont know how, just a basic code would suffice.

Thanks

user1467788
  • 5
  • 1
  • 4

2 Answers2

0

You dont want to use get, post, or session to pass the variable but your example uses this:

(.php?S=$inputboxvariable)

Which would be passing the variable using GET.

If you are truely trying to avoid using these,

  1. Use a database to store the data.

  2. Use a file to store the data.

Maybe you could tell me why you are avoiding get, post, or session variables and I will understand better what you are trying to accomplish?

trevorkavanaugh
  • 340
  • 1
  • 8
  • but i am not using get on the main page, its the secondry page which use get to grab value of S. my concern is how to post it using ajax – user1467788 Aug 10 '12 at 20:47
  • so basically, the hyperlink on the main page will post the variable and take you to the next page? – trevorkavanaugh Aug 10 '12 at 20:49
  • alright, well I dont quite understand why you will not use get or post for this. But since this is what you asked for, I will try. I am assuming that you are avoiding post and get because you dont want to use a form/submit button for some reason? – trevorkavanaugh Aug 10 '12 at 20:57
  • Yes the php page is table retrieved from database so there is no form just a table and i am adding a field at the end which will update that row in database using the variable in put in one input box. i hope i have explained well. – user1467788 Aug 10 '12 at 20:58
  • Oh wait, so your wanted to update that value in the database? or are you trying to pass a variable from one page to another? – trevorkavanaugh Aug 10 '12 at 21:11
  • Yes trevor i am grabing value from inputbox and updating the hyperlink dynamically so when i click on hyperlink it just passes the variable without any submit. – user1467788 Aug 10 '12 at 21:13
  • refer to my new answer for code :) – trevorkavanaugh Aug 10 '12 at 21:24
  • Sorry trevor but i wasnt able to explain my problem properly. i want to add picture but it wont let me – user1467788 Aug 10 '12 at 21:27
  • ahha whoah dude wheres a picture coming from? we started with a hyperlink moving a variable to the next page, then we had a database that needed to be updated, now a picture? Hmm.. think clearly about what you need and I will do my best. But be sure to be very clear because I am really having trouble figuring out what you are even trying to do... – trevorkavanaugh Aug 10 '12 at 21:31
  • omg sorry i meant i cannot add picture in my question because of my reputation which would help me explain my problem. I do not want to add picture to database – user1467788 Aug 10 '12 at 21:32
  • Ohh haha no problem, that just threw me off for a second :P Hmm would you like to move this to email (remove spaces)? trevor . kavanaugh @ gmail.com – trevorkavanaugh Aug 10 '12 at 21:37
0

Alright I get what your asking for now. The javascript below will make a call from your page to an external script (ajax/myscripthere.php) which will handle the SQL.

In the php script, we simply handle our SQL like we normally would if this was not an AJAX call.

Please accept answer if this is correct to your expectations :)

javascript:

<script>
    var xmlHttpReq = false;

    // Set ID Equal to your input box ID
    input_box_value = document.getElementById("inputboxvariable").value;

    if(window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if(window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }

    // Set filename equal to your PHP script
    self.xmlHttpReq.open('POST', "ajax/myscripthere.php", true);

    self.xmlHttpReq.onreadystatechange = function()
    {
        if(self.xmlHttpReq.readyState == 4)
        {
            // Update is complete
        }
    };

    self.xmlHttpReq.send("value="+input_box_value);
</script>

PHP:

<?php
if(isset($_POST['value']))
{
    $conn = new mysqli("host", "username", "password", "db_name")
                 or die ('Error: '.mysqli_connect__error());

    // Make Correct SQL Query (i dont know your DB)
    $query = "UPDATE table_name SET col=".$_POST['value']." WHERE xxxxxx;";

    $result = @$conn->query($query);

    $conn->close();
?>
trevorkavanaugh
  • 340
  • 1
  • 8