Forum Moderators: coopster

Message Too Old, No Replies

query problem

         

broC

7:00 am on Feb 27, 2008 (gmt 0)

10+ Year Member



im doing project for college.as im new to php n mysql,i dunt know much about programming language.im doing a simple form that contain name,email,contact,person attend and comment..and for this stage,i already put the validation for all area.its work when i click submit.however,it just prompt the error.but still query to database..here is mycoding
<table width="1000" height="95" border="1">
<tr>
<td bgcolor="#0000FF">&nbsp;</td>
</tr>
</table>

<center>

<?
include("connect.php");
//this is your validation in the form,put it here....
{

if (empty($_POST['name']))
{$errors[] = 'Please enter a name';}
if (empty($_POST['email']))
{$errors[] = 'Please enter a valid e-mail address';}
else if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$",
$_POST['email']))
{$errors[] = 'Please enter a valid e-mail address';}
if (empty($_POST['contact']))
{$errors[] = 'Please enter a valid contact with numeric value';}
else if (!is_numeric($_POST['contact']))
{$errors[] = 'Please enter a valid contact with a numeric value';}


if (empty($_POST['person_attend']))
{$errors[] = 'Please enter some word for person attend';}


else if (strlen ($_POST['person_attend']) > 255)
{$errors[] = 'person attend';}



if (empty($_POST['comment']))
{$errors[] = 'Please enter some comment';}
else if (strlen ($_POST['comment']) > 255)
{$errors[] = 'comment ';}

if(isset($errors))
{foreach($errors as $val)
{echo "Error: $val <br/>";}}


if($name="" && $email="" && $contact="" && $person_attend="" && $comment="" )

{} else {}


//this is your add query....

$name = $_POST['name'];

$email = $_POST['email'];

$contact = $_POST['contact'];

$person_attend = $_POST['person_attend'];

$comment = $_POST['comment'];

$query = "INSERT INTO rsvp (id, name, email, contact, person_attend, comment)

VALUES ('', '$name', '$email', '$contact', '$person_attend', '$comment')";

$results = mysql_query($query) or die

("Could not execute query : $query." . mysql_error());

{

echo "thanks you ";

}

mysql_close();
}

?>
</center>
<center>
<br>
<a href="Index.php">View list attend</a><br>
<a href="register.html">Clik here to register</a>
</center>

which part is wrong?

phparion

9:27 am on Feb 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



your code is very poor logically, besides, do this

if($name="" && $email="" && $contact="" && $person_attend="" && $comment="" && !is_array($errors) )

it means no error is caught in previous steps and errors array is empty.. define errors array before you starting to store values in it with an empty value e.g

$errors = array();

it might also work without defining it since php does most of at the time of compiling but not sure..

broC

9:46 am on Feb 27, 2008 (gmt 0)

10+ Year Member



which line should i replace?
sory..noob here

dreamcatcher

11:18 am on Feb 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also, your logic isn`t correct on your checking.

$name=""

Should be:

$name==""

dc

broC

12:50 am on Feb 28, 2008 (gmt 0)

10+ Year Member



done with $name==""

somehow its error
Notice: Undefined variable: name in c:\program files\easyphp1-8\www\rsvp\added.php on line 46

dreamcatcher

9:46 am on Feb 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Its because you haven`t declared the variable before you have used it. You should use:

if ($_POST['name']==''..

Using $name would only work with register_globals ON, which you don`t want. Always use the post array var as above.

dc