473,769 Members | 5,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding data to a mysql database works one time only

3 New Member
Hi I am busy now for many hours without luck

I have a database and when I use PHP to add date to it, it works only one time
when i want to add the next data, It doesn't work. but i don't get any errors???

see my code:
[PHP]
$query = "INSERT INTO products VALUES ('$typedata','$ pro_code_ourdat a','$pronum','$ proname','$prod etails','$facnu m','$picturedat a','$price','$p robox','$proqua ntity')";
mysql_query($qu ery);
[/PHP]

What is wrong here or what is missing?
Please help

You can check it at
www.bs-exportchina.com/products


Here is the full code:
Maybe some code is a bit unusual but that is because I'm new with PHP
[PHP]<html>
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" >
</head>

<body bgcolor="#FFFFF F" text="#000000">
<?
$pictureloadok = 0;
$type = $_REQUEST['type'];
$pronum = $_REQUEST['pronum'];
$proname = $_REQUEST['proname'];
$prodetails = $_REQUEST['prodetails'];
$probox = $_REQUEST['probox'];
$proquantity = $_REQUEST['proquantity'];
$facnum = $_REQUEST['facnum'];
$price = $_REQUEST['price'];
If (!empty($type)) {
$typeok = 1;
}else{
$typeok = 0;
}
If (!empty($pronum )) {
$pronumok = 1;
}else{
$pronumok = 0;
}
If (!empty($pronam e)) {
$pronameok = 1;
}else{
$pronameok = 0;
}
If (!empty($prodet ails)) {
$prodetailsok = 1;
}else{
$prodetailsok = 0;
}
If (!empty($probox )) {
$proboxok = 1;
}else{
$proboxok = 0;
}
If (!empty($proqua ntity)) {
$proquantityok = 1;
}else{
$proquantityok = 0;
}
If (!empty($facnum )) {
$facnumok = 1;
}else{
$facnumok = 0;
}
If (!empty($price) ) {
$priceok = 1;
}else{
$priceok = 0;
}
if ($typeok = 1) {
if ($pronumok = 1) {
if ($pronameok = 1) {
if ($prodetailsok = 1) {
if ($proboxok = 1) {
if ($proquantityok = 1) {
if ($facnumok = 1) {
if ($priceok = 1) {
If (!empty($_FILES['uploaded']['name'])){
$target = "databasepictur es/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploade d_file($_FILES['uploaded']['tmp_name'], $target)){
$pictureloadok = 1;
$picturedata = "/pictures/databasepicture s/".$_FILES['uploadedfile']['name'];
}else{
$pictureloadok = 0;
}
}else{
$pictureloadok = 2;
}
}
}
}
}
}
}
}
}
if ($pictureloadok == 1) {
$user="*******" ;
$password="**** ***";
$database="**** ****";
mysql_connect(l ocalhost,$user, $password);
@mysql_select_d b($database) or die( "Unable to select database");
$query="SELECT * FROM `products` ";
mysql_query($qu ery);
$result=mysql_q uery($query);
$num=mysql_numr ows($result) ;
$num--;
$pro_code_ourda ta=mysql_result ($result,$num," pro_code_our");
$pro_code_ourda ta++;
mysql_close();

mysql_connect(l ocalhost,$user, $password);
@mysql_select_d b($database) or die( "Unable to select database");
$query="SELECT * FROM pro_index ";
mysql_query($qu ery);
$result=mysql_q uery($query);
$num=mysql_numr ows($result);
$i=0;
while ($i < $num){
$typedataa=mysq l_result($resul t,$i,"pro_type_ code");
$typedatab=mysq l_result($resul t,$i,"pro_type" );
if ($typedatab == $type) {
$typedata = $typedataa;
}
$i++;
}

$picturedata = "products/".$target;
$query = "INSERT INTO products VALUES ('$typedata','$ pro_code_ourdat a','$pronum','$ proname','$prod etails','$facnu m','$picturedat a','$price','$p robox','$proqua ntity')";
mysql_query($qu ery);
mysql_close();
Print $typedata;
print " ";
print $pro_code_ourda ta;
print " ";
print $pronum;
print " ";
print $proname;
print " ";
print $prodetails;
print " ";
print $facnum;
print " ";
print "products/".$target;
print " ";
print $price;
print " ";
print $probox;
print " ";
print $proquantity;
print " ";
print "are added to the database";
}

$user="******";
$password="**** **";
$database="**** **";
$pro_type_scree n = isset($_REQUEST['pro_type_scree n']) ? trim($_REQUEST['pro_type_scree n']) : "";
mysql_connect(l ocalhost,$user, $password);
@mysql_select_d b($database) or die( "Unable to select database");
$query="SELECT * FROM `products` ";
mysql_query($qu ery);
$result=mysql_q uery($query);
$num=mysql_numr ows($result);
?>
<table width="*" border="1" cellspacing="0" cellpadding="0" >
<?

$i=0;
while ($i < $num) {
$pro_type=mysql _result($result ,$i,"pro_type") ;
$pro_code_our=m ysql_result($re sult,$i,"pro_co de_our");
$pro_code_fac=m ysql_result($re sult,$i,"pro_co de_fac");
$pro_name=mysql _result($result ,$i,"pro_name") ;
$pro_details=my sql_result($res ult,$i,"pro_det ails");
$pro_fac=mysql_ result($result, $i,"pro_fac");
$pro_pic=mysql_ result($result, $i,"pro_pic");
$pro_price=mysq l_result($resul t,$i,"pro_price ");
$pro_boxsize=my sql_result($res ult,$i,"pro_box size");
$pro_inbox=mysq l_result($resul t,$i,"pro_inbox ");
?>
<tr>
<?
echo"<td width='20' valign='top'>$p ro_type</td>";
echo"<td width='75' valign='top'>$p ro_code_our</td>";
echo"<td width='75' valign='top'>$p ro_code_fac</td>";
echo"<td width='100' valign='top'>$p ro_name</td>";
echo"<td width='400' valign='top'>$p ro_details</td>";
echo"<td width='20' valign='top'>$p ro_fac</td>";
echo"<td width='400' valign='top'>$p ro_pic</td>";
echo"<td width='150' valign='top'>$p ro_price</td>";
echo"<td width='100' valign='top'>$p ro_boxsize</td>";
echo"<td width='50' valign='top'>$p ro_inbox</td>";
?>
</tr>
<?
$i++;
}
?>
</table>
<?
mysql_close();
?>
<form name="form1" ENCTYPE="multip art/form-data" method="post" action="index.p hp">
<?
$user="******";
$password="**** **";
$database="**** **";
$pro_id=$_POST['pro_id'];
$pro_type=$_POS T['pro_type'];
mysql_connect(l ocalhost,$user, $password);
@mysql_select_d b($database) or die( "Unable to select database");
$query="SELECT * FROM pro_index";
mysql_query($qu ery);
$result=mysql_q uery($query);
$num=mysql_numr ows($result);
$i=0;
?>
Product type
<select name="type" size="1">
<?
while ($i < $num) {
$pro_id=mysql_r esult($result,$ i,"pro_type_cod e");
$pro_type=mysql _result($result ,$i,"Pro_type") ;
echo "<option>$pro_t ype</option>";
$i++;
}
mysql_close();
?>
</select>
<?
$pro_code_our++ ;
Echo "<br>Produc t number = BS$pro_code_our </p>";
?>
<br>
Product number from Factory
<input type="text" name="pronum">
<br>
Product name
<input type="text" name="proname">
<br>
Product details
<input type="text" name="prodetail s" size="50">
<br>
Box size
<input type="text" name="probox">
<br>
Quantity
<input type="text" name="proquanti ty">
<br>
Picture
<INPUT NAME="uploaded" TYPE="File">

<br>
Factory number
<input type="text" name="facnum">
<br>
Buy Price
<input type="text" name="price">
<br>
<input type="submit" name="Submit" value="Add record">
<br>
</form>
<p>&nbsp;</p>
</body>
</html>
[/PHP]
Mar 25 '07 #1
2 2268
ronverdonk
4,258 Recognized Expert Specialist
What do you mean by
I have a database and when I use PHP to add date to it, it works only one time when i want to add the next data, It doesn't work. but i don't get any errors???
1. How do you know it does not work? How did you verify that?

2. You don't get any errors because you do not trap the error message. Change your statement to
Expand|Select|Wrap|Line Numbers
  1. $r=mysql_query($query)
  2.    or die ("INSERT error: ".mysql_error());
and see what error message is returned.

Ronald :cool:
Mar 25 '07 #2
basestring
3 New Member
Greet, I didn't know that.

I got the massage INSERT error: Duplicate entry '1003' for key 1

I have 2 rows added with Myphpadmin.
the 3rd Row was added with my script. but wil add the row at the begining and not at the end. my script will check the last row not the first.

Thanks for the advise
Mar 26 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3947
by: Simon | last post by:
Hi, I am having a little problem with my PHP - MySQl code, I have two tables (shown below) and I am trying populate a template page with data from both. <disclaimer>Now I would like to say my skills, especially with MySQL are rudimentary</disclaimer> However my code (link below) fails, the nested database call does not return any data and this has me stumped. Any help will be much appreciated. Many thanks in advance
9
7042
by: Philip D Heady | last post by:
Ok, as some of you may know I'm an Oracle newbie w/ PHP. I'd rather use MySQL but at the office here we use Oracle and boy do I have alot to learn. I'm starting to hate it after using MySQL!! -------------------------------------------------------------------------- 1) Is there a similar statement using PHP/Oracle functions as below for MySQL? -------------------------------------------------------------------------- while (list...
11
2305
by: Dave Smithz | last post by:
Having adopted someone else's PHP cope and completing a crash course in the language I came across a (probably common) problem with the current code. On a registration form, whenever users names have an apostrophe in them it causes problems as they do not get added to the DB correctly for reasons that immediately become apparent. Before implementing my own workaround I noticed the functions. addslashes, stripslashes and directive...
3
1218
by: Amy G | last post by:
I am writing a simple Python program that will read in data from a database (userid, password, username). It will then store the data in a file in the format name:uid:gid:class:change:expire:gecos:home_dir:shell:password or in my case userid::20::::username::sh:password
12
3229
by: Jerry Weinstein | last post by:
Hi, I know about stored procedures and that they can speed up data entry via the SQL 'insert ' statement. However, one drawback to this method is that using the stored procedure still requires one to manually and individually enter each and every record to be inserted to the database before the procedure is executed. I want to circumvent this tedium by finding a way to use maybe a VB application that prompts a user for the data to be...
4
2273
by: chris | last post by:
I open MySQL Manager and connect to my database. I then insert one record in to an InnoDB table in MySQL (4.0 and 4.1 alpha hosted on XP running mysqld --console). I then retrieve the record successfully in MySQL Manager using the existing connection. This indicates that commit is running successfully, (I have seen this on the database trace too). I then try to retrieve the record (through a small MySQL/TomCat
1
3267
by: Mark Everett | last post by:
Hi, I am currently running out of space on one of my database servers. Is it possible to move the relevant files for tables onto another drive and instuct MySql to use both folders for it's data? So basically can you have mulitple data folders setup and if so how is this configured? On another note I could delete some of the older data but the database
4
1355
by: Scott | last post by:
Ok. Brand new at this so please give a little patience and help me on the baby steps. I'm rewriting something I did initially in PHP / MySql on a vb.net / mysql platform. Here's what I'm doing: 1) Data is pulled from the internet and stored to a CSV file 2) Data is loaded into the database with some changes 3) All sorts of data crunching goes on. Step one works fine -- data is saved to a csv file. Step 2 -- The data is loaded...
14
2898
by: Ben | last post by:
I don't know whether anyone can help, but I have an odd problem. I have a PSP (Spyce) script that makes many calls to populate a database. They all work without any problem except for one statement. I first connect to the database... self.con = MySQLdb.connect(user=username, passwd =password) self.cursor = self.con.cursor() self.cursor.execute("SET max_error_count=0")
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10048
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9865
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.