SnakZ Posted March 5, 2011 Share Posted March 5, 2011 ok im sure we all know how phpmyadmin works. You click insert it grabs the column names/fields using mysql_fetch_field with the help of a loop im sure then when you click submit it some how put them into the database can any one tell me how does it do this ? what code is needed as im trying to do the same thing try to look at there code but its crazy in there im not sure how it grabs the data and put it into the database ty you for your time sorry if this is hard to understand its hard to put it into words Quote Link to comment Share on other sites More sharing options...
SnakZ Posted March 5, 2011 Author Share Posted March 5, 2011 got it to some what work with this code but now not to sure what type of loop i need to get the column name to change along with the array i know i need some type of loop using mysql_fetch_field $tbox=$_POST['name']; foreach ($tbox as $value) { echo" $key $value <br />"; sql_query("INSERT INTO table_Z ($column)VALUES ($value)") or die(mysql_error()); } Quote Link to comment Share on other sites More sharing options...
SnakZ Posted March 5, 2011 Author Share Posted March 5, 2011 dont mind the other post (pass my edit time) it would not work as i would need an sql update or something like that im getting there i think lol Quote Link to comment Share on other sites More sharing options...
SnakZ Posted March 5, 2011 Author Share Posted March 5, 2011 [sOLVED] ok i got it to work 100% just posting for that what if other people want to know how to take an array from input and break it apart and put it into the database one by one the "echo" are for me so i can see there names before they go into the SQL $tbox=$_POST['name']; $result = $db->sql_query("SELECT * FROM Table_Z ") or die(mysql_error()) ; foreach ($tbox as $key => $value) { echo" $key $value <br />"; $property = mysql_fetch_field($result); if($key==0){ if (ctype_digit($value)) { sql_query("INSERT INTO table_Z (" . $property->name . ")VALUES ('$value')") or die(mysql_error());}else{ sql_query("INSERT INTO table_Z (" . $property->name . ")VALUES ($value)") or die(mysql_error());} $test=$value; echo"$test"; }else{ if (ctype_digit($value)) { $db->sql_query("UPDATE table_Z SET " . $property->name . "=$value WHERE names=$test") or die(mysql_error());}else{ $db->sql_query("UPDATE table_Z SET " . $property->name . "='$value' WHERE names=$test") or die(mysql_error());} } } Quote Link to comment Share on other sites More sharing options...
aabruzzese Posted March 11, 2011 Share Posted March 11, 2011 Isn't it amazing what we can do when we really want to? 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.