Dolamite Jenkins
asked on
Mysql rows not being populated
I am using the Python Request Module to post data to my database on line and it seems to be working except the data is not being moved to the database ... meaning it creates new row in the table but there is no data in the rows ...
This is the PHP code I use
Rows: 3
key1 key2
import requests
value1 = "100"
value2 = 'Clay'
payload = {'key1a': value1, 'key2a': value2}
r = requests.post("http://semsnation.com/aaa.php", params=payload)
#r = requests.get("http://httpbin.org/get", params=payload)
print r.url
the Python code generates this datahttp://semsnation.com/aaa.php?key2a=Clay&key1a=100
This is the PHP code I use
<?php
$dbhost = 'Transfer.xxxx.xxx.com';
$dbuser = 'TransferData';
$dbpass = 'xxxx';
$dbname='TransferData';
$tbl_name="DataMove"; // Table name
// Connect to server and select database.
mysql_connect("$dbhost", "$dbuser", "$dbpass")or die("cannot connect");
mysql_select_db("$dbname")or die("cannot select DB");
// Get values from form
$key1 = mysql_real_escape_string($_POST['key1a']);
$key2 = mysql_real_escape_string($_POST['key2a']);
// Insert data into mysql
$sql="INSERT INTO $tbl_name(key1, key2)VALUES('$key1', '$key2')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
}
else {
echo "ERROR";
}
?>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
array(0) { }
Notice: Undefined index: key1a in /home/content/15/6807515/html/aaa.php on line 18
Notice: Undefined index: key2a in /home/content/15/6807515/html/aaa.php on line 19
Successful
Back to main page
object(stdClass)#1 (2) { ["key1"]=> string(0) "" ["key2"]=> string(0) "" } object(stdClass)#2 (2) { ["key1"]=> string(0) "" ["key2"]=> string(0) "" } object(stdClass)#1 (2) { ["key1"]=> string(0) "" ["key2"]=> string(0) "" } object(stdClass)#2 (2) { ["key1"]=> string(0) "" ["key2"]=> string(0) "" } object(stdClass)#1 (2) { ["key1"]=> string(0) "" ["key2"]=> string(0) "" } object(stdClass)#2 (2) { ["key1"]=> string(0) "" ["key2"]=> string(0) "" } object(stdClass)#1 (2) { ["key1"]=> string(0) "" ["key2"]=> string(0) "" }
OK, it looks like the POST-method request is not reaching the script, since the first var_dump($_POST) showed array(0).
Let's try the same script again, but change $_POST to $_GET in all places.
Let's try the same script again, but change $_POST to $_GET in all places.
Strongly endorse reading Ray's excellent article on the deprecated MySQL API!
the MySQL API is deprecated as at PHP 5.5 and will be removed
(i.e. MySQLi or PDO should be used instead)
(sorry Ray, I get a little anxious when I see MySQL being removed :)
the MySQL API is deprecated as at PHP 5.5 and will be removed
(i.e. MySQLi or PDO should be used instead)
(sorry Ray, I get a little anxious when I see MySQL being removed :)
Hi!
Check your php.ini for register_globals (as of version 4.2.0 ) that variable is default off.
Also check the variables_order for the $_GET AND $_POST this variable should at least contain "GP" but I recommend that you set it to "EGPCS"
From the PHP manual for variables_order
"Sets the order of the EGPCS (Environment, Get, Post, Cookie, and Server) variable parsing. For example, if variables_order is set to "SP" then PHP will create the superglobals $_SERVER and $_POST, but not create $_ENV, $_GET, and $_COOKIE. Setting to "" means no superglobals will be set. "
Regards,
Tomas Helgi
Check your php.ini for register_globals (as of version 4.2.0 ) that variable is default off.
Also check the variables_order for the $_GET AND $_POST this variable should at least contain "GP" but I recommend that you set it to "EGPCS"
From the PHP manual for variables_order
"Sets the order of the EGPCS (Environment, Get, Post, Cookie, and Server) variable parsing. For example, if variables_order is set to "SP" then PHP will create the superglobals $_SERVER and $_POST, but not create $_ENV, $_GET, and $_COOKIE. Setting to "" means no superglobals will be set. "
Regards,
Tomas Helgi
@PortletPaul: Yes, the removal of the MySQL API is going to be something of an earthquake for the millions of programming novices who have been copying "found bits" of code from the mean streets of the internet, without understanding what the code is actually doing. Here are some possible scenarios...
1. Their hosting company will upgrade and they will start getting deprecated messages. Mass panic will ensue.
2. Their code will start failing. Mass panic will ensue.
3. Their hosting company will branch a PHP 5.3 server to give them time to upgrade, but they will never upgrade.
4. They are hosting their sites on their own servers, and they will never upgrade.
5. They will be forced to refactor because their applications have some economic or social value, and it will be a long, costly exercise.
There is no good way out of this conundrum. Either PHP continues to support a truly horrible language interface, or PHP takes a step forward into the 21st century. They have chosen the latter path. And if that's a bit troublesome for millions of novice web developers, well, tough break. They all got PHP for "free" and now the price of "free" is going up, way up!
Of course this means a huge amount of business for PHP programmers who can help refactor the old spaghetti code ;-)
1. Their hosting company will upgrade and they will start getting deprecated messages. Mass panic will ensue.
2. Their code will start failing. Mass panic will ensue.
3. Their hosting company will branch a PHP 5.3 server to give them time to upgrade, but they will never upgrade.
4. They are hosting their sites on their own servers, and they will never upgrade.
5. They will be forced to refactor because their applications have some economic or social value, and it will be a long, costly exercise.
There is no good way out of this conundrum. Either PHP continues to support a truly horrible language interface, or PHP takes a step forward into the 21st century. They have chosen the latter path. And if that's a bit troublesome for millions of novice web developers, well, tough break. They all got PHP for "free" and now the price of "free" is going up, way up!
Of course this means a huge amount of business for PHP programmers who can help refactor the old spaghetti code ;-)
ASKER
I am new to PHP ... this is my php5.ini ... I dont see anything referencing global variables
[PHP]
engine = On
session.bug_compat_warn = 0
AcceptPathInfo
cgi.fix_pathinfo=1
max_execution_time = 300 ; Maximum execution time of each script, in seconds
max_input_time = 600 ; Maximum amount of time each script may spend parsing request data
memory_limit = 128M ; Maximum amount of memory a script may consume (8MB)
post_max_size = 300M
default_mimetype = "text/html"
default_charset = "UTF-8"
file_uploads = On
upload_max_filesize = 400M
allow_url_fopen = On
user_agent="PHP"
default_socket_timeout = 60
I do not think there is anything here that interacts with register_globals
You can determine the actual settings of the PHP variables with this script, shown here in its entirety.
You can determine the actual settings of the PHP variables with this script, shown here in its entirety.
<?php phpinfo();
Let's go back to this comment and try the $_GET suggestion.
ASKER
After further testing I discovered this is not a PHP problem ... it is a python Problem... while it appears my code is sending it actually is not transmitting the data ... any Python opinions ?
ASKER
Thanks I learned a lot about PHP debugging this code
No Python ideas, but I think there is a Python Zone here at EE (I think), so a question there might get you some insight. Thanks for the points and good luck with your project, ~Ray
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html