Fri 13 Oct 2006 01:05:39
สวัสดีครับ
ผมเขียน code program ดังนี้ครับ
<?
function randomstr ($length)
{
$possible = 'abcdefghijklmnopqrstuvwxyz0198765432';
$str=" ";
while ( strlen ($str) < $length)
{
$str .= substr ($possible, (rand() % strlen($possible)), 1);
}
return ($str);
}
?>
<h3>New user registration</h3>
<?
$exit=0;
$link=mysql_connect("localhost","root","");
if(!$link)
{
print("Error");
}else{
mysql_select_db("member",$link);
$sql="select email1 from member where email1='$email1'";
$res=mysql_query($sql, $link);
$n=mysql_num_rows($res);
if($n==0){
$sql="insert into member (username,password,company,cperson,address,country,phone,fax,email1,email2,web,productd,agri,alkohol,nonal,bakery,cannedfood,cereals,candies,sugar,coffee,condiments,foodin,
fruits,dressings,meat,milk,oil,organic,pasta,ready,seafood,mail,fee,status,dtnow)
values('$email1','$password','$company','$cperson','$address','$country','$phone','$fax','$email1','$email2','$web','$productd','$agri','$alkohol','$nonal','$bakery','$cannedfood',
'$cereals','$candies','$sugar','$coffee','$condiments','$foodin','$fruits','$dressings','$meat','$milk','$oil','$organic','$pasta','$ready','$seafood','$mail','$fee','0',CURRENT_TIMESTAMP)";
$res =mysql_query($sql, $link);
if($res==1){
print("Please check your information again:");
$row=mysql_fetch_array($res);
?>
<p><form method="post" action="update.php">
Company:<input type="text" name="company" value="<? echo $row["company"];?>"><br>
Contact person:<input type="text" name="cperson" value="<?=$row[4]?>"><br>
Address:<input type="text" name="address" value="<?=$row[5]?>"><br>
<? $password=randomstr(6); ?>
Country:<select name="country"><option value="Albania"<? echo(($row["albania"]==albania)?"selected":"");?>>Albania</option><option value="Algeria"<? echo(($row["algeria"]==algeria)?"selected":"");?>>Algeria</option><option value="Argentina"<? echo(($row["argentina"]==argentina)?"selected":"");?>>Argentina</option></select>
Phone:<input type="text" name="phone" value="<?=$row[7]?>"><br>
Fax:<input type="text" name="fax" value="<?=$row[8]?>"><br>
Email_1:<input type="text" name="email1" value="<?=$row[9]?>"><br>
Email_2:<input type="text" name="email2" value="<?=$row[10]?>"><br>
Web:<input type="text" name="web" value="<?=$row[11]?>"><br>
Product detail:<input type="text" name="productd" value="<?=$row[12]?>"><br>
Product group:<br>
<input type="checkbox" name="agri" value="1"<? echo(($row["agri"]==1)?"checked":"");?>>Agricultural Products<br>
<input type="checkbox" name="alkohol" value="1"<? echo(($row["alkohol"]==1)?"checked":"");?>>Alkoholic Beverages<br>
<input type="checkbox" name="bakery"value="1"<? echo(($row["bakery"]==1)?"checked":"");?>>Bakery Products<br>
Would you like to receive food news?<br>
<input type="radio" name="mail" value="receive"<? echo (($row["mail"]=="1")?" checked":""); ?>>Receive<br>
<input type="radio" name="mail" value="nreceive"<? echo (($row["mail"]=="0")?" checked":""); ?>>Not receive
Member fee
<input type="radio" name="fee" value="1"<? echo (($row["fee"]=="1")?" checked":""); ?>>USD150/3 months<br>
<input type="radio" name="fee" value="2"<? echo (($row["fee"]=="2")?" checked":""); ?>>USD200/6 months<br>
<input type="radio" name="fee" value="3"<? echo (($row["fee"]=="3")?" checked":""); ?>>USD250/3 months<br>
<p><input type="submit" value="Confirm"></p>
</form>
<?
}else{
print("Error to register.");
}
}else{
print("This email already exists.");
}
}
?>
ปรากฎว่าเกิด error ดังนี้ครับ
New user registration
Please check your information again:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\appserv\www\main\member\member_regist.php on line 34
และข้อมูลก็ไม่สามารถดึงขึ้นมาจากฐานข้อมูลได้ครับ เป็นเพียงแต่ช่องว่าง ช่วยแนะนำด้วยครับ
Fri 13 Oct 2006 06:58:46
ขอบคุณครับ ผมได้ทำการ select แต่ข้อมูลก็ยังไม่ขึ้นครับ
<?
function randomstr ($length)
{
$possible = 'abcdefghijklmnopqrstuvwxyz0198765432';
$str=" ";
while ( strlen ($str) < $length)
{
$str .= substr ($possible, (rand() % strlen($possible)), 1);
}
return ($str);
}
?>
<h3>New user registration</h3>
<?
$exit=0;
$link=mysql_connect("localhost","root","");
if(!$link)
{
print("Error");
}else{
mysql_select_db("member",$link);
$sql="select email1 from member where email1='$email1'";
$res=mysql_query($sql, $link);
$n=mysql_num_rows($res);
if($n==0){
$sql="insert into member (username,password,company,cperson,address,country,phone,fax,email1,email2,web,productd,agri,alkohol,nonal,bakery,cannedfood,cereals,candies,sugar,coffee,condiments,foodin,
fruits,dressings,meat,milk,oil,organic,pasta,ready,seafood,mail,fee,status,dtnow)
values('$email1','$password','$company','$cperson','$address','$country','$phone','$fax','$email1','$email2','$web','$productd','$agri','$alkohol','$nonal','$bakery','$cannedfood',
'$cereals','$candies','$sugar','$coffee','$condiments','$foodin','$fruits','$dressings','$meat','$milk','$oil','$organic','$pasta','$ready','$seafood','$mail','$fee','0',CURRENT_TIMESTAMP)";
$res=mysql_query($sql, $link);
if($res==1){
print("Please check your information again:");
$sql="select email1 from member where email1='$email1'";
$res=mysql_query($sql, $link);
$n=mysql_num_rows($res);
$row=mysql_fetch_array($res);
?>
<p><form method="post" action="update.php">
Company:<input type="text" name="company" value="<? echo $row["company"];?>"><br>
Contact person:<input type="text" name="cperson" value="<?=$row[4]?>"><br>
Address:<input type="text" name="address" value="<?=$row[5]?>"><br>
<? $password=randomstr(6); ?>
Country:<select name="country"><option value="Albania"<? echo(($row["country"]==albania)?"selected":"");?>>Albania</option><option value="Algeria"<? echo(($row["country"]==algeria)?"selected":"");?>>Algeria</option><option value="Argentina"<? echo(($row["country"]==argentina)?"selected":"");?>>Argentina</option></select>
Phone:<input type="text" name="phone" value="<?=$row[7]?>"><br>
Fax:<input type="text" name="fax" value="<?=$row[8]?>"><br>
Email_1:<input type="text" name="email1" value="<?=$row[9]?>"><br>
Email_2:<input type="text" name="email2" value="<?=$row[10]?>"><br>
Web:<input type="text" name="web" value="<?=$row[11]?>"><br>
Product detail:<input type="text" name="productd" value="<?=$row[12]?>"><br>
Product group:<br>
<input type="checkbox" name="agri" value="1"<? echo(($row["agri"]==1)?"checked":"");?>>Agricultural Products<br>
<input type="checkbox" name="alkohol" value="1"<? echo(($row["alkohol"]==1)?"checked":"");?>>Alkoholic Beverages<br>
<input type="checkbox" name="bakery"value="1"<? echo(($row["bakery"]==1)?"checked":"");?>>Bakery Products<br>
Would you like to receive food news?<br>
<input type="radio" name="mail" value="receive"<? echo (($row["mail"]=="1")?" checked":""); ?>>Receive<br>
<input type="radio" name="mail" value="nreceive"<? echo (($row["mail"]=="0")?" checked":""); ?>>Not receive
Member fee
<input type="radio" name="fee" value="1"<? echo (($row["fee"]=="1")?" checked":""); ?>>USD150/3 months<br>
<input type="radio" name="fee" value="2"<? echo (($row["fee"]=="2")?" checked":""); ?>>USD200/6 months<br>
<input type="radio" name="fee" value="3"<? echo (($row["fee"]=="3")?" checked":""); ?>>USD250/3 months<br>
<p><input type="submit" value="Confirm"></p>
</form>
<?
}else{
print("Error to register.");
}
ผลที่แสดงได้ดังนี้ครับ
New user registration
Please check your information again:
รบกวนช่วยแนะนำด้วยครับ
อนันต์
$sql="select email1 from member where email1='$email1'";

















