ectraz Posted February 4, 2007 Share Posted February 4, 2007 Hey Guys. just a bit of advice really im relativly new to php and ive been doing some of my own work. just woundering if someone could go over an example of what ive done just give me some pointers of how i could improve what ive done. and if ive made any obviouse mistakes the code is all working absalutly fine but I would preffer to get things right the first time. Thanks ::: Code :::: <?php $get_add = $_GET['add']; $get_title = $_GET['level1title']; $get_title_upd = $_GET['level1title_upd']; if($get_title > ""){ if($get_add == "Add"){ #ADD# if(mysql_num_rows(mysql_query("SELECT * FROM tbl_tutorial_level1 WHERE tut_level1title='$get_title'")) < 1){ mysql_query("INSERT INTO tbl_tutorial_level1 (tut_level1title) VALUES ('$get_title')"); echo "Succesfully Added $get_title To Database!"; }else{ echo "$get_title Already Exists In Database!"; } }elseif($get_add == "Update"){ #UPDATE# if(mysql_num_rows(mysql_query("SELECT * FROM tbl_tutorial_level1 WHERE tut_level1title='$get_title_upd'")) > 0){ mysql_query("UPDATE tbl_tutorial_level1 SET tut_level1title = '$get_title' WHERE tut_level1title='$get_title_upd'"); echo "Succesfully Updates $get_title In Database"; }else{ echo "Cannot Update This Record it Dosent Exists"; } }elseif($get_add == "Delete"){ #DELETE# if(mysql_num_rows(mysql_query("SELECT * FROM tbl_tutorial_level1 WHERE tut_level1title='$get_title'")) > 0){ mysql_query("DELETE FROM tbl_tutorial_level1 WHERE tut_level1title='$get_title'"); echo "Succesfully Delete $get_title_upd From Database"; }else{ echo "Cannot Delete $get_title_upd From Database"; } } } ?> Quote Link to comment Share on other sites More sharing options...
only one Posted February 4, 2007 Share Posted February 4, 2007 yea i think it should work the only thing is when you are checkning if it already exists when you are creating a new one you might want to use the mysql_num_rows(); function to count how many of thing exists, then if($get_title > 0){ echo "already exists"; } else insert it... Quote Link to comment Share on other sites More sharing options...
ectraz Posted February 4, 2007 Author Share Posted February 4, 2007 mysql_num_rows(); is implemented after the if($get_title > ""){??? the only reason the if($get_title > ""){ is there is to check that a value has been got from post results i dont see a problem with this could you explain a little more in depth Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.