Jump to content

Code Check


ectraz

Recommended Posts

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";

}

}

}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/37015-code-check/
Share on other sites

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...

 

Link to comment
https://forums.phpfreaks.com/topic/37015-code-check/#findComment-176709
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.