Page 1 of 1

Record entering problem

Posted: Mon Apr 05, 2010 5:12 am
by dhammikai
Hi,
I try to insert a records by using following coding (which is taken by some tutorials), I create the database 'samples' and 'customers' tables also. Now the problem is when I enter a record to database it is entered to database successfully but according to PHP code is it not display after the enter the record.
Please give me some help to find out why it is not display entered record (but only the fields are display not the record)
here is the code

Code: Select all

<?php  echo $_SERVER['SCRIPT_NAME']."<BR>"; ?>
<?php
include_once("include/db_connection.php");
?>
<?php
	// Retreiving Form Elements from Form
	$thisCustomer_id = addslashes($_REQUEST['thisCustomer_idField']);
	$thisFname = addslashes($_REQUEST['thisFnameField']);
	$thisMname = addslashes($_REQUEST['thisMnameField']);
	$thisLname = addslashes($_REQUEST['thisLnameField']);
	$thisCompany = addslashes($_REQUEST['thisCompanyField']);
	$thisTitle = addslashes($_REQUEST['thisTitleField']);
	$thisAddress1 = addslashes($_REQUEST['thisAddress1Field']);
	$thisAddress2 = addslashes($_REQUEST['thisAddress2Field']);
	$thisAddress3 = addslashes($_REQUEST['thisAddress3Field']);
	$thisCity = addslashes($_REQUEST['thisCityField']);
	$thisState_province = addslashes($_REQUEST['thisState_provinceField']);
	$thisCountry = addslashes($_REQUEST['thisCountryField']);
	$thisPostal_code = addslashes($_REQUEST['thisPostal_codeField']);
	$thisPhone = addslashes($_REQUEST['thisPhoneField']);
	$thisFax = addslashes($_REQUEST['thisFaxField']);

$sqlQuery = "INSERT INTO customers (customer_id , fname , mname , lname , company , title , address1 , address2 , address3 , city , state_province , country , postal_code , phone , fax )
	VALUES ('$thisCustomer_id' , '$thisFname' , '$thisMname' , '$thisLname' , '$thisCompany' , '$thisTitle' , '$thisAddress1' , '$thisAddress2' , '$thisAddress3' , '$thisCity' , '$thisState_province' , '$thisCountry' , '$thisPostal_code' , '$thisPhone' , '$thisFax' )";
$result = MYSQL_QUERY($sqlQuery);

?>
A new record has been inserted in the database. Here is the information that has been inserted :- <br><br>
[i][b]// THIS PART OF THE PROGRAME IS NOT  WORKING, ONLY THE FIELD HEADING  IS DISPLAY BUT RECORD IS NOT DISPLAY.[/b][/i]
<table>
<tr height="30">
	<td align="right"><b>Customer_id : </b></td>
	<td><? echo $thisCustomer_id; ?></td>
</tr>
<tr height="30">
	<td align="right"><b>Fname : </b></td>
	<td><? echo $thisFname; ?></td>
</tr>
<tr height="30">
	<td align="right"><b>Mname : </b></td>
	<td><? echo $thisMname; ?></td>
</tr>
<tr height="30">
	<td align="right"><b>Lname : </b></td>
	<td><? echo $thisLname; ?></td>
</tr>
<tr height="30">
	<td align="right"><b>Company : </b></td>
	<td><? echo $thisCompany; ?></td>
</tr>
<tr height="30">
	<td align="right"><b>Title : </b></td>
	<td><? echo $thisTitle; ?></td>
</tr>
<tr height="30">
	<td align="right"><b>Address1 : </b></td>
	<td><? echo $thisAddress1; ?></td>
</tr>
<tr height="30">
	<td align="right"><b>Address2 : </b></td>
	<td><? echo $thisAddress2; ?></td>
</tr>
<tr height="30">
	<td align="right"><b>Address3 : </b></td>
	<td><? echo $thisAddress3; ?></td>
</tr>
<tr height="30">
	<td align="right"><b>City : </b></td>
	<td><? echo $thisCity; ?></td>
</tr>
<tr height="30">
	<td align="right"><b>State_province : </b></td>
	<td><? echo $thisState_province; ?></td>
</tr>
<tr height="30">
	<td align="right"><b>Country : </b></td>
	<td><? echo $thisCountry; ?></td>
</tr>
<tr height="30">
	<td align="right"><b>Postal_code : </b></td>
	<td><? echo $thisPostal_code; ?></td>
</tr>
<tr height="30">
	<td align="right"><b>Phone : </b></td>
	<td><? echo $thisPhone; ?></td>
</tr>
<tr height="30">
	<td align="right"><b>Fax : </b></td>
	<td><? echo $thisFax; ?></td>
</tr>
</table>
<p>&nbsp;</p>
<ul>
  <li>
    <div align="left"><a href="enter_new.php">Enter New customers</a></div>
  </li>
  <li>
    <div align="left"><a href="list.php">List All customers</a></div>
  </li>
  <li>
    <div align="left"><a href="search_form.php">Power Search customers</a></div>
  </li>
</ul>
<p></p>

Re: Record entering problem

Posted: Mon Apr 05, 2010 8:59 am
by mikosiko
try using long tags instead of the short ones... like here

you are using this

Code: Select all

        <td><? echo $thisCustomer_id; ?></td>
try in this way

Code: Select all

        <td><?php echo $thisCustomer_id; ?></td>

Re: Record entering problem

Posted: Mon Apr 05, 2010 9:12 am
by lunarnet76
you should also use error_reporting(E_ALL); at the begining of your script to show errors
because

Code: Select all

MYSQL_QUERY
is supposed to be in lower letters so the script must stopped here!

Re: Record entering problem

Posted: Tue Apr 06, 2010 12:45 am
by dhammikai
Hi lunarnet76 and mikosiko,
Thank you very much for your help and comments,

mikosiko, I changed the code as you mentioned (long tags) it works now! But in customer_id field (it is auto increment field) is still display in blank. Please give me some help to find out it.

lunarnet76, I also insert the statement as you mentioned. I this this is also really help me my php-code, thank you

Re: Record entering problem

Posted: Tue Apr 06, 2010 2:48 am
by eskio
Hi,
if customer_id is auto increment filed, you can retrieve it using mysql_insert_id() function.

Code: Select all

$customer_id = mysql_insert_id();

Re: Record entering problem

Posted: Tue Apr 06, 2010 3:44 am
by dhammikai
Hi,
Thanks eskio for Ur reply and help, Please check my following code, this insert of Ur mentioned statement is correct? otherwise please explan me how I insert it to my this code.

Code: Select all

<?php  echo $_SERVER['SCRIPT_NAME']."<BR>"; ?>
<?php
include_once("include/db_connection.php");
?>
<?php
        // Retreiving Form Elements from Form
        $thisCustomer_id = addslashes($_REQUEST['thisCustomer_idField']);
        $thisFname = addslashes($_REQUEST['thisFnameField']);
        $thisMname = addslashes($_REQUEST['thisMnameField']);
        $thisLname = addslashes($_REQUEST['thisLnameField']);
        $thisCompany = addslashes($_REQUEST['thisCompanyField']);
        $thisTitle = addslashes($_REQUEST['thisTitleField']);
        $thisAddress1 = addslashes($_REQUEST['thisAddress1Field']);
        $thisAddress2 = addslashes($_REQUEST['thisAddress2Field']);
        $thisAddress3 = addslashes($_REQUEST['thisAddress3Field']);
        $thisCity = addslashes($_REQUEST['thisCityField']);
        $thisState_province = addslashes($_REQUEST['thisState_provinceField']);
        $thisCountry = addslashes($_REQUEST['thisCountryField']);
        $thisPostal_code = addslashes($_REQUEST['thisPostal_codeField']);
        $thisPhone = addslashes($_REQUEST['thisPhoneField']);
        $thisFax = addslashes($_REQUEST['thisFaxField']);

$sqlQuery = "INSERT INTO customers (customer_id , fname , mname , lname , company , title , address1 , address2 , address3 , city , state_province , country , postal_code , phone , fax )
        VALUES ('$thisCustomer_id' , '$thisFname' , '$thisMname' , '$thisLname' , '$thisCompany' , '$thisTitle' , '$thisAddress1' , '$thisAddress2' , '$thisAddress3' , '$thisCity' , '$thisState_province' , '$thisCountry' , '$thisPostal_code' , '$thisPhone' , '$thisFax' )";
$result = MYSQL_QUERY($sqlQuery);

?>
A new record has been inserted in the database. Here is the information that has been inserted :- <br><br>
<span style="font-style: italic"><span style="font-weight: bold">// THIS PART OF THE PROGRAME IS NOT  WORKING, ONLY THE FIELD HEADING  IS DISPLAY BUT RECORD IS NOT DISPLAY.</span></span>
<table>
<tr height="30">
        <td align="right"><b>Customer_id : </b></td>
        <td><? echo [i][b][color=#4000FF]$customer_id  = mysql_insert_id();[/color][/b][/i] ?></td>
</tr>
<tr height="30">
        <td align="right"><b>Fname : </b></td>
        <td><? echo $thisFname; ?></td>
</tr>
<tr height="30">
        <td align="right"><b>Mname : </b></td>
        <td><? echo $thisMname; ?></td>
</tr>
<tr height="30">
        <td align="right"><b>Lname : </b></td>
        <td><? echo $thisLname; ?></td>
</tr>
<tr height="30">
        <td align="right"><b>Company : </b></td>
        <td><? echo $thisCompany; ?></td>
</tr>
<tr height="30">
        <td align="right"><b>Title : </b></td>
        <td><? echo $thisTitle; ?></td>
</tr>
<tr height="30">
        <td align="right"><b>Address1 : </b></td>
        <td><? echo $thisAddress1; ?></td>
</tr>
<tr height="30">
        <td align="right"><b>Address2 : </b></td>
        <td><? echo $thisAddress2; ?></td>
</tr>
<tr height="30">
        <td align="right"><b>Address3 : </b></td>
        <td><? echo $thisAddress3; ?></td>
</tr>
<tr height="30">
        <td align="right"><b>City : </b></td>
        <td><? echo $thisCity; ?></td>
</tr>
<tr height="30">
        <td align="right"><b>State_province : </b></td>
        <td><? echo $thisState_province; ?></td>
</tr>
<tr height="30">
        <td align="right"><b>Country : </b></td>
        <td><? echo $thisCountry; ?></td>
</tr>
<tr height="30">
        <td align="right"><b>Postal_code : </b></td>
        <td><? echo $thisPostal_code; ?></td>
</tr>
<tr height="30">
        <td align="right"><b>Phone : </b></td>
        <td><? echo $thisPhone; ?></td>
</tr>
<tr height="30">
        <td align="right"><b>Fax : </b></td>
        <td><? echo $thisFax; ?></td>
</tr>
</table>
<p>&nbsp;</p>
<ul>
  <li>
    <div align="left"><a href="enter_new.php">Enter New customers</a></div>
  </li>
  <li>
    <div align="left"><a href="list.php">List All customers</a></div>
  </li>
  <li>
    <div align="left"><a href="search_form.php">Power Search customers</a></div>
  </li>
</ul>
<p></p>

Re: Record entering problem

Posted: Tue Apr 06, 2010 4:00 am
by eskio
Hi,
you have tu use mysql_insert_id() after the insertion:

Code: Select all

$result = mysql_query($sqlQuery);
$customer_id = mysql_insert_id();
for my point of view it is better if you use like this:

Code: Select all

if (@mysql_query($sqlQuery)){
  print 'Infromation successfully inserted';  // something like that
  $customer_id = mysql_insert_id();
} else {
  print 'Error: '.mysql_errno().' - '.mysql_error();
} 

Re: Record entering problem

Posted: Tue Apr 06, 2010 4:02 am
by eskio
Hi,
you have to use mysql_insert_id() after the insertion:

Code: Select all

$result = mysql_query($sqlQuery);
$customer_id = mysql_insert_id();
for my point of view it is better if you use like this:

Code: Select all

if (@mysql_query($sqlQuery)){
  print 'Information successfully inserted';  // something like that
  $customer_id = mysql_insert_id();
} else {
  print 'Error: '.mysql_errno().' - '.mysql_error();
} 

Re: Record entering problem

Posted: Tue Apr 06, 2010 4:26 am
by dhammikai
Hi,
Thank you very much for Ur help and all comments. Now my retrieving of entered data form is successfully working. Thank you very much friends again.