champbronc2 Posted June 5, 2010 Share Posted June 5, 2010 <?php function registerUser() { mysql_connect('localhost', 'site_raffle', 'raffle', 'site_raffle'); $email = $_POST['email']; $Country = $_POST['Country']; $ip=@$REMOTE_ADDR; $sql = "INSERT INTO tblUsers (fldEmail, fldCountry, fldIP) VALUES ($email, $Country, $ip);"; mysql_query($sql); } ?> <form action="<?php $_SERVER['PHP_SELF']."?register=true" ?>" method="post"> <table border="0" width="400" align="center"> <tbody> <tr> <td width="150" align="left"><label>Email address</label></td> <td width="250" align="left"><input class="field" maxlength="100" name="email" size="25" type="text" tabindex="1" /></td> </tr> <tr> <td width="150" align="left"><label>Country (Shipping will NOT be free if outside of US)</label></td> <td width="250" align="left"><input class="field" maxlength="100" name="Country" size="25" type="text" tabindex="1" /></td> </tr> <tr> <td width="150" align="left"></td> <td width="250" align="right"><input class="submit" type="submit" value="Submit" tabindex="6" /></td> </tr> </tbody> </table> </form> What is wrong with the code?? I will go to my webpage, fill out the fields, and hit submit. I check the database, and no new information has been entered... Link to comment https://forums.phpfreaks.com/topic/203931-my-register-file-isnt-working/ Share on other sites More sharing options...
robert_gsfame Posted June 5, 2010 Share Posted June 5, 2010 change this $sql = "INSERT INTO tblUsers (fldEmail, fldCountry, fldIP) VALUES ($email, $Country, $ip);"; into this $sql = "INSERT INTO tblUsers (fldEmail, fldCountry, fldIP) VALUES ('$email', '$Country','$ip')", Link to comment https://forums.phpfreaks.com/topic/203931-my-register-file-isnt-working/#findComment-1068048 Share on other sites More sharing options...
champbronc2 Posted June 5, 2010 Author Share Posted June 5, 2010 $sql = "INSERT INTO tb_Users (Email, Country, IP) VALUES ($email, $Country, $ip)"; mysql_query($sql) or die(mysql_error()); echo "You have been registered correctly"; Tried changing it to that. It still won't work. I tried to submit it, and no errors seem to occur but the database is empty. And it does not echo You have been registered correctly. Link to comment https://forums.phpfreaks.com/topic/203931-my-register-file-isnt-working/#findComment-1068051 Share on other sites More sharing options...
PFMaBiSmAd Posted June 5, 2010 Share Posted June 5, 2010 Did you post all of your code, because there is no code to check if your form was submitted, to call the registerUser() function, or to echo You have been registered correctly. You also need to put an echo statement in for - $_SERVER['PHP_SELF']."?register=true" (do a view source in your browser of your form to see exactly what you are producing. Link to comment https://forums.phpfreaks.com/topic/203931-my-register-file-isnt-working/#findComment-1068052 Share on other sites More sharing options...
robert_gsfame Posted June 5, 2010 Share Posted June 5, 2010 <?php echo $_SERVER['PHP_SELF']."?register=true" ?> Link to comment https://forums.phpfreaks.com/topic/203931-my-register-file-isnt-working/#findComment-1068053 Share on other sites More sharing options...
champbronc2 Posted June 5, 2010 Author Share Posted June 5, 2010 That is all my code. I am really new and pretty much suck. And the thing is, I am using wordpress so my page is http://website.com/page/ so I don't know what to put instead of <?php echo $_SERVER['PHP_SELF']."?register=true" ?> Link to comment https://forums.phpfreaks.com/topic/203931-my-register-file-isnt-working/#findComment-1068055 Share on other sites More sharing options...
champbronc2 Posted June 5, 2010 Author Share Posted June 5, 2010 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@gmail.com, US, )' at line 1 I get that message after hitting submit now while testing it. I changed the code. The new code is in the original post. Link to comment https://forums.phpfreaks.com/topic/203931-my-register-file-isnt-working/#findComment-1068057 Share on other sites More sharing options...
champbronc2 Posted June 5, 2010 Author Share Posted June 5, 2010 Ok nevermind I can't edit. New code is here <? if (isset($_POST["email"])) { mysql_connect('localhost', 'champbux_raffle', 'raffle'); $con=mysql_connect('localhost', 'champbux_raffle', 'raffle'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("champbux_raffle", $con); $email = $_POST['email']; $Country = $_POST['Country']; $ip=@$REMOTE_ADDR; $sql = "INSERT INTO Users (Email, Country, IP) VALUES ($email, $Country, $ip)"; mysql_query($sql) or die(mysql_error()); echo "You have been registered correctly"; } ?> <form action="raffle.php" method="post"><strong>YOUR IP ADDRESS IS BEING RECORDED</strong> By registering you agree to the terms that we are not held liable for anything wrong with the jersey and that you may only enter ONCE. After 200 participants have registered, one winner will be randomly chosen. An email will be dispatched to the winner. Please add [email protected] to your white list. Prizes not claimed within 72 hours will be forfeited and another winner will be chosen. All entrants will be screened for cheating. Shipping will be free to the United States. You will only have access to this page for 24 hours after the survey is completed. This is to prevent cheating. Your information will NEVER be disclosed to anyone or used for malicious purposes. <table border="0" width="400" align="center"> <tbody> <tr> <td width="150" align="left"><label>Email address</label></td> <td width="250" align="left"><input class="field" maxlength="100" name="email" size="25" type="text" tabindex="1" /></td> </tr> <tr> <td width="150" align="left"><label>Country (Shipping will NOT be free if outside of US)</label></td> <td width="250" align="left"><input class="field" maxlength="100" name="Country" size="25" type="text" tabindex="1" /></td> </tr> <tr> <td width="150" align="left"></td> <td width="250" align="right"><input class="submit" type="submit" value="Submit" tabindex="6" /></td> </tr> </tbody> </table> </form> Link to comment https://forums.phpfreaks.com/topic/203931-my-register-file-isnt-working/#findComment-1068058 Share on other sites More sharing options...
robert_gsfame Posted June 5, 2010 Share Posted June 5, 2010 Based on the error, something wrong while inserting the record and you are not really changing your code into what i said $sql = "INSERT INTO Users (Email, Country, IP) VALUES ('$email', '$Country', '$ip')"; see the bold single quotes Link to comment https://forums.phpfreaks.com/topic/203931-my-register-file-isnt-working/#findComment-1068059 Share on other sites More sharing options...
champbronc2 Posted June 5, 2010 Author Share Posted June 5, 2010 Ohhh. Well thanks it works now!!! Only problem is the IP address isn't showing up now...? Link to comment https://forums.phpfreaks.com/topic/203931-my-register-file-isnt-working/#findComment-1068061 Share on other sites More sharing options...
robert_gsfame Posted June 5, 2010 Share Posted June 5, 2010 $_SERVER['REMOTE_ADDR'] Link to comment https://forums.phpfreaks.com/topic/203931-my-register-file-isnt-working/#findComment-1068064 Share on other sites More sharing options...
kenrbnsn Posted June 5, 2010 Share Posted June 5, 2010 This code <?php $ip=@$REMOTE_ADDR; ?> is written as though register globals is still enabled, which is hasn't been since about 2002. What you want instead is <?php $ip = $_SERVER['REMOTE_ADDR']; ?> Ken Link to comment https://forums.phpfreaks.com/topic/203931-my-register-file-isnt-working/#findComment-1068066 Share on other sites More sharing options...
champbronc2 Posted June 5, 2010 Author Share Posted June 5, 2010 It works perfect now. Thank you very much. Link to comment https://forums.phpfreaks.com/topic/203931-my-register-file-isnt-working/#findComment-1068067 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.