ivanax Posted March 24, 2014 Share Posted March 24, 2014 (edited) I wrote this code to retrieve data from a HTTP request in c++ program so once it recieves it it sends the data into a mysql database I get this error along the line. Here is my code. <?php require_once('inc/config.php'); $ip = $_POST['ip']; $country = $_POST['country']; $compname = $_POST['compname']; $usr = $_POST['usr']; $con = mysqli_connect(HOSTNAME,DBUSER,DBPASS,DB); if(mysqli_connect_errno()) { echo "Failed to Connect" .mysqli_connect_error(); } mysqli_query($con,"INSERT INTO data (ip,country,compname,usr) VALUES($ip,$country,$compname,$usr)"); ?> Now here is my error ( ! ) Notice: Undefined index: ip in C:\wamp\www\panel\gate.php on line 4 Call Stack # Time Memory Function Location 1 0.0050 142200 {main}( ) ..\gate.php:0 ( ! ) Notice: Undefined index: country in C:\wamp\www\panel\gate.php on line 5 Call Stack # Time Memory Function Location 1 0.0050 142200 {main}( ) ..\gate.php:0 ( ! ) Notice: Undefined index: compname in C:\wamp\www\panel\gate.php on line 6 Call Stack # Time Memory Function Location 1 0.0050 142200 {main}( ) ..\gate.php:0 ( ! ) Notice: Undefined index: usr in C:\wamp\www\panel\gate.php on line 7 Call Stack # Time Memory Function Location 1 0.0050 142200 {main}( ) ..\gate.php:0 Edited March 24, 2014 by ivanax Quote Link to comment https://forums.phpfreaks.com/topic/287230-undefined-index-please-help/ Share on other sites More sharing options...
gristoi Posted March 24, 2014 Share Posted March 24, 2014 are you actually posting any data to this script? you need to add some conditional checking in to make sure the data is there. ie: if(isset($_POST['ip])){......do stuff.....} Quote Link to comment https://forums.phpfreaks.com/topic/287230-undefined-index-please-help/#findComment-1473700 Share on other sites More sharing options...
ginerjm Posted March 24, 2014 Share Posted March 24, 2014 All of your POST variables are the result of an html page being 'posted' to this script. Do you have such a thing calling this script or are you running it as a url in your browser? As gristol said - confirm that the elements exist in the POST array,even if you run it as the result of a posted form and they are supposed to exist. Quote Link to comment https://forums.phpfreaks.com/topic/287230-undefined-index-please-help/#findComment-1473723 Share on other sites More sharing options...
ivanax Posted March 24, 2014 Author Share Posted March 24, 2014 @ginerjm, yes am actually sending the data from a http request done by a c++ program so that it can receive it and in turn save the data to a mysql base. I tried that too gave me some errors, maybe I am not doing it correctly, a source code may be quite helpful. Quote Link to comment https://forums.phpfreaks.com/topic/287230-undefined-index-please-help/#findComment-1473725 Share on other sites More sharing options...
ivanax Posted March 24, 2014 Author Share Posted March 24, 2014 And I am running it from a URL, I indicated the use of useragent in ma c++ program, so what am I not getting correctly? Quote Link to comment https://forums.phpfreaks.com/topic/287230-undefined-index-please-help/#findComment-1473726 Share on other sites More sharing options...
ginerjm Posted March 24, 2014 Share Posted March 24, 2014 So - this data is coming from a c program and not from a client's browser? (I'm a little sketchy on what you are trying to accomplish) Quote Link to comment https://forums.phpfreaks.com/topic/287230-undefined-index-please-help/#findComment-1473730 Share on other sites More sharing options...
ginerjm Posted March 24, 2014 Share Posted March 24, 2014 Is your C++ program sending the http request using the post method or the get method? Quote Link to comment https://forums.phpfreaks.com/topic/287230-undefined-index-please-help/#findComment-1473732 Share on other sites More sharing options...
ivanax Posted March 24, 2014 Author Share Posted March 24, 2014 Its sending via a POST method, and am not doing anything malicious. Quote Link to comment https://forums.phpfreaks.com/topic/287230-undefined-index-please-help/#findComment-1473734 Share on other sites More sharing options...
ginerjm Posted March 24, 2014 Share Posted March 24, 2014 Sorry - I don't know anything about doing this. I didn't know you could emulate an http request but you will have to do some research on the proper formatting of that data stream and perhaps how to make php retrieve it. In fact, how ARE you telling php where the data is coming from? Quote Link to comment https://forums.phpfreaks.com/topic/287230-undefined-index-please-help/#findComment-1473735 Share on other sites More sharing options...
boompa Posted March 24, 2014 Share Posted March 24, 2014 If you can post your C++ code, maybe I can see what you're doing wrong. Quote Link to comment https://forums.phpfreaks.com/topic/287230-undefined-index-please-help/#findComment-1473736 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.