cleary1981 Posted July 1, 2008 Share Posted July 1, 2008 Hi All, I'm trying to get my script to insert values into a table. My php works fine but the values i pass from my javascript are not getting added to my table Heres the javascript function create_object() { var g_model = document.getElementById("model").value; var g_objName = document.getElementById("objName").value; var url = "create_object.php?g_model" + escape(g_model) + "?g_objName" + escape(g_objName); request.open("GET", url, true); request.onreadystatechange = updateObject; request.send(null); } heres the php <?php require "config.php"; $g_model = $_REQUEST['g_model']; $g_objName = $_REQUEST['g_objName']; mysql_query("INSERT INTO object (module_name, object_name, xpos, ypos) VALUES ('$g_model', '$g_objName', '10', '10')"); ?> where have i gone wrong? Link to comment https://forums.phpfreaks.com/topic/112765-solved-insert-into/ Share on other sites More sharing options...
JD* Posted July 1, 2008 Share Posted July 1, 2008 Try this instead: mysql_query("INSERT INTO object (module_name, object_name, xpos, ypos) VALUES ('".$g_model."', '".$g_objName."', '10', '10')"); Link to comment https://forums.phpfreaks.com/topic/112765-solved-insert-into/#findComment-579143 Share on other sites More sharing options...
cleary1981 Posted July 1, 2008 Author Share Posted July 1, 2008 I gave it a try there and the two values are still showing as blank in the db. Link to comment https://forums.phpfreaks.com/topic/112765-solved-insert-into/#findComment-579148 Share on other sites More sharing options...
JD* Posted July 1, 2008 Share Posted July 1, 2008 Try to echo out your mysql statement by doing the following: //mysql_query("INSERT INTO object (module_name, object_name, xpos, ypos) VALUES ('$g_model', '$g_objName', '10', '10')"); echo("INSERT INTO object (module_name, object_name, xpos, ypos) VALUES ('$g_model', '$g_objName', '10', '10')"); and just see what shows up. If you don't see anything in the $g_model and $g_objName parts, then the value isn't found from the javascript. In that case, try to echo your $_REQUEST['g_mode'] and see what happens. If that still doesn't work, then you have to look into the javascript. If it does work, let me know and we'll look further into it Link to comment https://forums.phpfreaks.com/topic/112765-solved-insert-into/#findComment-579155 Share on other sites More sharing options...
cleary1981 Posted July 1, 2008 Author Share Posted July 1, 2008 I tried both of those as you suggested. Neither one showed any values. I'm nearly sure its my line var url = "create_object.php?g_model" + escape(g_model) + "?g_objName" + escape(g_objName); but i'm not sure where Link to comment https://forums.phpfreaks.com/topic/112765-solved-insert-into/#findComment-579160 Share on other sites More sharing options...
JD* Posted July 1, 2008 Share Posted July 1, 2008 Oh, duh, I see what's going on....you're putting the values in to the URL, so you should be using $_GET instead of $_REQUEST. Try that and see if it works. Link to comment https://forums.phpfreaks.com/topic/112765-solved-insert-into/#findComment-579164 Share on other sites More sharing options...
AndyB Posted July 1, 2008 Share Posted July 1, 2008 var url = "create_object.php?g_model" + escape(g_model) + "?g_objName" + escape(g_objName); surely that should be var url = "create_object.php?g_model=" + escape(g_model) + "&g_objName=" + escape(g_objName); Link to comment https://forums.phpfreaks.com/topic/112765-solved-insert-into/#findComment-579168 Share on other sites More sharing options...
cleary1981 Posted July 1, 2008 Author Share Posted July 1, 2008 I noticed something myself in the line i mentioned. I forgot the = in the line var url = "create_object.php?g_model=" + escape(g_model) + "?g_objName=" + escape(g_objName); when i made this change i was getting a module_name value of SSa1?g_objName= when i made your change to $_GET I still got same result. Link to comment https://forums.phpfreaks.com/topic/112765-solved-insert-into/#findComment-579172 Share on other sites More sharing options...
cleary1981 Posted July 1, 2008 Author Share Posted July 1, 2008 thanks guys. Ur the bestest Link to comment https://forums.phpfreaks.com/topic/112765-solved-insert-into/#findComment-579173 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.