Page 1 of 1

Newbie Need Help in Function For PHP 5

Posted: Fri May 13, 2005 4:07 am
by MBDesktop
Hai there.. Before I continue my problems, I would like to apologize for my poor English. I am beginners in php programming.

What I want to do are :
- I want to create a error handler function or objects in php 5. The development concept are all the items inside the dialog box that display Feedback Title, Feedback Messages, Icon and Action Button are variables that will save inside the tables.
- I can call that function by enter the Feedback Title, Feedback Messages, Icon and Action Button parameters.

Please help me, I need guide. Thanks

Posted: Wed May 25, 2005 5:30 pm
by thomas777neo
Ok, here is a simple example to work with...

I haven't put any error checking.

sql:

Code: Select all

drop table if exists feedback;

create table feedback
(
id int(10) auto_increment primary key,
title varchar(150),
message text,
icon varchar(150),
action varchar(150)
);
feedback.php

Code: Select all

<p>Feedback</p>
<form name="form1" method="post" action="insertFeedback.php">
  <table>
    <tr>
      <td>Title</td>
      <td><input name="title" type="text" id="title"></td>
    </tr>
    <tr>
      <td>Message</td>
      <td><textarea name="message" cols="30" rows="5" id="message"></textarea></td>
    </tr>
    <tr>
      <td>Icon</td>
      <td><input name="icon" type="text" id="icon"></td>
    </tr>
    <tr>
      <td>Action</td>
      <td><input name="action" type="text" id="action"></td>
    </tr>
    <tr>
      <td colspan="2"><div align="center">
        <input type="submit" name="Submit" value="Submit">
      </div></td>
    </tr>
  </table>
</form>
insertFeedback.php

Code: Select all

require_once("class.feedback.php");

$feedback = new feedback; // created new object

$feedback-> insert_feedback($title,$message,$icon,$action);
class.feedback.php

Code: Select all

class feedback
{
	function insert_feedback($title,$message,$icon,$action)
	{
		$connection = mysql_connect("host","username","password");
		mysql_select_db("misc");
		
		$sql = "INSERT INTO feedback(title,message,icon,action) VALUES ('$title','$message','$icon','$action')";
		mysql_query($sql);
	}
}
1. run the sql
2. create the 3 pages
3. copy into folder accessible by webserver
4. open feedback.php in browser.
5. A simple example of an object created in php.
6. First learn the basics, then move on to exception handling etc