RIMs Posted February 10, 2012 Share Posted February 10, 2012 Hi guys, I need a help to find out what is a problem. Some of my code does not work on my local comp and in the same time it works well when I place it on Internet server. First example: <body> <?php if($_POST['submit_form'] == "Submit") { $varNewTeam = $_POST['Reg_Team']; $varNewCity = $_POST['Reg_City']; $db = mysql_connect('localhost', 'root', '') or die ('no connection with server'); mysql_select_db('db_m ,$db) or die('DB error'); mysql_query ("INSERT INTO reg2012 VALUES ('$varNewTeam','$varNewCity')") or die('insert error'); } ?> <form action="registration_2012_form.php" method="post"> <p>Team: <input type="text" name="Reg_Team" size="20" maxlength="50" value="<?=$varNewTeam;?>" /><br /></p> <p>City: <input type="text" name="Reg_City" size="20" maxlength="50" value="<?=$varNewCity;?>" /><br /></p> <p><input type="Submit" value="Submit" name="submit_form" /></p> </form> </body> On local comp: It gives me message "Undefined index: submit_form". On Net server works well. If I split the code in two files. In the first one I leave the form with "action=FILE2.php" and put my php code in the second file "FILE2.php" - it starts work even on local server. second example: <body> <?php $db = mysql_connect('localhost', 'root', '') or die ('no connection with server'); mysql_select_db('db_m' ,$db) or die('DB error'); mysql_query ("CREATE TABLE temp1 (team char(50), city char(50) )") or die('create tables error'); ?> </body> It works in the Net and can not create the TABLE on my local comp. I use XAMPP on my local comp (if it's important) Quote Link to comment https://forums.phpfreaks.com/topic/256816-code-does-not-work-on-local-comp-and-works-well-on-internet-server/ Share on other sites More sharing options...
spiderwell Posted February 10, 2012 Share Posted February 10, 2012 the warning you are getting is just switched off on the live server, use this instead isset($_POST['submit_form']) Quote Link to comment https://forums.phpfreaks.com/topic/256816-code-does-not-work-on-local-comp-and-works-well-on-internet-server/#findComment-1316568 Share on other sites More sharing options...
Pikachu2000 Posted February 10, 2012 Share Posted February 10, 2012 The error is still there on your hosted server, it's just that display_errors is off, or error_reporting is at a low enough level that the notice isn't displayed, or it simply goes into the error log instead. You're not checking if $_POST['submit_form'] actually exists before you see if its value is "Submit". Also since some browsers mishandle sending the value of submit buttons, you could/should either use a hidden form field's value, or replace that line with this to see if the form has been submitted. if( strtolower($_SERVER['REQUEST_METHOD']) === 'post' ) { Quote Link to comment https://forums.phpfreaks.com/topic/256816-code-does-not-work-on-local-comp-and-works-well-on-internet-server/#findComment-1316570 Share on other sites More sharing options...
RIMs Posted February 10, 2012 Author Share Posted February 10, 2012 Thank's guys! Any idea, why CREATE TABLE does not work on local? Quote Link to comment https://forums.phpfreaks.com/topic/256816-code-does-not-work-on-local-comp-and-works-well-on-internet-server/#findComment-1316588 Share on other sites More sharing options...
Pikachu2000 Posted February 10, 2012 Share Posted February 10, 2012 Not without seeing whatever errors MySQL returns, no. Run the CREATE TABLE query in phpMyAdmin, (or echo mysql_error() if you've already set up the code in php) and start a thread in the MySQL forum, if the error doesn't help you figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/256816-code-does-not-work-on-local-comp-and-works-well-on-internet-server/#findComment-1316592 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.