Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding to a MySQL database

Status
Not open for further replies.

d3sol4t3

Programmer
Oct 27, 2005
40
GB
Hi a script i put together was working until a moved hosts, all it does is add to a MySQL database depending what was entered into the HTML form.

code for add.php (adds to the database)



code for add.html (add.php enters details from add.html)


php code i used to create the table 'article' with:


The problem is that nothing gets added to the and after the page reloads it just stays on add.html instead telling me if 'Dates have been inserted' or if a MYSQL error has occured (which worked fine on my previous host).

Any ideas?
 
I'd be willing to bet, its becasue your new host doesn't have register_globals set to ON, and you are referrencing your variables directly instead of ussing the appropriate arrays.
such as $_GET or $_POSt depending on the method of your form.

Read this more more info on register_globals.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
How would i turn register globals on, without going direct to my host?
 
You don't turn register_globals on because having it on is less secure. You code your software so that it does not need register_globals to be on.

Instead of the variable $inputname, you reference $_POST['inputname'] and $_GET['inputname'] for POST- and GET-method form inputs, respectively, and $_COOKIE for cookies.

See:




Want the best answers? Ask the best questions! TANSTAAFL!
 
Yes, Having register_globals set to on is a really big security risk. You should follow Sleipnir's advice and code the script so ti uses the $_POST or $_GET variables.

Its really a very minor change, that should be done, as most hosts now have register_globals set to off, and most of them
wont change it as it is a security risk.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
How comes though the exact code i posted above worked on one host and doesn't on another?
 
How comes though the exact code i posted above worked on one host and doesn't on another?
Because the hosts themselves had different default configurations (one probably had register_globals on, one probably had it off -- for example). Unless you are certain the hosts were identical, that will be the reason.

It's really easy to modify your code to handle this. You need only 2 lines to set up a local variable to be either empty string or the value that was passed in (from a get or post). This is how I set up my code for a get form submit:
Code:
$myinput = '';
if (isset($_GET('something')) $myinput = $_GET('something');
I'm ranting... sorry.

Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Would it be possible for somebody to 'repair' my script? Im confused on how to do it.

Thanks
 
Wild idea, could you append $_REQUEST[] into $GLOBALS ?
 
Just change all the variables that come from the HTML form such as: $head and $cont. to

$_POST['head'] and $_POST['cont']

as well as the rest of the variables that come from the form. and are put into the SQL query.

Its really not difficult give it a try.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top