A
Anonymous
Guest
Hi,
i'm trying to write a page to add records into my MySQL database through a form,
but i cannot add record into it(i check it with the SELECT * from guestbook; command at the MySQL,but it return an empty set). Anyone know what's wrong with it?Thanks
here's the coding :
i'm trying to write a page to add records into my MySQL database through a form,
but i cannot add record into it(i check it with the SELECT * from guestbook; command at the MySQL,but it return an empty set). Anyone know what's wrong with it?Thanks
here's the coding :
Code:
<?php
$name=$HTTP_POST_VARS['name'];
$location=$HTTP_POST_VARS['location'];
$email=$HTTP_POST_VARS['email'];
$url=$HTTP_POST_VARS['url'];
$comments=$HTTP_POST_VARS['comments'];
$submit=$HTTP_POST_VARS['submit'];
$text="";
$db = @ mysql_pconnect('localhost', 'usr', 'pass');
mysql_select_db('database');
$checkQuery="select * from guestbook where email=\"$email\"";
$result=mysql_query($checkQuery);
$num_result=mysql_num_rows($result);
if (!$db)
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
mysql_select_db('B0300641');
if(empty($email))
{
$text.="<li>Please enter email.</li>";
$submit=false;
}
else if(!ereg("(.*@.*.\..*)",$email))
{
$text.="<li>$email doesn't look like a valid e-mail address</li>";
$submit=false;
}
else if($num_result!=0)
{
$text.="<li>$email have already sign the guestbook.</li>";
$submit=false;
}
if(empty($name))
{
$text.="<li>Please enter name.</li>";
$submit=false;
}
if(!empty($url) && !ereg("^http://.*.\..*",$url))
{
$text.="<li>$url doesn't look like a valid URL</li>";
$submit=false;
}
if ($submit)
{
$query="insert into guestbook(name,location,email,url,comments)
values('".$name."','".$location."',
'".$email."','".$url."',
'".$comments."')";
mysql_query($query);
echo '<h2>Thanks!</h2>';
echo '<h2><a href="view.php">View My Guest Book!!!</a></h2>';
}
else
{
echo '<ul>';
echo $text;
echo '</ul>';
include('sign.php');
}
?>