0

i m newbie in web development plz help me to sort out the problem..
the problem is: in edit.php when control enters in if condition it never goes to else when i press the edit button.

i want to get id from view.php and display category name in edit.php textbox so i can change the category name by pressing edit button.

view.php

<?
		require("Datab.class.php");
		$db = new Datab("localhost", "root", "intaha", "subc");
		$db->connect();
	
		$result = $db->query("select * from category");
		
		?>
		<table border="1" cellpadding="0">
        <? 

		if(mysql_num_rows($result)){
			
			while($rows = mysql_fetch_row($result)){ ?>
                <tr>
                <td><? echo $rows[0]; ?></td> 
                <td><? echo $rows[1]; ?></td>
                <td><a href="edit.php?id=<?=$rows[0]?>">edit</a></td>                
                <td><a href="delete.php?id=<?=$rows[0]?>">delete</a></td>
          
                           
				</tr>
            <?	
			}
		}
		?> </table>

edit.php

<html>
<head>
<title></title>
</head>
<body>


<?php
		require("Datab.class.php");
		$db = new Datab("localhost", "root", "intaha", "subc");
		$db->connect();
		$id = $_GET['id'];
		echo "hello this is upper.... $id";			
		
		$result = $db->query("select name from category where category_id = $id");
		
		$name = "";
		if(mysql_num_rows($result) > 0){
			while($rows = mysql_fetch_row($result)){
				$name = $rows[0];
			}
		}
		
	if(!isset($_POST['submit'])){
		echo "<br> in !isset condition..... <br> ";
		?>	
			<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
			<input type="text" name="cat_name"  value= "<? echo $name; ?>" />
			<input type="submit" name="submit" value="edit" />
			</form>
		<?
	}else{
		echo "<br> in else condition..... <br> ";
		$uname= $_POST['cat_name'];
		echo "name = " .$uname;
		echo "in id = " . $id . "  ";
		$result = $db->query("update category SET name = '$uname' where category_id = $id");
		echo "Category name changed ";
	}
		?>
        

</body>
</html>
3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by diafol
0

<form action="<?=$_SERVER?>" method="post">

I believe you have an extraneous '=' in there... Shouldn't that be an "echo"?

Edited by Fbody: n/a

0

below is the output after clicking the Edit button.

hello this is upper.... Error in query : select name from category where category_id = . You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

0

Look at lines 18 and 19 of view.php. Then look at my previous post.

<td><a href="edit.php?id=<? echo $rows[0]?>">edit</a></td>        
<td><a href="delete.php?id=<? echo $rows[0]?>">delete</a></td>

are same no difference at all.. echo and ?= did the same thing.. and the problem is in edit.php, view.php doing the same thing which i want.

<td><a href="edit.php?id=<?=$rows[0]?>">edit</a></td>        
<td><a href="delete.php?id=<?=$rows[0]?>">delete</a></td>
0

Open view.php in a browser and view the page source. Look for the HTML markup produced by lines 18 and 19. If there are not values in the "id" fields, the issue at least starts in view.php, not in edit.php. If there is a value, the issue could be in either file. I'm concerned about the part of your script that generates the link address(es). It appears that the ID is not getting into edit.php. Once we confirm that it is, we can go from there.

Edited by Fbody: n/a

0

Took out the db stuff as I don't have your tables and it worked fine:

<html>
<head>
<title></title>
</head>
<body>
 
 
<?php
		$id = $_GET['id'];
		echo "hello this is upper.... $id";			
 
		
		$name = "";
		
 
	if(!isset($_POST['submit'])){
		echo "<br> in !isset condition..... <br> ";
		?>	
			<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
			<input type="text" name="cat_name"  value= "<? echo $name; ?>" />
			<input type="submit" name="submit" value="edit" />
			</form>
		<?
	}else{
		echo "<br> in else condition..... <br> ";
		$uname= $_POST['cat_name'];
		echo "name = " .$uname;
		echo "in id = " . $id . "  ";
		echo "Category name changed ";
	}
		?>
 
 
</body>
</html>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.