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
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
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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