Jump to content


Photo

Why wont this code work


  • Please log in to reply
10 replies to this topic

#1 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 02 April 2006 - 02:19 AM

everything works...but the last 'if'.... it checks everything and if correct sends off the form to a database!(bolded) please help! also please only rewrite what i should put replacing the bold...(makes it less confusing)

<html>

<head>
<title></title>
</head>

<body text="#FF0000" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">

<p align="center"><font face="Aachen-Bold" size="6" color="#FF0000">Splatmen
Paintball Club</font>
<p align="center"><font color="#FF0000" face="Comic Sans MS"><a href="http://">Home</a>
<a href="../Pictures.htm">
Pictures</a> <a href="members.php">Members</a> <a href="http://www.mattswebp...13ab">Forum</a>
<a href="../Membership.php">
Player Info</a> <a href="../Chat_Room.htm">Chat room</a>
<a href="../schedule.htm"> Schedule</a> <a href="../Contact.htm"> Contact</a></font></p>

<p>
<?php

if(isset($_POST['submit']))
{

if(!empty($_POST['first'])){
$first=$_POST['first'];}
else{
$name = NULL;
echo "<p><font color=\"yellow\">*Please enter your First Name!</font></p>";
}
if(!empty($_POST['last'])){
$last=$_POST['last'];
}else{
$last = NULL;
echo "<p><font color=\"yellow\">*Please enter your last Name!</font></p>";}

if(!empty($_POST['gun'])){
$gun=$_POST['gun'];
}else{
$gun = NULL;
echo "<p><font color=\"yellow\">*Please enter what kind of gun you have!</font></p>";}

if(!empty($_POST['age'])){
$age=$_POST['age'];
}else{
$age = NULL;
echo "<p><font color=\"yellow\">*Please enter how old you are!</font></p>";}

if(!empty($_POST['saying'])){
$saying=$_POST['saying'];
}else{
$saying = NULL;
echo "<p><font color=\"yellow\">*Please enter a saying!</font></p>";}

if(!empty($_POST['email'])){
$email=$_POST['email'];
}else{
$email = NULL;
echo "<p><font color=\"yellow\">*Please enter your Email Address!</font></p>";}

if(!empty($_POST['phone'])){
$phone=$_POST['phone'];
}else{
$phone = NULL;
echo "<p><font color=\"yellow\">*Please enter your Phone Number!</font></p>";}

if(!empty($_POST['user'])){
$users=$_POST['user'];
}else{
$users = NULL;
echo "<p><font color=\"yellow\">*Please enter a Username!</font></p>";}

if(!empty($_POST['pass'])){
$passs=$_POST['passs'];
}else{
$passs = NULL;
echo "<p><font color=\"yellow\">*Please enter a Password!</font></p>";}
if ($first && $last && $gun && $age && $saying && $email && $phone && $users && $passs)
{
$host = "localhost";
$user = "--";
$pass = "--";
$db = "mattswebpage_com_-_web";

$connection = mysql_connect($host,$user,$pass) or die ("Unable to
connect!");

mysql_select_db($db) or die ("Unable to select database!");

$query = "INSERT INTO members VALUES ('$first','$last','$gun','$age','$saying','$email','$phone','$users','$passs')";
mysql_query($query);
}

}
?>

<form method="POST" name="membership" action="Membership.php">
<p align="center">First name <input type="text" name="first" size="20">
Last Name:<input type="text" name="last" size="24">
<br><br>
Phone#<input type="text" name="phone">(format= 000-0000)
<p align="center">
Gun type:<input type="text" name="gun" size="36"><br>
<br>
Age:<input type="text" name="age" size="3"><br>
<br>
Saying:<br>
<textarea rows="2" name="saying" cols="20"></textarea></p>
<p align="center">
Current email address:<input type="text" name="email" size="36">
</p>
<p align="center">
Desired Username:<input type="text" name="user" size="20">
</p>
<p align="center">
Desired pass:<input type="password" name="pass" size="20">
</p>
<p align="center">
</p>
<p align="center"><input type="submit" value="Submit" name="submit"></p>
</form>
</html>
"Syntax error" .. WHERE THE **** IS IT?!

#2 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 02 April 2006 - 02:25 AM

if (($first) AND ($last) AND ($gun) AND ($age) AND ($saying) AND ($email) AND ($phone) AND ($users) AND ($passs))
{
$host = "localhost";
$user = "--";
$pass = "--";
$db = "mattswebpage_com_-_web";

$connection = mysql_connect($host,$user,$pass) or die ("Unable to
connect!");

mysql_select_db($db) or die ("Unable to select database!");

$query = "INSERT INTO members VALUES ('$first','$last','$gun','$age','$saying','$email','$phone','$users','$passs')";
mysql_query($query);
}

try that ;)

#3 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 02 April 2006 - 02:46 AM

[!--quoteo(post=360782:date=Apr 1 2006, 09:25 PM:name=darkcarnival)--][div class=\'quotetop\']QUOTE(darkcarnival @ Apr 1 2006, 09:25 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
if (($first) AND ($last) AND ($gun) AND ($age) AND ($saying) AND ($email) AND ($phone) AND ($users) AND ($passs))
{
$host = "localhost";
$user = "--";
$pass = "--";
$db = "mattswebpage_com_-_web";

$connection = mysql_connect($host,$user,$pass) or die ("Unable to
connect!");

mysql_select_db($db) or die ("Unable to select database!");

$query = "INSERT INTO members VALUES ('$first','$last','$gun','$age','$saying','$email','$phone','$users','$passs')";
mysql_query($query);
}

try that ;)
[/quote]

no didnt work i tried replacing the connection stuff with an echo and it still didnt work so it much be something wrong with the if statement..(maybe something to do with the rest of the code?)

"Syntax error" .. WHERE THE **** IS IT?!

#4 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 02 April 2006 - 04:48 AM

ok well i have another idea for ya.

i did this for a install script i made.

basically a variable that would be set to ture all the time.

then check for that variable.

heres an eamxple of what i mean.

if($name !== ""){
$name_r = true;
}
if ($age !== ""){
$age_r = true;
}

then check for those variables like so:

if (($name_r == true) and ($age_r == true)){
//go further in script
}

give that a try.

#5 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 02 April 2006 - 04:35 PM

this comes up....line 97 is the if command...

Parse error: parse error, unexpected '{' in /var/www/html/splatmenpaintball/memshiphandler.php on line 97

when i remove the { stating where the if command starts it says unexpecting T_variable
"Syntax error" .. WHERE THE **** IS IT?!

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 April 2006 - 05:06 PM

You can also try like this but add this afther trying the below code.

if ((!$first)||(!$last)||(!$gun)||(!$age)||(!$saying)||(!$email)||(!$phone)||(!$users)||(!$passs)) {
}



Try The code this way ok if the database gets the entrys then add the above code ok or leave as it is.

Good luck.

Always make a backup of your data before trying anythink.


<html>

<head>
<title></title>
</head>

<body text="#FF0000" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">

<p align="center"><font face="Aachen-Bold" size="6" color="#FF0000">Splatmen
Paintball Club</font>
<p align="center"><font color="#FF0000" face="Comic Sans MS"><a href="http://">Home</a>
<a href="../Pictures.htm">
Pictures</a> <a href="members.php">Members</a> <a href="http://www.mattswebpage.com/mainforum/viewforum.php?f=1&sid=4ab3e05eef87dc57e23c7fdf72eb13ab">Forum</a>
<a href="../Membership.php">
Player Info</a> <a href="../Chat_Room.htm">Chat room</a>
<a href="../schedule.htm"> Schedule</a> <a href="../Contact.htm"> Contact</a></font></p>

<p>
<?php

$host = "localhost";
$user = "--";
$pass = "--";
$db = "mattswebpage_com_-_web";

$connection = mysql_connect($host,$user,$pass) or die ("Unable to
connect!");

mysql_select_db($db) or die ("Unable to select database!");


if(isset($_POST['submit']))
{

if(!empty($_POST['first'])){
$first=$_POST['first'];}
else{
$name = NULL;
echo "<p><font color=\"yellow\">*Please enter your First Name!</font></p>";
}
if(!empty($_POST['last'])){
$last=$_POST['last'];
}else{
$last = NULL;
echo "<p><font color=\"yellow\">*Please enter your last Name!</font></p>";}

if(!empty($_POST['gun'])){
$gun=$_POST['gun'];
}else{
$gun = NULL;
echo "<p><font color=\"yellow\">*Please enter what kind of gun you have!</font></p>";}

if(!empty($_POST['age'])){
$age=$_POST['age'];
}else{
$age = NULL;
echo "<p><font color=\"yellow\">*Please enter how old you are!</font></p>";}

if(!empty($_POST['saying'])){
$saying=$_POST['saying'];
}else{
$saying = NULL;
echo "<p><font color=\"yellow\">*Please enter a saying!</font></p>";}

if(!empty($_POST['email'])){
$email=$_POST['email'];
}else{
$email = NULL;
echo "<p><font color=\"yellow\">*Please enter your Email Address!</font></p>";}

if(!empty($_POST['phone'])){
$phone=$_POST['phone'];
}else{
$phone = NULL;
echo "<p><font color=\"yellow\">*Please enter your Phone Number!</font></p>";}

if(!empty($_POST['user'])){
$users=$_POST['user'];
}else{
$users = NULL;
echo "<p><font color=\"yellow\">*Please enter a Username!</font></p>";}

if(!empty($_POST['pass'])){
$passs=$_POST['passs'];
}else{
$passs = NULL;
echo "<p><font color=\"yellow\">*Please enter a Password!</font></p>";}

$query = "INSERT INTO members VALUES ('$first','$last','$gun','$age','$saying','$email','$phone','$users','$passs')";
mysql_query($query);
}
?>

<form method="POST" name="membership" action="Membership.php">
<p align="center">First name <input type="text" name="first" size="20">
Last Name:<input type="text" name="last" size="24">
<br><br>
Phone#<input type="text" name="phone">(format= 000-0000)
<p align="center">
Gun type:<input type="text" name="gun" size="36"><br>
<br>
Age:<input type="text" name="age" size="3"><br>
<br>
Saying:<br>
<textarea rows="2" name="saying" cols="20"></textarea></p>
<p align="center">
Current email address:<input type="text" name="email" size="36">
</p>
<p align="center">
Desired Username:<input type="text" name="user" size="20">
</p>
<p align="center">
Desired pass:<input type="password" name="pass" size="20">
</p>
<p align="center">
</p>
<p align="center"><input type="submit" value="Submit" name="submit"></p>
</form>
</html>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 02 April 2006 - 05:41 PM

[!--quoteo(post=360912:date=Apr 2 2006, 12:06 PM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ Apr 2 2006, 12:06 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You can also try like this but add this afther trying the below code.

if ((!$first)||(!$last)||(!$gun)||(!$age)||(!$saying)||(!$email)||(!$phone)||(!$users)||(!$passs)) {
}
Try The code this way ok if the database gets the entrys then add the above code ok or leave as it is.

Good luck.

Always make a backup of your data before trying anythink.


<html>

<head>
<title></title>
</head>

<body text="#FF0000" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">

<p align="center"><font face="Aachen-Bold" size="6" color="#FF0000">Splatmen
Paintball Club</font>
<p align="center"><font color="#FF0000" face="Comic Sans MS"><a href="http://">Home</a>
<a href="../Pictures.htm">
Pictures</a> <a href="members.php">Members</a> <a href="http://www.mattswebpage.com/mainforum/viewforum.php?f=1&sid=4ab3e05eef87dc57e23c7fdf72eb13ab">Forum</a>
<a href="../Membership.php">
Player Info</a> <a href="../Chat_Room.htm">Chat room</a>
<a href="../schedule.htm"> Schedule</a> <a href="../Contact.htm"> Contact</a></font></p>

<p>
<?php

$host = "localhost";
$user = "--";
$pass = "--";
$db = "mattswebpage_com_-_web";

$connection = mysql_connect($host,$user,$pass) or die ("Unable to
connect!");

mysql_select_db($db) or die ("Unable to select database!");
if(isset($_POST['submit']))
{

if(!empty($_POST['first'])){
$first=$_POST['first'];}
else{
$name = NULL;
echo "<p><font color=\"yellow\">*Please enter your First Name!</font></p>";
}
if(!empty($_POST['last'])){
$last=$_POST['last'];
}else{
$last = NULL;
echo "<p><font color=\"yellow\">*Please enter your last Name!</font></p>";}

if(!empty($_POST['gun'])){
$gun=$_POST['gun'];
}else{
$gun = NULL;
echo "<p><font color=\"yellow\">*Please enter what kind of gun you have!</font></p>";}

if(!empty($_POST['age'])){
$age=$_POST['age'];
}else{
$age = NULL;
echo "<p><font color=\"yellow\">*Please enter how old you are!</font></p>";}

if(!empty($_POST['saying'])){
$saying=$_POST['saying'];
}else{
$saying = NULL;
echo "<p><font color=\"yellow\">*Please enter a saying!</font></p>";}

if(!empty($_POST['email'])){
$email=$_POST['email'];
}else{
$email = NULL;
echo "<p><font color=\"yellow\">*Please enter your Email Address!</font></p>";}

if(!empty($_POST['phone'])){
$phone=$_POST['phone'];
}else{
$phone = NULL;
echo "<p><font color=\"yellow\">*Please enter your Phone Number!</font></p>";}

if(!empty($_POST['user'])){
$users=$_POST['user'];
}else{
$users = NULL;
echo "<p><font color=\"yellow\">*Please enter a Username!</font></p>";}

if(!empty($_POST['pass'])){
$passs=$_POST['passs'];
}else{
$passs = NULL;
echo "<p><font color=\"yellow\">*Please enter a Password!</font></p>";}

$query = "INSERT INTO members VALUES ('$first','$last','$gun','$age','$saying','$email','$phone','$users','$passs')";
mysql_query($query);
}
?>

<form method="POST" name="membership" action="Membership.php">
<p align="center">First name <input type="text" name="first" size="20">
Last Name:<input type="text" name="last" size="24">
<br><br>
Phone#<input type="text" name="phone">(format= 000-0000)
<p align="center">
Gun type:<input type="text" name="gun" size="36"><br>
<br>
Age:<input type="text" name="age" size="3"><br>
<br>
Saying:<br>
<textarea rows="2" name="saying" cols="20"></textarea></p>
<p align="center">
Current email address:<input type="text" name="email" size="36">
</p>
<p align="center">
Desired Username:<input type="text" name="user" size="20">
</p>
<p align="center">
Desired pass:<input type="password" name="pass" size="20">
</p>
<p align="center">
</p>
<p align="center"><input type="submit" value="Submit" name="submit"></p>
</form>
</html>

[/quote]

Thankyou know the form is acculy sent to the dtabase(sumthing musta been screwed up before) but even after adding the if statment it still sends if fields are left blank.....

"Syntax error" .. WHERE THE **** IS IT?!

#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 April 2006 - 05:51 PM


Try it with a die; or exit;



if(isset($submit)) {

if(!empty($_POST['first'])){
$first=$_POST['first'];}
else{
$name = NULL;
echo "<p><font color=\"yellow\">*Please enter your First Name!</font></p>";
die;
}
}


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 April 2006 - 06:01 PM

I think this is correct not sure.


$first=$_POST['first'];// set before posting

if(isset($submit)) {

if(!empty(['first'])) {

echo "<p><font color=\"yellow\">*Please enter your First Name!</font></p>";

}
}


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 April 2006 - 06:22 PM


I got it to work this way try it.


<?


$host = "localhost";
$user = "--";
$pass = "--";
$db = "mattswebpage_com_-_web";

$connection = mysql_connect($host,$user,$pass) or die ("Unable to
connect!");

$first=$_POST['first'];// set before posting

if($submit) {

if(empty($first)) {

echo "<p><font color=\"yellow\">*Please enter your First Name!</font></p>";
}

$query = "INSERT INTO members VALUES ('$first','$last','$gun','$age','$saying','$email','$phone','$users','$passs')";
mysql_query($query);
}
?>

<form method="post" action="">
<input type="text" name="$first">
<input type="submit" name="submit">
</form>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#11 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 02 April 2006 - 06:25 PM

I got it using a book i just bought!!! i used an array! everything worked perfectly!

heres the finnal code!

<html>

<head>
<title></title>
</head>

<body text="#FF0000" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">

<p align="center"><font face="Aachen-Bold" size="6" color="#FF0000">Splatmen
Paintball Club</font>
<p align="center"><font color="#FF0000" face="Comic Sans MS"><a href="http://">Home</a>
<a href="../Pictures.htm">
Pictures</a> <a href="members.php">Members</a> <a href="http://www.mattswebpage.com/mainforum/viewforum.php?f=1&sid=4ab3e05eef87dc57e23c7fdf72eb13ab">Forum</a>
<a href="../Membership.php">
Player Info</a> <a href="../Chat_Room.htm">Chat room</a>
<a href="../schedule.htm"> Schedule</a> <a href="../Contact.htm"> Contact</a></font></p>

<p>
<?php

if(isset($_POST['submit']))
{
$errors = array();

        if(empty($_POST['first'])){
        $errors[] = '<p><font color=\"yellow\">*Please enter your first Name!</font></p>';
        }else{
        $first=$_POST['first'];
        }
        if(empty($_POST['last'])){
        $errors[] = '<p><font color=\"yellow\">*Please enter your last Name!</font></p>';
        }else{
        $last=$_POST['last'];
        }
        if(empty($_POST['gun'])){
        $errors[] = '<p><font color=\"yellow\">*Please enter your gun type!</font></p>';
        }else{
        $gun=$_POST['gun'];
        }
        if(empty($_POST['age'])){
        $errors[] = '<p><font color=\"yellow\">*Please enter your age!</font></p>';
        }else{
        $age=$_POST['age'];
        }
        if(empty($_POST['saying'])){
        $errors[] = '<p><font color=\"yellow\">*Please enter a saying!</font></p>';
        }else{
        $saying=$_POST['saying'];
        }
        if(empty($_POST['email'])){
        $errors[] = '<p><font color=\"yellow\">*Please enter a email!</font></p>';
        }else{
        $email=$_POST['email'];
        }
        if(empty($_POST['phone'])){
        $errors[] = '<p><font color=\"yellow\">*Please enter your Phone number!</font></p>';
        }else{
        $phone=$_POST['phone'];
        }
        if(empty($_POST['user'])){
        $errors[] = '<p><font color=\"yellow\">*Please enter your Username!</font></p>';
        }else{
        $users=$_POST['user'];
        }
        if(empty($_POST['pass'])){
        $errors[] = '<p><font color=\"yellow\">*Please enter your Password!</font></p>';
        }else{
        $passs=$_POST['pass'];
        }
if (empty($errors)) {
$host = "localhost";
$user = "--";
$pass = "--";
$db = "mattswebpage_com_-_web";

$connection = mysql_connect($host,$user,$pass) or die ("Unable to
connect!");

mysql_select_db($db) or die ("Unable to select database!");

$query = "INSERT INTO members VALUES ('$first','$last','$gun','$age','$saying','$email','$phone','$users','$passs')";
mysql_query($query);
}else{
foreach ($errors as $key){
echo "$key";
}
}
}
?>

<form method="POST" name="membership" action="Membership.php">
<p align="center">First name <input type="text" name="first" size="20">
Last Name:<input type="text" name="last" size="24">
<br><br>
Phone#<input type="text" name="phone">(format= 000-0000)
<p align="center">
Gun type:<input type="text" name="gun" size="36"><br>
<br>
Age:<input type="text" name="age" size="3"><br>
<br>
Saying:<br>
<textarea rows="2" name="saying" cols="20"></textarea></p>
<p align="center">
Current email address:<input type="text" name="email" size="36">
</p>
<p align="center">
Desired Username:<input type="text" name="user" size="20">
</p>
<p align="center">
Desired pass:<input type="password" name="pass" size="20">
</p>
<p align="center">
</p>
<p align="center"><input type="submit" value="Submit" name="submit"></p>
</form>
</html>

thankyou to everyone who help!
"Syntax error" .. WHERE THE **** IS IT?!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users