\";?", "text": "<p>I tried using $_SESSION["name"] = "document.write(name)"; and it works if i echo it out. But if i were to show this SESSION variable into a textbox or use it to do SQL, it shows document.write(name). How can i properly store it into a php variable? I've search and many people say you cant convert it. But surely there is someways where i can use the Javascript variable(name) to show it in a textbox or use it in SQL. </p>\n\n<p>javascript code with the variable name.</p>\n\n<pre class="prettyprint"><code><script>\n var name;\n $(document).ready(function()\n {\n $('#info tr #name').click(function()\n {\n name = $(this).text();\n alert(name);\n window.location = 'CV.php';\n });\n });\n</script>\n</code></pre>\n\n<p>For SQL my code is this,</p>\n\n<pre class="prettyprint"><code><?php $_SESSION["name"] = "<script>document.write(name)</script>"; \n echo $_SESSION["name"];\n $connect = mysqli_connect("localhost", "root", "","test1");\n $sql = "SELECT Name, Number, Expertise, Status, Remarks FROM particulars WHERE Name ='". $_SESSION["name"]."'";\n\n $result = mysqli_query($connect, $sql);\n\n while($row= mysqli_fetch_array($result))\n {\n $name = $row['Name'];\n $number =$row['Number'];\n $Expertise =$row['Expertise'];\n $status =$row['Status'];\n $remarks =$row['Remarks'];\n }\n?>\n</code></pre>\n\n<p>And below is my code to try to show the variable that i have stored in session into textbox.</p>\n\n<pre class="prettyprint"><code><input type='text' value='" .htmlspecialchars($_SESSION['name']) . "'/>\n</code></pre>", "answerCount": 1, "upvoteCount": 508, "dateCreated": "2026-07-18 00:20:06", "dateModified": "2026-07-20 14:30:05", "author": { "type": "Person", "name": "Samuel" }, "acceptedAnswer": { "@type": "Answer", "text": "<pre class="prettyprint"><code><script>\n var name;\n $(document).ready(function()\n {\n $('#info tr #name').click(function()\n {\n\n name = $(this).text();\n alert(name);\n window.location = 'CV.php?name=' + name; // send in link\n\n });\n });\n </script>\n</code></pre>\n\n<p>Inside CV.PHP</p>\n\n<pre class="prettyprint"><code>if(isset($_GET['name']))\n{\n $name = $_GET['name']; // Get it from URL\n $_SESSION["name"] = $name; \n}\nelse\n{\n $name = $_SESSION['name']; // Get it from session\n}\n$connect = mysqli_connect("localhost", "root", "","test1");\n$sql = "SELECT Name, Number, Expertise, Status, Remarks FROM particulars WHERE Name ='". $_SESSION["name"]."'";\n\n$result = mysqli_query($connect, $sql);\n\nwhile($row= mysqli_fetch_array($result))\n{\n $name = $row['Name'];\n $number =$row['Number'];\n $Expertise =$row['Expertise'];\n $status =$row['Status'];\n $remarks =$row['Remarks'];\n} ?>\n</code></pre>\n\n<p>To show it in input box:</p>\n\n<pre class="prettyprint"><code> <input type='text' value='" .$name . "'/> // echo value as string\n <input type='text' value='" .$_SESSION['name']. "'/> // if it's a page that is not CV.php\n</code></pre>", "upvoteCount": 69, "url": "https://exchangetuts.com/index.php/how-to-store-js-variable-into-php-without-using-sessionname-scriptdocumentwritenamescript-1768501802860825#answer-1784593206957002", "dateCreated": "2026-07-20 00:30:05", "dateModified": "2026-07-20 14:30:05", "author": { "type": "Person", "name": "Moussa Khalil" } } } }