หน้า 1 จากทั้งหมด 1

ดูโค้ดให้หน่อยค่ะ มันเข้าแต่ else ไม่เข้า if เลย มือใหม่หัดเขียน ชี้แนะด้วยค่ะ

โพสต์แล้ว: 12/10/2012 3:54 pm
โดย memooApple
1. ไฟล์ add.php
<form id="form2" name="form2" method="post" action="add_product1.php" enctype="multipart/form-data">
<table width="485" border="0">
<tr>
<th width="86" scope="col">รหัสสินค้า</th>
<td width="389"><label for="num_pro"></label>
<input type="text" name="num_pro" id="num_pro" />
</tr>
<tr>
<th scope="row"><span class="style23">ชื่อสินค้า</span></th>
<td><input name="name_pic" type="text" id="name_pic" size="45" /></td>
</tr>
<tr>
<th scope="row"><span class="style23">ราคา</span></th>
<td><input type="text" name="price" id="price" /></td>
</tr>
<tr>
<th scope="row"><span class="style23">ภาพสินค้า</span></th>
<td><input name="fileupload " type="file" id="fileupload " size="45" /></td>
</tr>
<tr>
<th scope="row">&nbsp;</th>
<td><input type="submit" name="Submit" id="Submit" value="เพิ่มสินค้า" />
<input type="submit" name="reset" id="reset" value="ยกเลิก" /></td>
</tr>
</table>
</form>



2. ไฟล์ add1.php

โค้ด: เลือกทั้งหมด

<? 
$num_pro= $_POST['num_pro'];        
$name_pic = $_POST['name_pic'];        
$price = $_POST['price'];
$fileupload = $_POST['pic_pro'];

@mysql_connect("localhost", "root", "1234") or die (mysql_error());
@mysql_select_db ("furniture");

    if($name_pic=="")
        @mysql_query($sql) or die (mysql_error());
        {
          if(move_uploaded_file($_FILES["fileupload "]["tmp_name"],"product/$fileupload ".$_FILES["fileupload "]["name"]))
               {
            echo"complete";
            $pro_pic = $_FILES["fileupload "]["name"];
              $sql = "Insert into product  (id_pic,num_pro,name_pic,price,fileupload) values('','$num_pro','$name_pic','$price','$fileupload ');";
             
            }
         else
            {
              echo"NO";
             }
        }
?>
[/color]

Re: ดูโค้ดให้หน่อยค่ะ มันเข้าแต่ else ไม่เข้า if เลย มือใหม่หัดเขียน ชี้แนะด้วยค่ะ

โพสต์แล้ว: 12/10/2012 4:10 pm
โดย mindphp
โค้ด

โค้ด: เลือกทั้งหมด

    if($name_pic=="")
        @mysql_query($sql) or die (mysql_error());
        { 
ต้องการทำอะไรคับ

Re: ดูโค้ดให้หน่อยค่ะ มันเข้าแต่ else ไม่เข้า if เลย มือใหม่หัดเขียน ชี้แนะด้วยค่ะ

โพสต์แล้ว: 12/10/2012 4:56 pm
โดย iBest

โค้ด: เลือกทั้งหมด

action="add_product1.php"
ใช่ไฟล์เดียวกับ add1.php ที่บอกรึเปล่าคับ

Re: ดูโค้ดให้หน่อยค่ะ มันเข้าแต่ else ไม่เข้า if เลย มือใหม่หัดเขียน ชี้แนะด้วยค่ะ

โพสต์แล้ว: 15/10/2012 10:33 am
โดย HurricaneCyber
ตรง @mysql_query($sql) or die (mysql_error());
มันน่าจะอยู่ข้างล่าง $sql = "Insert into product (id_pic,num_pro,name_pic,price,fileupload) values('','$num_pro','$name_pic','$price','$fileupload ');"; รึเปล่า

แล้วที่เข้า else ตลอด หมายถึงมัน แสดงว่า NO ตลอดใช่ไหมครับ ถ้าใช่ ลองเช็คโฟลเดอร์ที่จะอัพโหลดไฟล์ไปใส่ดูว่าถูกต้องรึเปล่า
ลอง echo "product/$fileupload ".$_FILES["fileupload "]["name"]; มาเช็คดูครับ

และตรง $fileupload = $_POST['pic_pro'];
$_POST['pic_pro'] คือค่าไหนครับ ในฟอร์มไม่มีการส่งค่านี้มาเลย