Could you help the newbie ?!
In general, there is a database. In Denver. (although the database does not matter) There are CARS, FOOTBALL and COUNTRIES bases.
Inside the bases all the same! For example: in CARS the MAIN table (Merc, BMW, Audi, etc.)
And then comes the table MODELS, which are tied to the MARKES (for example, MERS - Gelandewagen, SLK and CLK).
In FOOTBALL - the main CLUBS, and the second - PLAYERS in them. In COUNTRIES - the main COUNTRY, and SECOND - CITY in them.
The essence of the question: the fact is that I have a lot of different requests from "process.php" in "functions.php" for functions such as INSERT, SELECT, UPDATE and DELETE:
function insert_add_marka($connect){ $marka=@$_POST['marka_name']; $sql="SELECT * FROM marki WHERE marka_name='$marka'"; $res=mysqli_query($connect,$sql) or die(mysqli_error($connect)); $get=mysqli_fetch_assoc($res); if($get['id']==0){ $sql="INSERT INTO marki (marka_name)value('$marka')"; $res = mysqli_query($connect,$sql); echo "<script>window.location='index.php'</script>"; } } function update_edit_marka($connect){ $marka=@$_POST['marka_name']; $marka_id=@$_POST['marka_id']; $sql="UPDATE marki SET marka_name='$marka' WHERE id=$marka_id"; $res = mysqli_query($connect,$sql); echo "<script>window.location='index.php'</script>"; } function insert_add_model($connect){ $file_name=null; $file_error=@$_FILES['photo_file']['error']; if($file_error==0){ $file_name=@$_FILES['photo_file']['name']; $file_tmp_name=@$_FILES['photo_file']['tmp_name']; move_uploaded_file($_FILES['photo_file']['tmp_name'], "../uploads/". $_FILES['photo_file']['name']); } $mod_name=@$_POST['model_name']; $opisanie=@$_POST['opisanie']; $marka_id=@$_POST['marka_id']; $sql="SELECT * FROM car_models WHERE model_name='$mod_name'"; $res=mysqli_query($connect,$sql) or die(mysqli_error($connect)); $get=mysqli_fetch_assoc($res); if($get['id']==0){ $sql = "INSERT INTO car_models (model_name, photo, opisanie, marka_id)values('$mod_name','$file_name','$opisanie', $marka_id)"; $res = mysqli_query($connect,$sql); echo "<script>window.location='model.php?marka_id=$marka_id'</script>"; } } Now the teacher wants me to have new universal functions Insert, select, update and delete for all occasions!
But how to do it, for example, if for example in $sql="INSERT INTO marki (marka_name)value('$marka')" are 3 parameters, and in $sql = "INSERT INTO car_models (model_name, photo, opisanie, marka_id)values('$mod_name','$file_name','$opisanie', $marka_id)" - already 9 parameters!
In $sql="UPDATE marki SET marka_name='$marka' WHERE id=$marka_id"; - 4 parameters come, and in $sql = "UPDATE car_models SET model_name='$mod_name', photo='$file_name', marka_id='$marka_id', opisanie='$opisanie' WHERE id=$model_id"; - 9-10 parameters!
Already 4 day I write the code - it is impossible! And I can not find such on the Internet!
Has anyone already come across - and wrote such universal functions INSERT, SELECT, UPDATE и DELETE ?!
ATTENTION: I do not use classes yet! Please write answers without them!
Thanks in advance for the cuff in the right direction! :-)
explode(',', $arr)or to taste - toxxxa