943,152 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 565
  • PHP RSS
Mar 17th, 2010
0

control never goes in "else" part.. PHP/MYSQL

Expand Post »
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
PHP Syntax (Toggle Plain Text)
  1. <?
  2. require("Datab.class.php");
  3. $db = new Datab("localhost", "root", "intaha", "subc");
  4. $db->connect();
  5.  
  6. $result = $db->query("select * from category");
  7.  
  8. ?>
  9. <table border="1" cellpadding="0">
  10. <?
  11.  
  12. if(mysql_num_rows($result)){
  13.  
  14. while($rows = mysql_fetch_row($result)){ ?>
  15. <tr>
  16. <td><? echo $rows[0]; ?></td>
  17. <td><? echo $rows[1]; ?></td>
  18. <td><a href="edit.php?id=<?=$rows[0]?>">edit</a></td>
  19. <td><a href="delete.php?id=<?=$rows[0]?>">delete</a></td>
  20.  
  21.  
  22. </tr>
  23. <?
  24. }
  25. }
  26. ?> </table>

edit.php
PHP Syntax (Toggle Plain Text)
  1.  
  2. <html>
  3. <head>
  4. <title></title>
  5. </head>
  6. <body>
  7.  
  8.  
  9. <?php
  10. require("Datab.class.php");
  11. $db = new Datab("localhost", "root", "intaha", "subc");
  12. $db->connect();
  13. $id = $_GET['id'];
  14. echo "hello this is upper.... $id";
  15.  
  16. $result = $db->query("select name from category where category_id = $id");
  17.  
  18. $name = "";
  19. if(mysql_num_rows($result) > 0){
  20. while($rows = mysql_fetch_row($result)){
  21. $name = $rows[0];
  22. }
  23. }
  24.  
  25. if(!isset($_POST['submit'])){
  26. echo "<br> in !isset condition..... <br> ";
  27. ?>
  28. <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  29. <input type="text" name="cat_name" value= "<? echo $name; ?>" />
  30. <input type="submit" name="submit" value="edit" />
  31. </form>
  32. <?
  33. }else{
  34. echo "<br> in else condition..... <br> ";
  35. $uname= $_POST['cat_name'];
  36. echo "name = " .$uname;
  37. echo "in id = " . $id . " ";
  38. $result = $db->query("update category SET name = '$uname' where category_id = $id");
  39. echo "Category name changed ";
  40. }
  41. ?>
  42.  
  43.  
  44. </body>
  45. </html>
yun
Reputation Points: 10
Solved Threads: 2
Light Poster
yun is offline Offline
42 posts
since May 2009
Mar 17th, 2010
0
Re: control never goes in "else" part.. PHP/MYSQL
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">

I believe you have an extraneous '=' in there... Shouldn't that be an "echo"?
Last edited by Fbody; Mar 17th, 2010 at 11:24 am.
Featured Poster
Reputation Points: 833
Solved Threads: 392
Posting Maven
Fbody is offline Offline
2,846 posts
since Oct 2009
Mar 17th, 2010
0

control never goes in "else" part.. PHP/MYSQL

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
yun
Reputation Points: 10
Solved Threads: 2
Light Poster
yun is offline Offline
42 posts
since May 2009
Mar 17th, 2010
0
Re: control never goes in "else" part.. PHP/MYSQL
Look at lines 18 and 19 of view.php. Then look at my previous post.
Featured Poster
Reputation Points: 833
Solved Threads: 392
Posting Maven
Fbody is offline Offline
2,846 posts
since Oct 2009
Mar 17th, 2010
0
Re: control never goes in "else" part.. PHP/MYSQL
Click to Expand / Collapse  Quote originally posted by Fbody ...
Look at lines 18 and 19 of view.php. Then look at my previous post.
PHP Syntax (Toggle Plain Text)
  1.  
  2. <td><a href="edit.php?id=<? echo $rows[0]?>">edit</a></td>
  3. <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.
PHP Syntax (Toggle Plain Text)
  1.  
  2. <td><a href="edit.php?id=<?=$rows[0]?>">edit</a></td>
  3. <td><a href="delete.php?id=<?=$rows[0]?>">delete</a></td>
yun
Reputation Points: 10
Solved Threads: 2
Light Poster
yun is offline Offline
42 posts
since May 2009
Mar 17th, 2010
0
Re: control never goes in "else" part.. PHP/MYSQL
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.
Last edited by Fbody; Mar 17th, 2010 at 1:32 pm.
Featured Poster
Reputation Points: 833
Solved Threads: 392
Posting Maven
Fbody is offline Offline
2,846 posts
since Oct 2009
Mar 17th, 2010
0
Re: control never goes in "else" part.. PHP/MYSQL
Took out the db stuff as I don't have your tables and it worked fine:

PHP Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title></title>
  4. </head>
  5. <body>
  6.  
  7.  
  8. <?php
  9. $id = $_GET['id'];
  10. echo "hello this is upper.... $id";
  11.  
  12.  
  13. $name = "";
  14.  
  15.  
  16. if(!isset($_POST['submit'])){
  17. echo "<br> in !isset condition..... <br> ";
  18. ?>
  19. <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  20. <input type="text" name="cat_name" value= "<? echo $name; ?>" />
  21. <input type="submit" name="submit" value="edit" />
  22. </form>
  23. <?
  24. }else{
  25. echo "<br> in else condition..... <br> ";
  26. $uname= $_POST['cat_name'];
  27. echo "name = " .$uname;
  28. echo "in id = " . $id . " ";
  29. echo "Category name changed ";
  30. }
  31. ?>
  32.  
  33.  
  34. </body>
  35. </html>
Sponsor
Featured Poster
Reputation Points: 1041
Solved Threads: 935
Sarcastic Poster
ardav is offline Offline
6,620 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Php cms problem
Next Thread in PHP Forum Timeline: Php session





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC