Topic: PHP OOP Inserting records into db
hello, i'm new to Object Oriented Programming and I am trying to create a class function that will insert data into my database.
i beleive i have the code correct but i'm not sure what i am doing wrong. can some one help me please?
here is my code.....
class cms{
var $db;
var $host;
var $username;
var $password;
var $school;
var $country;
var $city;
var $state;
var $zip;
function connect(){
$con = mysql_connect($this->host,$this->username,$this->password) or die("Could not connect to database");
$sel =mysql_select_db($this->db) or die("Could not select database");
}
function newSchool(){
$sql = mysql_query("INSERT INTO schools (school, country, city, state, zip) VALUES (" . $this->school . ',' . $this->country . ',' . $this->city . ',' . $this->state . ',' . $this->zip . ")");
}
}
and here is my other code........
<?php
include("config.php");
$cms = new cms();
$cms->connect();
if($_GET['new_school'] == "yes"){
$cms->newSchool();
}
?>
<form action="new_school.php?new_school=yes" method="post">
<center><table align="center" border="1">
<tr>
<td>School Name: </td><td><input type="text" name="school_name" /></td>
</tr>
<tr>
<td>Country: </td><td><?=$cms->country(); ?></td>
</tr>
<tr>
<td>City: </td><td><input type="text" name="city" /></td>
</tr>
<tr>
<td>State: </td><td><input type="text" name="state" /></td>
</tr>
<tr>
<td>Zip: </td><td><input type="text" name="zip" /></td>
</tr>
<tr>
<td></td><td><input type="submit" name="submit" value="Add School!" /></td>
</tr>
</table>
and the config file just defines my $_POST vars for the form.

