Jump to content

Code does not work on local comp and works well on Internet server


Recommended Posts

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)

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' ) {

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.