08-11-2008, 02:29
|
|
|
חבר מתאריך: 06.01.05
הודעות: 44
|
|
UPDATE לא עובד משום מה
היי
אני מנסה לבצע UPDATE, אבל משום מה זה לא קורה.
אולי למישהו מפה יש מושג למה הוא לא מצליח?
הנה הקוד:
קוד PHP:
<?php
header ('content-type: text/html; charset=utf-8');
header ('content-language: he');
$host="localhost"; // Host name
$username="test"; // Mysql username
$password="test"; // Mysql password
$db_name="test"; // Database name
$tbl_name="test1"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
mysql_query("SET NAMES utf8;");
$sql="SELECT * FROM $tbl_name ORDER BY cat_id, menu_id";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
?>
<html>
<head>
<title>Edit Categories</title>
<style>
* {font-family: Arial; font-size: 12px;}
input {direction:ltr; width: 200px}
h1 {font-size: 20px;}
</style>
</head>
<body>
<center>
<h1>Update All Records</h1>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<tr>
<td>
<table width="750" border="0" cellspacing="1" cellpadding="5">
<tr>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>Cat ID</strong></td>
<td align="center"><strong>Menu ID</strong></td>
<td align="center"><strong>Cat Title</strong></td>
<td align="center"><strong>File Name</strong></td>
<td align="center"><strong>Class Name</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $id=$rows['id']; ?><? echo $rows['id']; ?></td>
<td align="center"><input name="cat_id" type="text" id="cat_id" value="<? echo $rows['cat_id']; ?>"></td>
<td align="center"><input name="menu_id" type="text" id="menu_id" value="<? echo $rows['menu_id']; ?>"></td>
<td align="center"><input name="cat_title" type="text" id="cat_title" value="<? echo $rows['cat_title']; ?>" style="direction:rtl"></td>
<td align="center"><input name="file_name" type="text" id="file_name" value="<? echo $rows['file_name']; ?>"></td>
<td align="center"><input name="class_name" type="text" id="class_name" value="<? echo $rows['class_name']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="6" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
if($Submit){
// Check if button name "Submit" is active, do this
$id = $_POST['id'];
$cat_id = $_POST['cat_id'];
$menu_id = $_POST['menu_id'];
$cat_title = $_POST['cat_title'];
$file_name = $_POST['file_name'];
$class_name = $_POST['class_name'];
$sql1 = "UPDATE $tbl_name SET cat_id='$cat_id', menu_id='$menu_id', cat_title='$cat_title',
file_name='$file_name', class_name='$class_name' WHERE id='$id'";
$result1 = mysql_query($sql1);
}
if($result1){
echo "Saved!";
}
mysql_close();
?>
</center>
</body>
</html>
נערך לאחרונה ע"י blackman בתאריך 08-11-2008 בשעה 02:34.
|