hmark Posted January 4, 2010 Share Posted January 4, 2010 I know very little php. I'm hoping I could get some help from experts here. I would like to let users, Add, modify, or delete etries from the database. Right now, I got modify and delete to work. I'm having trouble with the ADD. My friend gave me this to help get me started. I was wondering if anyone can guide me through this step by step so that I no how to apply this to my situation: <? require 'lib-hollydb.inc'; //if new enumeration values specified, update database table column definition foreach ($_GET as $key => $value){ if(preg_match("/^new_/","$key") && ($value!="")){ $col=preg_replace("/^new_/","","$key"); $nv =$value; $arr_enum = getColumnEnumValues("comcode","$col"); if(in_array($nv,$arr_enum)){ errorMsg("$nv already exists in the drop down list..."); } $str_enum = implode("','", $arr_enum); $q="ALTER TABLE experts CHANGE $col $col enum('$str_enum','$nv')"; run_query($q); $_GET[$col]=$nv; } } $k = array(); $v = array(); foreach ($_GET as $key => $value){ if(!preg_match("/^new_/","$key")){ array_push($k,$key); array_push($v,$value); } } $x = implode(",",$k); $y = implode("','",$v); $q = "insert into experts ($x) values('$y')"; connect_to_db("$dbname"); run_query($q); ?> <? cePageHead(); ceLeftMenu(); ?> </td> <td valign="top"> <img src="images/red_vertical_bar.gif" width=1 height=120 border=0 alt=""> </td> <td valign="top"> </td> <b></b> <td> <b>PRO input:</b> add | <a href="pred_edit.php">edit</a> | <a href="pred_delete.php">delete</a> <br> <BR> Input a record<br><br> Thank you.<br> Your input has been uploaded into the database.<br> To edit this record, click <a href="pred_edit2.php?comcode=<?echo mysql_insert_comcode()?>" > here</a> </td> I would appeciate any help I can get. Thanks! Holly Quote Link to comment Share on other sites More sharing options...
gizmola Posted January 4, 2010 Share Posted January 4, 2010 Holly, 2 things to help you here. First, put bbcode around your code snippets. You can use php or code, but php is usually preferred. (Note that I modified your post for you and inserted these since this is your first post.) [code=php:0] //your php code [/code] The second tip is that you have to supply people with specifics. What *specifically* doesn't work at present? Quote Link to comment Share on other sites More sharing options...
gizmola Posted January 4, 2010 Share Posted January 4, 2010 Just glancing at that code, I see a lot of very strange things, and code that is altering the structure of a table for some inexplicable reason. I don't see how it in any way relates to adding entries, although we don't know among other things: -what the application is -what the database structure looks like Quote Link to comment Share on other sites More sharing options...
crabfinger Posted January 4, 2010 Share Posted January 4, 2010 This is something along the lines of what you need to let users add, delete, and modify entries in a database, of course its not anywhere near a full script, but you didn't give us very much information <?php print "\r\n"; $act_table = 'some_table'; $_GET['act'] = 'die'; if(isset($_GET['act'])) { switch($_GET['act']) { case 'add': $act_sql = 'INSERT INTO ' . $act_table . ' (some_field,some_field,some_field) VALUES ("' . $some_text . '","' . $some_text . '","' . $some_text . '")'; if(@mysql_query($act_sql)) { print 'Content added'; } else { die(mysql_error()); } break; case 'del': $act_sql = 'DELETE FROM ' . $act_table . ' WHERE some_field=' . $some_value . ''; if(@mysql_query($act_sql)) { print 'Content deleted'; } else { die(mysql_error()); } break; case 'mod': print 'Modify content'; // i'm too lazy to show you how to do this, figure it out. break; default: print 'Invalid action supplied'; break; } } print "\r\n\r\n"; ?> 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.