Reg form error

currently getting this error:

syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

here is the code:

<?PHP 
$con = mysql_connect("","","");
if (!$con)
	{
	die('Could not connect: ' .mysql_error());
	}
	
mysql_select_db("", $con);

$sql= "INSERT INTO conference (first, last, middle, street1, street2, city, state, home, cell, work, media, meal, business, other) VALUES ('$_POST['first']','$_POST['last']','$_POST['middle']','$_POST['street1']','$_POST['street2']','$_POST['city']','$_POST['state']','$_POST['home']','$_POST['cell']','$_POST['work']','$_POST['media']','$_POST['meal']','$_POST['business']','$_POST['other']')";
	
  if (!mysql_query($sql,$con))
  {
  die('Error: ' .mysql_error());
  }
 echo "1 record added'<br />' click here to continue registration ";
 
 mysql_close($con)
?>

This is because of single quotes and double quotes problem…


<?PHP 
$con = mysql_connect("","","");
if (!$con)
	{
	die('Could not connect: ' .mysql_error());
	}
	
mysql_select_db("", $con);

//instead of this line,

[B]$sql= "INSERT INTO conference (first, last, middle, street1, street2, city, state, home, cell, work, media, meal, business, other) VALUES ('$_POST['first']','$_POST['last']','$_POST['middle']','$_POST['street1']','$_POST['street2']','$_POST['city']','$_POST['state']','$_POST['home']','$_POST['cell']','$_POST['work']','$_POST['media']','$_POST['meal']','$_POST['business']','$_POST['other']')";[/B]

//write-down like this

$sql= "INSERT INTO conference (first, last, middle, street1, street2, city, state, home, cell, work, media, meal, business, other) VALUES ('".$_POST[first]."','".$_POST[last]."','".$_POST[middle]."','".$_POST[street1]."','".$_POST[street2]."','".$_POST[city]."','".$_POST[state]."','".$_POST[home]."','".$_POST[cell]."','".$_POST[work]."','".$_POST[media]."','".$_POST[meal]."','".$_POST[business]."','".$_POST[other]."')";
	
  if (!mysql_query($sql,$con))
  {
  die('Error: ' .mysql_error());
  }
 echo "1 record added'<br />' click here to continue registration ";
 
 mysql_close($con)
?>



Venkat is correct that your query was wrong, however that not why you were getting the syntax error :wink:

Your last line of code isnt terminated with a ;

[COLOR=#0000bb]

mysql_close($con)

[/COLOR]

to

[COLOR=#0000bb]

 mysql_close($con);

[/COLOR]

I’m getting the following error:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

I believe that it is because there is not a proper redirect but I’m not sure where to place it.

<?php

include 'global.php';

if ($_POST['register'])
{
//get form data
$first = ($_POST['first']);
$middle = ($_POST['middle']);
$last = ($_POST['last']);
$street1 = ($_POST['street1']); 
$street2 = ($_POST['street2']);
$city = ($_POST['city']); 
$state = ($_POST['state']); 
$zip = ($_POST['zip']); 
$home = ($_POST['home']); 
$cell = ($_POST['cell']); 
$work = ($_POST['work']);  
$media = ($_POST['media']); 
$meal = ($_POST['meal']); 
$business = ($_POST['business']); 
$other = ($_POST['other']); 
	
	//generate random code
    $code = rand(11111111,99999999);
	
	//send activation email
       $to = $email;
       $subject = "Thank you for your registration";
       $headers = "From: devingeesr@devingeesr.com";
       $body = "Hello $first,\
\
Thank You for registering!";

       if (!mail($to,$subject,$body,$headers))
           echo "We couldn't sign you up at this time. Please try again later.";
       else
	   {
		//register to database
		$register = mysql_query("INSERT INTO fvconference VALUES 
		('','$first','middle','$last','street1','street2','city','state','zip','home','cell','work','media','meal','business','other','code')");
		echo "You have been registered successfully! Please check your email";
		}
	}

else
{

?>

<div class="secSet9">
<form method="post" action="/proto/templates/bin/submit.php">
<div class="name">
<h3>Name</h3>
<div class="labelName">First:</div>
<div class="inputName"><input class="inputName" type="text" name="first" /></div>
<div class="labelName">Middle:</div>
<div class="inputName"><input class="inputName" type="text" name="middle" /></div>
<div class="labelName">Last:</div>
<div class="inputName"><input class="inputName" type="text" name="last" /></div>
</div>

<div class="addres">
<h3>Address</h3>
<div class="labelName">Street1:</div>
<div class="inputAdd"><input typ="text" name="street1" /></div>
<div class="labelName">Street2:</div>
<div class="inputAdd"><input typ="text" name="street2" /></div>
<div class="labelName">City:</div>
<div class="inputAdd"><input typ="text" name="city" /></div>
<div class="labelName">State:</div>
<select name="state">
  <option>AL</option>
  <option>AK</option>
  <option>AS</option>
  <option>AZ</option>
  <option>AR</option>
  <option>CA</option>
  <option>CO</option>
  <option>CT</option>
  <option>DE</option>
  <option>DC</option>
  <option>FM</option>
  <option>FL</option>
  <option>GA</option>
  <option>GU</option>
  <option>HI</option>
  <option>ID</option>
  <option>IL</option>
  <option>IN</option>
  <option>IA</option>
  <option>KS</option>
  <option>KY</option>
  <option>LA</option>
  <option>MEMH</option>
  <option>MD</option>
  <option>MA</option>
  <option>MI</option>
  <option>MN</option>
  <option>MS</option>
  <option>MO</option>
  <option>MT</option>
  <option>NE</option>
  <option>NV</option>
  <option>NH</option>
  <option>NJ</option>
  <option>NM</option>
  <option>NY</option>
  <option>NC</option>
  <option>ND</option>
  <option>MP</option>
  <option>OH</option>
  <option>OK</option>
  <option>OR</option>
  <option>PW</option>
  <option>PA</option>
  <option>PR</option>
  <option>RI</option>
  <option>SC</option>
  <option>SD</option>
  <option>TN</option>
  <option>TX</option>
  <option>UT</option>
  <option>VT</option>
  <option>VI</option>
  <option>VA</option>
  <option>WA</option>
  <option>WV</option>
  <option>WI</option>
  <option>WY</option>
  </select><br />
<div class="labelName">Zip:</div>
<div class="inputZip"><input typ="text" name="zip" /></div>
</div>

<div class="phone">
  <h3>Phone</h3>
  <div class="labelName">Home:</div>
  <div class="inputPh"><input type="text" name="home" /></div>
  <div class="labelName">Cell:</div>
  <div class="inputPh"><input type="text" name="cell" /></div>
  <div class="labelName">Work:</div>
  <div class="inputPh"><input type="text" name="work" /></div>
</div> 

<div class="email">
	<h3>Email</h3>
	<div class="labelName">Email</div>
	<div class="inputemail"><input type="text" name="email"/></div>

<div class="media">
  <h3>Media Preference</h3>
  <div class="labelName">Media:</div>
  <select name="media">
  <option>Braille</option>
  <option>Large Print</option>
  <option>Electronic</option>
  </select>
</div>

<div class="meal">
  <h3>Meal Preference</h3>
  <div class="labelMeal">Regular - TBD</div>
  <input type="checkbox" name="meal" value="regular" /><br />
  
  <div class="labelMeal">Veggie - TBD</div>
  <input type="checkbox" name="meal" value="veggie" />
</div>

<div class="business">
<h3>Business Unit</h3>
<div class="inputText">
<textarea name="business">
</textarea>
</div>
<div class="sp1"></div>
</div>
<div class="other">
<h3>Other Special needs</h3>
  <div class="inputText">
  <textarea name="other">
  </textarea>
  </div>
  <div class="sp1"></div>
  </div>
  <input type="submit" class="button" name="register" value="Register" />
  </form>
</div>

<?php

}
?>

What is the error, make it clear?

i fixed it thanks!

Ok I have this forum and it’s doing nothing it’s not post nor giving any errors:

<?php
echo "<h1>Register</h1>";

//grab submited data
$submit =& $_POST['submit'];
$first =& $_POST['first'];
$middle =& $_POST['middle'];
$last =& $_POST['last'];
$street1 =& $_POST['street1'];
$street2 =& $_POST['street2'];
$city =& $_POST['city'];
$state =& $_POST['state'];
$home =& $_POST['home'];
$cell =& $_POST['cell'];
$work =& $_POST['work'];
$email =& $_POST['email'];
$media =& $_POST['media'];
$meal =& $_POST['meal'];
$business =& $_POST['business'];
$other =& $_POST['other'];

//Remove coding tags
$first = strip_tags("first");
$middle = strip_tags("middle");
$last = strip_tags("last");
$street1 = strip_tags("street1");
$street2 = strip_tags("street2");
$city = strip_tags("city");
$state = strip_tags("state");
$home = strip_tags("home");
$cell = strip_tags("cell");
$work = strip_tags("work");
$email = strip_tags("email");
$media = strip_tags("media");
$meal = strip_tags("meal");
$business = strip_tags("business");
$other = strip_tags("other");
$date = date("Y-m-d");

if ($submit)
{

	//open database
	$connect = mysql_connect("localhost","root","");
	mysql_select_db("phplogin"); //select database

$queryreg = mysql_query("INSERT INTO register VALUES('','$first',$middle','$last','$street1','$street2','$city','$state','$home','$cell','$work','$email','$media','$business','$other','$date')");
}
else echo "Please fill enter your details and click Resgister";



?>
<p>

<form action="index.php?page=con_reg&section=conference" method="POST">

<fieldset>
<legend>Name</legend>
<label for="first">First</label><br />
<input type="text" name="first" /><br />

<label for="middle">Middle</label><br />
<input type="text" name="middle" /><br />

<label for="last">Last</label><br />
<input type="text" name="last" />
</fieldset>

<fieldset>
<legend>Address</legend>
<label for="street1">Street1</label><br />
<input type="text" name="street1" /><br />

<label for="street2">Street2</label><br />
<input type="text" name="street2" /><br />

<label for="city">City</label><br />
<input type="text" name="city" /><br />

<label for="state">State</label><br />
<select name="state">
  <option>AL</option>
  <option>AK</option>
  <option>AS</option>
  <option>AZ</option>
  <option>AR</option>
  <option>CA</option>
  <option>CO</option>
  <option>CT</option>
  <option>DE</option>
  <option>DC</option>
  <option>FM</option>
  <option>FL</option>
  <option>GA</option>
  <option>GU</option>
  <option>HI</option>
  <option>ID</option>
  <option>IL</option>
  <option>IN</option>
  <option>IA</option>
  <option>KS</option>
  <option>KY</option>
  <option>LA</option>
  <option>MEMH</option>
  <option>MD</option>
  <option>MA</option>
  <option>MI</option>
  <option>MN</option>
  <option>MS</option>
  <option>MO</option>
  <option>MT</option>
  <option>NE</option>
  <option>NV</option>
  <option>NH</option>
  <option>NJ</option>
  <option>NM</option>
  <option>NY</option>
  <option>NC</option>
  <option>ND</option>
  <option>MP</option>
  <option>OH</option>
  <option>OK</option>
  <option>OR</option>
  <option>PW</option>
  <option>PA</option>
  <option>PR</option>
  <option>RI</option>
  <option>SC</option>
  <option>SD</option>
  <option>TN</option>
  <option>TX</option>
  <option>UT</option>
  <option>VT</option>
  <option>VI</option>
  <option>VA</option>
  <option>WA</option>
  <option>WV</option>
  <option>WI</option>
  <option>WY</option>
  </select><br />
<label for="addzip">Zip:</label><br />
<input typ="text" name="addzip" />
</fieldset>

<fieldset>
<legend>Phone</legend>
<label for="home">Home:</label><br />
<input type="text" name="home" maxlength='10'/><br />

<label for="cell">Cell:</label><br />
<input type="text" name="cell"  maxlength='10'/><br />

<label for="work">Work:</label><br />
<input type="text" name="work"  maxlength='10'/>
</fieldset>  
<fieldset>

<legend>Email</legend>
<label for="email">Email: </label>
<input type="text" name="email" />
</fieldset>  

<fieldset>
<legend>Media Preference</legend>
<select name="media">
  <option>Braille</option>
  <option>Large Print</option>
  <option>Electronic</option>
</select>
</fieldset>

<fieldset>
<legend>Meal Preference</legend>
<select name="meal">
	<option>Regular - TBD</option>
	<option>Veggie - TBD</option>
</select>
</fieldset>

<fieldset>
<legend>Business Unit</legend>
<textarea name="business"></textarea>
</fieldset>

<fieldset>
<legend>Other Special needs</legend>
<textarea name="other"></textarea>
</fieldset>
<button type="submit" class="button" value="submit" name="submit">Submit</button>
</form>




<button type="submit" class="button" value="submit" name="submit">Submit</button>

That is an invalid html form so it will not send (in its present form without the aid of some javascript), Should be:


<input type=submit />

If you add some error checking you should be good to go.


<?php
if('POST' === $_SERVER['REQUEST_METHOD']){
  
  $con = mysql_connect('host', 'user', 'pass');
  
  mysql_select_db('database', $con);
  
  $fields = array(
    'first'     => '',
    'middle'    => '',
    'last'      => '',
    'street1'   => '',
    'street2'   => '',
    'city'      => '',
    'state'     => '',
    'home'      => '',
    'cell'      => '',
    'work'      => '',
    'email'     => '',
    'media'     => '',
    'meal'      => '',
    'business'  => '',
    'other'     => '',
  );
  
  foreach($fields as $key => & $value){
    if(array_key_exists($key, $_POST)){
      $value = mysql_real_escape_string($_POST[$key]);
    }
  }
  
  $sql = sprintf(
    "INSERT INTO table ('%s') VALUES ('%s');",
    implode("', '", array_keys($fields)),
    implode("', '", array_values($fields))
  );
  
  mysql_query($sql, $con);
}

Let me know if you have any specific questions.