Greetings. This is my first post here, I do not wish to waste your time, and any responses are greatly appreciated whether they lead to a resolution of this issue or not.
Recently, after becoming tired of having to handle a remote server via Dreamweaver and the webhost-provided tools, I decided to establish a server with PHP and mySQL on my laptop for development purposes.
The setup features the latest version of WAMP (v2.2, I believe), PHP 5.3.8, Apache 2.2.21, and mySQL 5.5.16 with phpMyAdmin 3.4.5. I have not changed anything besides the passwords for PHP and mySQL to allow them to share information.
Tests show that PHP functions fine (using phpinfo()), I have successfully added and retrieved data from tables in the database. I will post below the tests I have attempted and the manner in which I did so.
I know I have done something really wrong, but I've been working on setting up this server and running tests all day, so chances are something's just flying right past me.
So, to the tests. The first hint of a problem occurred when I attempted to load onto my site a registration form, made with PHP. It had seemed to work, almost, on the old remote server, but now I get a hideous "Notice: Undefined index: newName in C:\wamp\www\php\reg.php on line 33" error whenever the submit button is pressed.
The line of code that the error references is an IF logic bundle, as follows:
#33 if(!$_POST['newName'] || !$_POST['newPass']){
In context with the rest of its block:
if(isset($_POST['subjoin'])){
#33 if(!$_POST['newName'] || !$_POST['newPass']){
die("Missing fields. <a href='frontp.php' target='_parent'>Return</a>");}
$_POST['newName'] = trim($_POST['newName']);
if(strlen($_POST['newName']) > 24){
die("Username too long or invalid characters. <a href='frontp.php' target='_parent'>Return</a>");}
if(usrTaken($_POST['newName'])){
$use = $_POST['newName'];
die("The username $use has already been taken. <a href='frontp.php' target='_parent'>Return</a>");}
$md5pass = md5($_POST['newPass']);
...
It continues in a like manner:
$_SESSION['regName'] = $_POST['newName'];
$_SESSION['regRes'] = addUsr($_POST['newName'], $md5pass);
$_SESSION['registered'] = true;
echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
return;}
else{ ?>
<form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
<table border="0">
<tr> <td> <b>Account Registration</b> </td> </tr>
<tr> <td> <b style="font-size:12px;">Provide an Unique Username [6-24 characters, letters and numbers permitted]</b> </td> </tr>
<tr> <td> <input type="text" name"newName" /> </td> </tr>
<tr> <td> <b style="font-size:12px;">Choose a Security Code [password, 4-24 characters, letters or numbers permitted]</b> </td> </tr>
<tr> <td> <input type="text" name="newPass" /> </td> </tr>
<tr> <td> <b style="font-size:12px;">Re-enter Passcode for Authentication</b> </td> </tr>
<tr> <td> <input type="password" name="newPassAut" /> </td> </tr>
<tr> <td> <b style="font-size:12px;">Enter Your Email [optional]</b> </td> </tr>
<tr> <td> <input type="text" name="eMail" /> </td> </tr>
<tr> <td> <input type="checkbox" name="acceptTNC" />
<b style="font-size:12px;">I Accept the Conditions Listed on the Legal Page <a href="legal.html" target="_new">?</a></b> </td> </tr>
<tr> <td> <input type="submit" name="subjoin" value="Register" /> </td> </tr>
</table>
</form>
<?php mysql_close($con); } ?>
It is contained as a frame within a PHP page within which a database.php file is called, which is simply this:
<?php
$con = mysql_connect("localhost","root","root")or die(mysql_error());
mysql_select_db("alpha",$con); ?>
There is more to the registration form, if you request I will post the functions and such. I have only posted line #33 down.
So, to try and isolate the problem, I made two test files on my local server: test.php and test2.php.
test.php:
<?php include('php/database.php');
global $starone, $startwo;
#test one
/*if(!isset($_POST['one']) || !isset($_POST['two'])){
echo "failure";}
else{
$_POST['one'] = $starone;
$_POST['two'] = $startwo;
echo "success";
print $starone;
print $startwo;} */
#test two
if(isset($_POST['one']) || isset($_POST['two'])){
$_POST['one'] = $starone;
$_POST['two'] = $startwo;
echo "success";
echo $starone;
print $startwo;}
else { echo "failure"; }
#phpinfo(); ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="one"; />
<input type="text" name="two"; />
<input type="submit" />
</form>
<form action="test2.php" method="post">
<input type="text" name="three"; />
<input type="text" name="four"; />
<input type="submit" />
</form>
Very makeshift. I simply iced (#'d) the different parts of the code and tested every possible combination on this sheet. Including taking out the include(); trying $_GET, and et cetera.
test2.php:
<?php include('php/database.php');
global $starone, $startwo;
#test one
/*if(!isset($_POST['three']) || !isset($_POST['four'])){
echo "failure";}
else{
$_POST['three'] = $starone;
$_POST['four'] = $startwo;
echo "success";
print $starone;
print $startwo;} */
#test two
if(isset($_POST['three']) || isset($_POST['four'])){
$_POST['three'] = $starone;
$_POST['four'] = $startwo;
echo "success";
echo $starone;
print $startwo;}
else { echo "failure"; }
#phpinfo(); ?>
Same thing here, tried all the combinations, same results all the time (besides the obvious exceptions, like if i were to remove a crucial element, obviously failure would ensue.)
The difference here between the reg.php, as mentioned earlier in the post, and these tests is that there is no issue with undefined variables.
Upon loading the page for the first time with these tests, success is shown, or, inversely, failure with some setups. The results are reversed upon clicking the submit button, regardless of the content of the fields. Success is displayed where failure was previously, and vice versa. When content is entered, it does not show up. i used both echo and print, as you can see, at the same time to tell if there was a difference. There was none.
I know I'm missing a crucial piece here, but its all totally perplexing to me right now.
Any more information will be provided upon requests.
Thanks much for any help at all, I appreciate it all.