Jump to content

My register file isn't working.


champbronc2

Recommended Posts

<?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
Share on other sites

  $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
Share on other sites

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
Share on other sites

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
Share on other sites

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 raffle@champbux.com 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
Share on other sites

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
Share on other sites

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.