Jump to content

[SOLVED] INSERT INTO


cleary1981

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.