update database

tini ajah · Sep 21, 2011
saya punya form seperti ini. form ini adalah form untuk mengedit account yang ada fotonya.
<form method="post" name="userform" action="user_edit.php">
<table width="100%" border="0">
<tr><td align="center" height="50" colspan="2" bgcolor="#00FF00" style="font-family:Georgia, 'Times New Roman', Times, serif; font-size:22px; color:#F00; font-weight:bold;">
Edit Your Account
</td>
</tr>
<tr><td align="center" height="31" colspan="2" >

</td>
</tr>
  <tr>
    <td width="60%">
    <?php
	include "connection.php";
	$nam=$_SESSION['user_active'];
	$query=mysql_query("SELECT * FROM adminlogin where name='$nam'");
    $a=mysql_fetch_array($query);
		 
	?>
    <div class="eu">
    <table width="90%" border="0"  cellpadding="10">
  <tr>
    <td width="217">Name</td>
    <td width="8">:</td>
    <td width="414"><input name="name" type="text" id="textfield2" size="50" value="<?php echo $a[name]?>" /></td>
  </tr>
  <tr>
    <td>Email</td>
    <td>:</td>
    <td><input name="email" type="text" id="textfield" size="50" value="<?php echo $a['email']?>" /></td>
  </tr>
  <tr>
    <td>Address</td>
    <td>:</td>
    <td><input name="address" type="text" id="textfield3" size="50" value="<?php echo $a['alamat']?>" /></td>
  </tr>
  <tr>
    <td>Telephone</td>
    <td>:</td>
    <td><input name="tlp" type="text" id="textfield4" size="50" value="<?php echo $a['tlp']?>"/></td>
  </tr>
  <tr>
    <td>Foto</td>
    <td>:</td>
    <td><input name="foto" type="file" id="textfield5" size="38" value="<?php echo $a['foto']?>" /></td>
  </tr>
  <tr>
    <td>Password</td>
    <td>:</td>
    <td><input name="pwd" type="text" id="textfield6" size="50" value="<?php echo $a[password]?>" /></td>
  </tr>
   <tr>
    <td>New Password</td>
    <td>:</td>
    <td><input name="newpwd" type="text" id="textfield7" size="50" /></td>
  </tr>
   <tr>
    <td>Confirm New Password</td>
    <td>:</td>
    <td><input name="cnewpwd" type="text" id="textfield8" size="50" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><label>
      <input type="submit" name="save" id="button2" value="Edit" style="width:100px;" />
      <input type="reset" name="Reset" id="button3" value="Cancel" style="width:100px;" />
    </label></td>
  </tr>
</table>
</div>
</td>
    <td width="40%" valign="top"><div style="width:260px; height:310px; background:#FFF; padding:10px;"><img src="<?php echo $a[foto]?>" width="250" height="300" align="top" /></div></td>
  </tr>
</table>

</form>

Ini adalah actionnya.
<?php
include "connection.php";
$id = $_SESSION['user_active'];
$name = $_POST['name'];
$email = $_POST['email'];
$pwd = $_POST['pwd'];
$adress = $_POST['address'];
$tlp = $_POST['tlp'];
$fileName = $_FILES['foto']['name']; //get the file name
$fileSize = $_FILES['foto']['size']; //get the size
$fileError = $_FILES['foto']['error']; //get the error when upload
if($fileSize > 0 || $fileError == 0){ //check if the file is corrupt or error
$move = move_uploaded_file($_FILES['foto']['tmp_name'], 'C:\xampp\htdocs\ricepoint\admin-rp\foto'.$fileName); //save image to the folder
if($move){

$q = "update into adminlogin VALUES('','$name','$email','$pwd','$address','$tlp','../foto/$fileName' where name=$id)"; //insert image property to database
$result = mysql_query($q);
}
?>

tapi script saya diatas masih error. bingung salahnya dimana. mohon dibantu....
Silahkan login untuk menjawab!
1
Loading...
Ellyx Christian · Sep 21, 2011 · 1 Suka · 0 Tidak Suka
kamu salah dibagian form

<form method="post" name="userform" action="user_edit.php">

agar file mau terupload harus ditambahkan attribute enctype="multipart/form-data", seperti:

<form method="post" name="userform" action="user_edit.php" enctype="multipart/form-data">
0
Loading...
tini ajah · Sep 21, 2011 · 0 Suka · 0 Tidak Suka
masih ada error yg keluar di line 19 user_edit.php kak...
0
Loading...
Laily · Sep 21, 2011 · 0 Suka · 0 Tidak Suka
Kurang tutup kurung kurawal '}'
0
Loading...
tini ajah · Sep 21, 2011 · 0 Suka · 0 Tidak Suka
ga muncul error tp ga mw update ke database...
bingung kak....
maaf baru belajar...
0
Loading...
Laily · Sep 21, 2011 · 0 Suka · 0 Tidak Suka
Coba ke line 13 :
... 'C:\xampp\htdocs\ricepoint\admin-rp\foto'.$fileName);
Sepertinya kurang '\' --> 'C:\xampp\htdocs\ricepoint\admin-rp\foto\'.$fileName);
0
Loading...
Ellyx Christian · Sep 22, 2011 · 0 Suka · 0 Tidak Suka
kamu lupa menutup if bagian ini:
if($fileSize > 0 || $fileError == 0){
<?php
include "connection.php";
$id = $_SESSION['user_active'];
$name = $_POST['name'];
$email = $_POST['email'];
$pwd = $_POST['pwd'];
$adress = $_POST['address'];
$tlp = $_POST['tlp'];
$fileName = $_FILES['foto']['name']; //get the file name
$fileSize = $_FILES['foto']['size']; //get the size
$fileError = $_FILES['foto']['error']; //get the error when upload
if($fileSize > 0 || $fileError == 0){ //check if the file is corrupt or error
$move = move_uploaded_file($_FILES['foto']['tmp_name'], 'C:\xampp\htdocs\ricepoint\admin-rp\foto'.$fileName); //save image to the folder
if($move){
 
$q = "update into adminlogin VALUES('','$name','$email','$pwd','$address','$tlp','../foto/$fileName' where name=$id)"; //insert image property to database
$result = mysql_query($q);
}
}
?>
0
Loading...
tini ajah · Sep 22, 2011 · 0 Suka · 0 Tidak Suka
gimana ya scriptnya kalau mau nentuin folder uploadnya disimpan..???
dan script update databasenya bagian mana yg slah ya??
soalnya ga mau ke-update databasenya.
1
Loading...
Ellyx Christian · Sep 22, 2011 · 1 Suka · 0 Tidak Suka