Search the Community
Showing results for tags 'mysql_connect'.
-
Bear with me, I'm new to PHP and MySQL. Ok, so strange thing. Last night, I'm coding it up, everything's working great. Go to bed, wake up, now my form isn't working. Literally 9 hours before, it was. Nothing changed, suddenly isn't working. I have 2 files, form.php and insert.php. form.php: <html> <head> <title>YAY!</title> </head> <body> <h2>Register Form</h2> <form method="get" action="insert.php"> <table border="0" width="60%"> <tr> <td width="10%">Referred By: </td><td><input type="text" name="referredby" /></td> </tr> <tr> <td width="10%">Email: </td><td><input type="text" name="email" /></td> </tr> <tr> <td width="10%">Name: </td><td><input type="text" name="name" /></td> </tr> <tr> <td width="10%">Password: </td><td><input type="text" name="password" /></td> </tr> <tr> <td width="10%">Earned: </td><td><input type="text" name="earned" /></td> </tr> <tr> <td width="10%">Image: </td><td><input type="text" name="image" /></td> </tr> </table> <p> <input type="submit" value="Register" /> <input type="reset" value="reset" /> </form> </body> </html> insert.php: <?php $referredby = $_REQUEST['referredby']; $email = $_REQUEST['email']; $name = $_REQUEST['name']; $password = $_REQUEST['password']; $earned = $_REQUEST['earned']; $image = $_REQUEST['image']; if($email && $name && $password && $password && $earned) { mysql_connect("dbserver", "username", "password") or die("Problem connecting to the database server. Please contact administrator at <link to contact form here> with the following error message: " . mysql_errno() . ": " . mysql_error() . "<br />" ); mysql_select_db("database"); mysql_query("INSERT INTO desiredtable(referredby,email,name,password,earned,image) VALUES('$referredby','$email','$name','$password','$earned','$image')"); $registered = mysql_affected_rows(); echo "$name was successfully registered! $registered row(s) added to the table."; mysql_close(); }else{ echo "You have to complete the form<br />"; echo "Email: " . $email . "<br />" . "Name: " . $name . "<br />" . "password: " . $password . "<br />" . "Earned: " . $earned . "<br />"; } echo mysql_errno() . ": " . mysql_error() . "<br />"; echo "<a href=\"form.php\">Return to the previous page</a>" ?> Now, here's the kicker. When I fill out the form and click register, I have my else { } statement echo the $_REQUEST[ ] variables (added that for troubleshooting), and it's displaying the contents correctly. I even changed my form from method="post" to method="get" to verify in the address bar. Apparently, everything before and after the initial IF statement conditions are working correctly. It's the conditions that are not, which doesn't make sense, because as I said, I was using it last night in order to add entries into my table. It's probably something really simple stupid, and I'm hoping you can help me out with it :/ FYI, this is set up under a XAMPP installation on my PC