Page 1 of 1

[SOLVED] need help inserting data into mysql

Posted: Sat Dec 20, 2003 12:04 am
by concatenate_man
SOLVEDHi folks, I am having trouble with some of my php code when it comes to inserting data in mysql. First there is a page called insert_buyer.html that is a form for gathering required data

Code: Select all

<html> 
<head> 
   <title>MarCat Buyer Insertion</title> 
</head> 
<body bgcolor="#000000" text="#FFFFFF" link="#0000FF" 
     vlink="#000080" alink="#FF0000"> 
    <p align="center"><img src="images/logo.gif" width="850" height="89"></p> 
<p> 
<h1>MarCat Buyer Insertion Page</h1> 
<p> 
<hr> 
<p> 
<form action="insert_buyer.php" method="post"> 
  <table border="0"> 
    <tr> 
      <td>NAME</td> 
      <td><input type="text" name="buyer_name" maxlength="20" size="20"><br/></td> 
    </tr> 
    <tr> 
      <td>ADDRESS</td> 
      <td><input type="text" name="buyer_address" maxlength="50" size="50"><br/></td> 
    </tr> 
    <tr> 
      <td>PHONE</td> 
      <td><input type="text" name="buyer_phone" maxlength="20" size="20"><br/></td> 
    </tr> 
    <tr> 
      <td>COMPANY</td> 
      <td><input type="text" name="buyer_company" maxlength="50" size="50"><br/></td> 
    </tr> 
    <tr> 
      <td>ABN</td> 
      <td><input type="text" name="buyer_abn" maxlength="20" size="20"><br/></td> 
    </tr> 
    <tr> 
      <td colspan="2"><input type="submit" value="Insert Buyer"</td> 
    </tr> 
  </table> 
</form> 
</body> 
</html>
this calls insert_buyer.php

Code: Select all

<html> 
<head> 
   <title>MarCat Buyer Insertion</title> 
</head> 
<body bgcolor="#000000" text="#FFFFFF" link="#0000FF" 
     vlink="#000080" alink="#FF0000"> 
    <p align="center"><img src="images/logo.gif" width="850" height="89"></p> 
    <p align="center"><h1>Buyer Insertion Results</h1> 
<p> 
<hr> 
<?php 

$buyer_name=$HHTP_POST_VARS&#1111;'buyer_name']; 
$buyer_address=$HHTP_POST_VARS&#1111;'buyer_address']; 
$buyer_phone=$HHTP_POST_VARS&#1111;'buyer_phone']; 
$buyer_company=$HHTP_POST_VARS&#1111;'buyer_company']; 
$buyer_abn=$HHTP_POST_VARS&#1111;'buyer_abn']; 

if (!buyer_name || !buyer_address || !buyer_phone || !buyer_company || !buyer_abn) 
&#123; 
   echo 'You have not entered all the required details.<br/>' 
        .'Please go back and try again...'; 
   exit; 
&#125; 

$buyer_name = addslashes($buyer_name); 
$buyer_address = addslashes($buyer_address); 
$buyer_phone = addslashes($buyer_phone); 
$buyer_company = addslashes($buyer_company); 
$buyer_abn = addslashes($buyer_abn); 


$connection = mysql_connect('localhost'); 

if (!$connection) 
&#123; 
   echo 'Error: Could not connect to database. Please try again later.'; 
   exit; 
&#125; 

mysql_select_db('marcat'); 

$query = "insert into BUYERS(Name,Address,Phone,Company,ABN) values 
     ('".$buyer_name."','".$buyer_address."','".$buyer_phone."','".$buyer_company."','".$buyer_abn."')"; 

$result = mysql_query($query); 

if ($result) 
   echo mysql_affected_rows().' buyer inserted into database.'; 

?> 

</body> 
</html>
now when i run this it creates a new row in the BUYERS but when i check the table in myphpadminI only get the default values eg nothing for varchars and 0 for int. can anyone tell me what i am doing wrong and how i can fix this situation.

cheers
Joe

Posted: Sun Dec 21, 2003 8:23 pm
by geethanandh
hi
its not $HHTP_POST_VARS it only $HTTP_POST_VARS