Dears
I am new to OOP Php. for now i am entangled at very initial level i.e. data insertion into db. I simply passed the insert query to a variable in simple php file, which i further get in class function executeQuery(). Although, on echoing $query variable shows right output yet, i cannot find out why data is not going to database. The class code is as under: -
<?php
-
class DBCon
-
{
-
var $con;
-
function getCon()
-
{
-
$hostname = 'localhost';
-
$dbuser = 'root';
-
$dbpassword = '';
-
-
$con=mysql_connect($hostname,$dbuser,$dbpassword);
-
if(!$con)
-
{
-
die('cannot connect db'.mysql_error());
-
}
-
mysql_select_db("studyco",$con);
-
return $con;
-
}
-
-
//Queries
-
function executeQuery($query)
-
{
-
if($query!= null)
-
{
-
mysql_query($query);
-
echo 'record added'.$query;
-
}
-
else
-
{
-
echo 'not added';
-
}
-
}
-
function destruct()
-
{
-
mysql_close();
-
}
-
}
-
?>
-
i would be extremely obliged for anyone's help in this regard.
Thanks
Qaiser
7 1509
i cannot see your code anywhere this code is for the class how are you calling the function and declaring object for the class no one is going to write the code for you we can suggest fixing.
regards,
Omer Aslam
Dear Umer Butt
Thanks alot for your quick response. I actually have this code in Php file which is as follows: sorry for inconvenience
Moreover, html code is is also placed at the end of this thread i.e. after php code -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-
<?php require_once('classes/db_con.class.php'); ?>
-
<?php require_once('classes/parentinfo.class.php'); ?>
-
</head>
-
-
<body>
-
<?php
-
$stdbcon = new DBCon();
-
if(!$stdbcon->getCon())
-
{
-
echo 'Connection not established with the DB';
-
} else
-
{
-
-
$parentdetail=new ParentInfo();
-
-
if(isset($_POST['btnSubmit']))
-
{
-
$parenttype = $_POST['comboParentType'];
-
$firstName = $_POST['txtFName'];
-
$lastName = $_POST['txtLName'];
-
$FHName = $_POST['txtFHName'];
-
$gender = $_POST['comboGender'];
-
$profession = $_POST['txtProfession'];
-
$contactoff = $_POST['txtContactOff'];
-
$contacthome = $_POST['txtContactHome'];
-
$mobile = $_POST['txtContactMobile'];
-
$email = $_POST['txtEmail'];
-
$address = $_POST['txtAddress'];
-
$snap = $_POST['image'];
-
-
//$parentdetail->addStudentInfo();
-
-
$query="INSERT INTO parent (firstname,lastname,gender,father_husbandname,profession,contactoffice,contacthome,mobile,email,address,snap,alt_parentid)
-
VALUES ('".$firstName."', '".$lastName."', '".$gender."', '".$FHName."', '".$profession."', '".$contactoff."', '".$contacthome."', '".$mobile."', '".$address."', '".$snap."', '".$parenttype."')";
-
$stdbcon->executeQuery($query);
-
-
}
-
-
}
-
?>
-
</body>
-
</html>
-
html code
i could not see if you are verifying your mysql query
please replace your class with the following code -
<?php
-
class DBCon
-
{
-
var $con;
-
function getCon()
-
{
-
$hostname = 'localhost';
-
$dbuser = 'root';
-
$dbpassword = '';
-
-
$con=mysql_connect($hostname,$dbuser,$dbpassword);
-
if(!$con)
-
{
-
die('cannot connect db'.mysql_error());
-
}
-
mysql_select_db("studyco",$con);
-
return $con;
-
}
-
-
//Queries
-
function executeQuery($query)
-
{
-
if($query!= null)
-
{
-
mysql_query($query) or die(mysql_error());
-
echo 'record added'.$query;
-
}
-
else
-
{
-
echo 'not added';
-
}
-
}
-
function destruct()
-
{
-
mysql_close();
-
}
-
}
-
?>
-
-
-
Try this.. replace this: -
$query="INSERT INTO parent (firstname,lastname,gender,father_husbandname,profession,contactoffice,contacthome,mobile,email,address,snap,alt_parentid)
-
VALUES ('".$firstName."', '".$lastName."', '".$gender."', '".$FHName."', '".$profession."', '".$contactoff."', '".$contacthome."', '".$mobile."', '".$address."', '".$snap."', '".$parenttype."')";
-
$stdbcon->executeQuery($query);
-
with this: -
-
$query="INSERT INTO `parent` (firstname,lastname,gender,father_husbandname,profession,contactoffice,contacthome,mobile,email,address,snap,alt_parentid)
-
VALUES ('$firstName', '$lastName', '$gender', '$FHName', '$profession', '$contactoff', '$contacthome', '$mobile', '$address', '$snap', '$parenttype')";
-
$stdbcon->executeQuery($query);
Also, did you make sure to add a primary, auto-incrementing key to your table?
Dear Umer and AutumnsDecay
Thaaaanks alot for your help. Replies from both of you indeed helped me identify and resolve the issue. Actually i was missing a variable in the query. Therefore, there was discrepancy in the table fields and values of query. Thus the record was not going to the db. Now this issue is up.
Thanks alot once again
Ah yes, I do see now that you missed the $email variable in the query.
Glad you got it resolved, and glad we could help.
Sure
glad to help out
regards,
Omer Aslam
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sugapablo |
last post by:
Let's say I create a new record in a table like this:
mysql_query("INSERT INTO table (col1) VALUES ('example')",$conn);
....that had an auto-incrementing, unique identifying column named "ID"...
|
by: David |
last post by:
Hi,
I have the following code which adds a record to a table:
vUser = request.form("user") '(UserID = PK in table)
vPass = request.form("pass")
vEmail = request.form("email")
uSQL =...
|
by: YFS DBA |
last post by:
How do I use VBA to insert a *new* record into a subform?
I have a master form with client information, and a sub form with billing
information. I want to click on a button ("Add Data") and have...
|
by: Mark |
last post by:
I'm using ASP.Net to accress a database, what I need to do is get the fields
out of the very last record in the db.
How do I do this?
Actually I'm after the primary key, titled 'AdID' it'll tell...
|
by: Vincy |
last post by:
Once there is any addition of record to the table in the database( insertion
of the record is not from the datagrid), the datagrid in the windows form
should automatically refresh. How do i do...
|
by: Jan |
last post by:
Hello,
Just after the new record is inserted in the database using a Detailsview
control, i would like to display a short message "the record is inserted".
In the aspx file, i defined a...
|
by: dav3 |
last post by:
Alright folks I am in need of a lil guidance/assistance here. I have a program which reads in a txt file. This txt file contains lines of the form
January 3, 2007, 85.8
Now each line of the txt...
|
by: TimSki |
last post by:
Hi,
In my asp page I am inserting a record in to the sql server 2005 db as follows...
OpenDataConnection()
oConn.BeginTrans
set cm = CreateObject("ADODB.Command")
set cm.ActiveConnection =...
|
by: Jim in Arizona |
last post by:
I forgot what the SQL command was to return the key of the last inserted
record. Does anyone happen to know what it is?
Thanks,
Jim
--
|
by: Van Fitz |
last post by:
I am importing an excel worksheet into an existing access 2000 table using TransferSpreadsheet. Im using a timestamp field as well in this table. This is going well, however, once the data is...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |