...

View Full Version : Help me to Finish



balkan
10-26-2006, 03:29 PM
i have create litle script but i have missing some codes, plz help me to finish ...

base.sql

CREATE TABLE `products` (
`id` int(5) NOT NULL auto_increment,
`key` varchar(25) NOT NULL default '',
`product` varchar(65) NOT NULL default '',
`detail` longtext NOT NULL,
`select` varchar(65) NOT NULL default '',
`datetime` varchar(25) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;


CREATE TABLE `category` (
`id` int(5) NOT NULL auto_increment,
`name1` varchar(65) NOT NULL default '',
`name2` varchar(65) NOT NULL default '',
`name3` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

config.php

<?php

$dbhost = "localhost";
$dbname = "xxx";
$dbuser = "xxx";
$dbpassword = "xxx";

$title = "Products";
$added = "New Product has been successful added";
$add = "Add new Product";

$key1 = "Key";
$product1 = "Product";
$detail1 = "Detail";
$new1 = "New";
$select1 = "Select";
$category1 = "Category";
$date1 = "Date";

?>

balkan
10-26-2006, 03:31 PM
add.php

<?php

include("config.php");

?>


<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php $title; ?></title>
</head>

<body bgcolor="#C0C0C0">

<div align="center">
<table border="1" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
<td bordercolor="#808080">&nbsp;<p>&nbsp;</p>
<p>&nbsp;</td>
</tr>
</table>
<table border="1" width="90%" cellpadding="0" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">&nbsp;</td>
</tr>
</table>
<table border="0" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600" colspan="2">
<p align="center">$add</td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
$key1</td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp</td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
$product1</td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp;<input type="text" name="product" size="53" /></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
$detail1</td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp;<textarea rows="4" cols="45" name="detail"></textarea></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
$new1</td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<input type="checkbox" name="new" value="new"></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
$cd1</td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp;<select size="1" name="select">
<option selected>- Select -</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
$category1</td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp;<select size="1" name="category">
<option selected>- Category -</option>
<option value="name1">Name 1</option>
<option value="name2">Name 2</option>
<option value="name3">Name 3</option>
</select></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p>$data1</td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp;</td>
</tr>
</table>
<table border="1" width="90%" cellpadding="0" style="border: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">
<p align="center"><br>
<form id="form1" name="form1" method="post" action="added.php">
<input type="submit" name="Submit" value="Submit">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" name="Submit2" value="Clear"><br>
&nbsp;</td>
</tr>
</table>
</div>

</body>

</html>

added.php

<?php

include("config.php");

// Connect to server and select database.
mysql_connect("$dbhost", "$dbuser", "$dbpassword")or die("cannot connect server ");
mysql_select_db("$dbname")or die("cannot select DB");

// get data that sent from form
$product=$_POST['product'];
$detail=$_POST['detail'];
$new=$_POST['new'];
$select=$_POST['select'];

//From select Category
$name1=$_POST['name1'];
$name2=$_POST['name2'];
$name3=$_POST['name3'];

$string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$key = "";
for($i=0; $i<5; $i++){
$y = rand(0,strlen($string)-1);
$code .= $string[$y];
}

// if checked show New
if($_POST['new']==="on"){
echo "New <br><br>";

$date=date("d/m/y h:i:s"); //create date time

$sql2="INSERT INTO category (name1, name2, name3)VALUES('$name1', '$name2', '$name3')";

$sql="INSERT INTO products (key, product, detail, new, date)VALUES('$key', '$product', '$detail', '$new', '$date')";
$result=mysql_query($sql, sql2);
}
if($result){
echo "Successful<BR>";
echo "<a href=index.php>View your Products</a>";
}
else {
echo "ERROR";
}
mysql_close();

?>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $title; ?></title>
</head>

<body bgcolor="#C0C0C0">

<div align="center">
<table border="1" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
<td bordercolor="#808080">&nbsp;<p>&nbsp;</p>
<p>&nbsp;</td>
</tr>
</table>
<table border="1" width="90%" cellpadding="0" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">&nbsp;</td>
</tr>
</table>
<table border="0" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
</div>

<div align="center">
<table border="1" width="90%" cellpadding="0" style="border: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">
<p align="center">&nbsp;</p>
<p align="center"><?php echo $added; ?></p>
<p align="center">&nbsp;</td>
</tr>
</table>
</div>

</body>

</html>

balkan
10-26-2006, 03:31 PM
index.php

<?php

include("config.php");

// Connect to server and select database.
mysql_connect("$dbhost", "$dbuser", "$dbpassword")or die("cannot connect server ");
mysql_select_db("$dbname")or die("cannot select DB");

$sql = "SELECT * FROM programi ORDER BY id DESC";

$sql2 = "SELECT * FROM category ORDER BY id DESC";

$result = mysql_query($sql, sql2);

?>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $title; ?></title>
</head>

<body bgcolor="#C0C0C0">

<div align="center">
<table border="1" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
<td bordercolor="#808080">&nbsp;<p>&nbsp;</p>
<p>&nbsp;</td>
</tr>
</table>
<table border="1" width="90%" cellpadding="0" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">&nbsp;</td>
</tr>
</table>

<?php
// Start looping table row
while($rows=mysql_fetch_array($result)){
?>

<table border="0" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600">
<p align="center"><?php echo $key1; ?></td>
<td bordercolor="#808080" style="border-style: solid; border-width: 1px" bgcolor="#FF6600">
<p align="center"><?php echo $product1; ?></php></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600">
<p align="center"><?php echo $detail1; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600">
<p align="center"><?php echo $select1; ?></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p align="center">
<? echo $rows['key']; ?></td>
<td bordercolor="#808080" style="border-style: solid; border-width: 1px">
<p align="center"><? echo $rows['product']; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p align="center">
<?php echo $rows['detail']; ?><?php echo $rows['new']; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p align="center">
<? echo $rows['select']; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p align="center">
<? echo $rows['category']; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p align="center">
<? echo $rows['date']; ?></td>
</tr>
</table>
</div>

<div align="center">
<table border="1" width="90%" cellpadding="0" style="border: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">
<p align="center">&nbsp;</p>
<p align="center"></p>
<p align="center">&nbsp;</td>
</tr>
</table>
</div>

</body>

</html>
<?php } ?>

Crowds
10-26-2006, 03:35 PM
On your index page you have


$sql = "SELECT * FROM programi ORDER BY id DESC";

think that should be



$sql = "SELECT * FROM products ORDER BY id DESC";

Also your echoing out your mysql results wrong


echo $key

should be


echo $result['key'];

Whats the actual problem ?

Crowds

balkan
10-26-2006, 03:38 PM
web site is:

http://www.prerodbalab.org/test/

you can test here.

balkan
10-26-2006, 03:43 PM
this is variable echo $key
i have for result
<? echo $rows['key']; ?>

Crowds
10-26-2006, 03:43 PM
Change your query on index from


$result = mysql_query($sql, sql2);

to


$result = mysql_query($sql, sql2) or die(mysql_error());

and we will see what is going wrong clearer

Crowds
10-26-2006, 03:45 PM
this is variable echo $key
i have for result
<? echo $rows['key']; ?>

Not according to the index page you posted up here....


<?php echo $key1; ?>

Sorry, I see that further down you do have that in place. My mistake.
Put the


or die(mysql_error());

In place and see if that helps give you a clue to what is going wrong

balkan
10-26-2006, 03:46 PM
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/prerodba/public_html/test/index.php on line 13

balkan
10-26-2006, 03:47 PM
yes i know for variable, but i have error in index and i dont know what show me ...

balkan
10-26-2006, 03:48 PM
// Start looping table row
while($rows=mysql_fetch_array($result)){

Crowds
10-26-2006, 03:52 PM
It doesn't like


$sql2 = "SELECT * FROM category ORDER BY id DESC";

Crowds
10-26-2006, 04:07 PM
Try this

Change


$sql = "SELECT * FROM programi ORDER BY id DESC";

$sql2 = "SELECT * FROM category ORDER BY id DESC";

$result = mysql_query($sql, sql2);

to



$sql = "SELECT products.*,category.* FROM products,category ORDER BY id DESC";


$result = mysql_query($sql);

balkan
10-26-2006, 06:10 PM
Column 'id' in order clause is ambiguous

balkan
10-26-2006, 06:19 PM
try to add product in

http://www.prerodbalab.org/test/add.php

show me ERROR to added.php

Crowds
10-26-2006, 06:26 PM
http://www.prerodbalab.org/test/add.php

It added fine with no errors...??

New Product has been successful(ly) added
I cannot see where you echo out the results from the category table on index so it is not needed. Change to



$sql = "SELECT * FROM products ORDER BY id DESC";

$result = mysql_query($sql);

balkan
10-26-2006, 06:33 PM
its blank

http://www.prerodbalab.org/test/index.php

when you add new product look in added.php in header, show ERROR ...


if($result){
echo "Successful<BR>";
echo "<a href=index.php>View your Products</a>";
}
else {
echo "ERROR";
}
mysql_close();

maybe must change some codes, please review again codes ...

Crowds
10-26-2006, 06:54 PM
Ok Change your added.php page to this and then try to add data to your mysql DB.



<?php

include("config.php");

// Connect to server and select database.
mysql_connect("$dbhost", "$dbuser", "$dbpassword")or die("cannot connect server ");
mysql_select_db("$dbname")or die("cannot select DB");

// get data that sent from form
$product=$_POST['product'];
$detail=$_POST['detail'];
$new=$_POST['new'];
$select=$_POST['select'];

//From select Category
$name1=$_POST['name1'];
$name2=$_POST['name2'];
$name3=$_POST['name3'];

$string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$key = "";
for($i=0; $i<5; $i++){
$y = rand(0,strlen($string)-1);
$code .= $string[$y];
}

// if checked show New
if($_POST['new']==="on"){
echo "New <br><br>";

$date=date("d/m/y h:i:s"); //create date time



$sql="INSERT INTO products (key, product, detail, new, date)VALUES('$key', '$product', '$detail', '$new', '$date')";
$result=mysql_query($sql) or die(mysql_error());
}
if(!$result){
echo "ERROR";
}
else {
}

$sql="INSERT INTO category (name1, name2, name3)VALUES('$name1', '$name2', '$name3')";
$result=mysql_query($sql) or die(mysql_error());
}
if($result){
echo "Successful<BR>";
echo "<a href=index.php>View your Products</a>";
}
else {
echo "ERROR";
}
mysql_close();

?>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $title; ?></title>
</head>

<body bgcolor="#C0C0C0">

<div align="center">
<table border="1" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
<td bordercolor="#808080">&nbsp;<p>&nbsp;</p>
<p>&nbsp;</td>
</tr>
</table>
<table border="1" width="90%" cellpadding="0" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">&nbsp;</td>
</tr>
</table>
<table border="0" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
</div>

<div align="center">
<table border="1" width="90%" cellpadding="0" style="border: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">
<p align="center">&nbsp;</p>
<p align="center"><?php echo $added; ?></p>
<p align="center">&nbsp;</td>
</tr>
</table>
</div>

</body>

</html>


Look at the end of each query.
I have added or die(mysql_error());
This helps us get a more detailed idea of what is going wrong instead of just printing "ERROR"

balkan
10-26-2006, 07:02 PM
its ok now whit added.php
now need code to show products in index.php

Crowds
10-26-2006, 07:19 PM
Ok first things first.
Do you need two tables ? products and category ?
From what I can see category is supplied from a drop down menu so there can only be one result. Would it not be simpler to create just the one MySql table like this.



CREATE TABLE products (
id int(5) NOT NULL auto_increment,
key varchar(25) NOT NULL default '',
product varchar(65) NOT NULL default '',
detail longtext NOT NULL,
select varchar(65) NOT NULL default '',
datetime varchar(25) NOT NULL default '',
name varchar(65) NOT NULL default '',
PRIMARY KEY (id)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

balkan
10-26-2006, 07:24 PM
Ok first things first.
Do you need two tables ? products and category ?
From what I can see category is supplied from a drop down menu so there can only be one result. Would it not be simpler to create just the one MySql table like this.



CREATE TABLE products (
id int(5) NOT NULL auto_increment,
key varchar(25) NOT NULL default '',
product varchar(65) NOT NULL default '',
detail longtext NOT NULL,
select varchar(65) NOT NULL default '',
date varchar(25) NOT NULL default '',
PRIMARY KEY (id)
) TYPE=MyISAM AUTO_INCREMENT=1 ;


yes i need to select category, and in drop down menu, so this is table of products, UP. So i see you wanna help me whit this litle script, if you can review all files and add or change some codes, because im newbie in PHP, thank you for you support ....

Crowds
10-26-2006, 08:10 PM
Sorry balkan, there is a little language barrier here :) So you don't need the two tables right?

Just products with


category varchar(65) NOT NULL default '',


Added to it ?

balkan
10-26-2006, 08:40 PM
Sorry balkan, there is a little language barrier here :) So you don't need the two tables right?

Just products with


category varchar(65) NOT NULL default '',


Added to it ?

i was add in products table .

Crowds
10-26-2006, 09:04 PM
Ok then.

Firstly this is the new database layout



CREATE TABLE products (
id int(5) NOT NULL auto_increment,
key varchar(25) NOT NULL default '',
product varchar(65) NOT NULL default '',
detail longtext NOT NULL,
select varchar(65) NOT NULL default '',
datetime varchar(25) NOT NULL default '',
category varchar(65) NOT NULL default '',
PRIMARY KEY (id)
) TYPE=MyISAM AUTO_INCREMENT=1 ;


Your index.php should be



<?php

include("config.php");

// Connect to server and select database.
mysql_connect("$dbhost", "$dbuser", "$dbpassword")or die("cannot connect server ");
mysql_select_db("$dbname")or die("cannot select DB");

$sql = "SELECT * FROM products ORDER BY id DESC";



$result = mysql_query($sql) or die(mysql_error());

?>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $title; ?></title>
</head>

<body bgcolor="#C0C0C0">

<div align="center">
<table border="1" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
<td bordercolor="#808080">&nbsp;<p>&nbsp;</p>
<p></td>
</tr>
</table>
<table border="1" width="90%" cellpadding="0" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">&nbsp;</td>
</tr>
</table>

<?php
// Start looping table row
while($rows=mysql_fetch_array($result)){
?>

<table border="0" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600">
<p align="center"><?php echo $key1; ?></td>
<td bordercolor="#808080" style="border-style: solid; border-width: 1px" bgcolor="#FF6600">
<p align="center"><?php echo $product1; ?></php></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600">
<p align="center"><?php echo $detail1; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600">
<p align="center"><?php echo $select1; ?></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p align="center">
<? echo $rows['key']; ?></td>
<td bordercolor="#808080" style="border-style: solid; border-width: 1px">
<p align="center"><? echo $rows['product']; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p align="center">
<?php echo $rows['detail']; ?><?php echo $rows['new']; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p align="center">
<? echo $rows['select']; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p align="center">
<? echo $rows['category']; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p align="center">
<? echo $rows['date']; ?></td>
</tr>
</table>
</div>

<div align="center">
<table border="1" width="90%" cellpadding="0" style="border: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">
<p align="center">&nbsp;</p>
<p align="center"></p>
<p align="center"></td>
</tr>
</table>
</div>

</body>

</html>
<?php } ?>



Your add.php page should be



<?php

include("config.php");

?>


<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php $title; ?></title>
</head>

<body bgcolor="#C0C0C0">

<div align="center">
<table border="1" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
<td bordercolor="#808080">&nbsp;<p>&nbsp;</p>
<p></td>
</tr>
</table>
<table border="1" width="90%" cellpadding="0" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">&nbsp;</td>
</tr>
</table>
<table border="0" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600" colspan="2">
<p align="center">$add</td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
$key1</td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp</td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
$product1</td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<form id="form1" name="form1" method="post" action="added.php">
&nbsp;<input type="text" name="product" size="53" /></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
$detail1</td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp;<textarea rows="4" cols="45" name="detail"></textarea></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
$new1</td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<input type="checkbox" name="new" value="new"></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
$cd1</td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp;<select size="1" name="select">
<option selected>- Select -</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
$category1</td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp;<select size="1" name="category">
<option selected>- Category -</option>
<option value="name1">Name 1</option>
<option value="name2">Name 2</option>
<option value="name3">Name 3</option>
</select></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p>$data1</td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">&nbsp;
</td>
</tr>
</table>
<table border="1" width="90%" cellpadding="0" style="border: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">
<p align="center"><br>

<input type="submit" name="Submit" value="Submit">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" name="Submit2" value="Clear"></form><br>
&nbsp;</td>
</tr>
</table>
</div>

</body>

</html>


And your added.php page should be



<?php

include("config.php");

// Connect to server and select database.
mysql_connect("$dbhost", "$dbuser", "$dbpassword")or die("cannot connect server ");
mysql_select_db("$dbname")or die("cannot select DB");

// get data that sent from form
$product=$_POST['product'];
$detail=$_POST['detail'];
$new=$_POST['new'];
$select=$_POST['select'];

//From select Category
$category=$_POST['category'];


$string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$key = "";
for($i=0; $i<5; $i++){
$y = rand(0,strlen($string)-1);
$code .= $string[$y];
}

// if checked show New
if($_POST['new']==="on"){
echo "New <br><br>";

$date=date("d/m/y h:i:s"); //create date time



$sql="INSERT INTO products (key, product, detail, new, datetime, category)VALUES('$key', '$product', '$detail', '$new', '$date', '$category')";
$result=mysql_query($sql) or die(mysql_error());
}



if($result){
echo "Successful<BR>";
echo "<a href=index.php>View your Products</a>";
}
else {
echo "ERROR";
}
mysql_close();

?>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $title; ?></title>
</head>

<body bgcolor="#C0C0C0">

<div align="center">
<table border="1" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
<td bordercolor="#808080">&nbsp;<p>&nbsp;</p>
<p></td>
</tr>
</table>
<table border="1" width="90%" cellpadding="0" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">&nbsp;</td>
</tr>
</table>
<table border="0" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
</div>

<div align="center">
<table border="1" width="90%" cellpadding="0" style="border: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">
<p align="center">&nbsp;</p>
<p align="center"><?php echo $added; ?></p>
<p align="center"></td>
</tr>
</table>
</div>
</body>

</html>



Update them and see how you go.

Crowds

balkan
10-26-2006, 09:12 PM
again nothing show in index.php and in added.php in header show ERROR

Crowds
10-26-2006, 09:17 PM
http://www.prerodbalab.org/test/add.php
Is blank.
What have you done with the add.php page ?

balkan
10-26-2006, 09:22 PM
i tested in my localhost, because i cant upload it to my homepage.

Crowds
10-26-2006, 09:34 PM
Why not ?

Did you update all three pages with the code I posted above ?
and did you also update the mysql database ?

I have also noticed this section in added.php



// if checked show New
if($_POST['new']==="on"){
echo "New <br><br>";

$date=date("d/m/y h:i:s"); //create date time



$sql="INSERT INTO products (key, product, detail, new, datetime, category)VALUES('$key', '$product', '$detail', '$new', '$date', '$category')";
$result=mysql_query($sql) or die(mysql_error());
}


Is you intention to only be able to post if the 'new' checkbox is ticked ? because you sql query is inside an if() statement.
And I think that.



if($_POST['new']==="on"){


should be



if($_POST['new'] = "new"){

balkan
10-26-2006, 09:38 PM
yes update all and nothing, if you can to complete it i give you FTP login from :(
http://prerodbalab.org/test/

CapMcButterNuts
10-26-2006, 11:20 PM
Does anyone have any good links for PHP tutorials?

slimy tosser (http://www.elysee.fr/elysee/anglais/the_president/biography/biography.39706.html)

balkan
10-27-2006, 03:29 PM
i change some codes in add.php
so i now only query just KEY and DATE for other values not take action to datebase, in index.php show 2 table how can fix it ?:
add.php

<?php

include("config.php");

?>


<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php $title; ?></title>
</head>

<body bgcolor="#C0C0C0">

<div align="center">
<table border="1" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
<td bordercolor="#808080">&nbsp;<p>&nbsp;</p>
<p>&nbsp;</td>
</tr>
</table>
<table border="1" width="90%" cellpadding="0" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">&nbsp;</td>
</tr>
</table>
<table border="0" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600" colspan="2">
<p align="center"><?php echo $add; ?></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<?php echo $key1; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp;<input type="hidden" name="key" size="53" /></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<?php echo $product1; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp;<input type="text" name="product" size="53" /></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<?php echo $detail1; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp;<textarea rows="4" cols="45" name="detail"></textarea></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<?php echo $new1; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<input type="checkbox" name="new" value="new"></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<?php echo $select1; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp;<select size="1" name="select">
<option selected>- Select -</option>
<option>1</option>
<option2</option>
<option3</option>
<option4</option>
<option5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<?php echo $category1; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp;<select size="1" name="category">
<option selected>- Category -</option>
<option>Name 1</option>
<option>Name 2</option>
<option>Name 3</option>
</select></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<?php echo $date1; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
&nbsp;<?php echo $date; ?></td>
</tr>
</table>
<table border="1" width="90%" cellpadding="0" style="border: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">
<p align="center"><br>
<form id="form1" name="form1" method="post" action="add.php">
<input type="submit" name="Submit" value="Submit">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" name="Submit2" value="Clear"><br>
&nbsp;</td>
<tr>
<td width="70%" align=right> <div align="center">
<?php

$db = mysql_connect("$dbhost", "$dbuser", "$dbpassword")or die("cannot connect server ");
mysql_select_db("$dbname")or die("cannot select DB");

if($_POST['Submit']) {

$string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$key = "";
for($i=0; $i<5; $i++){
$y = rand(0,strlen($string)-1);
$key .= $string[$y];
}

$product = $_POST['product'];
$detail = $_POST['detail'];
$select = $_POST['select'];
$date = date("d/m/y h:i:s");
$new = $_POST['new'];
$category = $_POST['category'];
$sql = "INSERT INTO `products` (`id`, `key`, `product`, `detail`, `select`, `date`, `new`, `category`) VALUES ('', '$key', '$product', '$detail', '$select', '$date', '$new', '$category')" or die('insert into is wrong');
mysql_query($sql,$db) or die('query is wrong.');
print "Product Added Successfull.";
}
?>

&nbsp;</div></td>

</tr>
</table>
</div>

</body>

</html>

index.php

<?php

include("config.php");

// Connect to server and select database.
$db = mysql_connect("$dbhost", "$dbuser", "$dbpassword")or die("cannot connect server ");
mysql_select_db("$dbname")or die("cannot select DB");

$sql = "SELECT * FROM products ORDER BY id DESC";

$result = mysql_query($sql,$db) or die(mysql_error());

?>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $title; ?></title>
</head>

<body bgcolor="#C0C0C0">

<div align="center">
<table border="1" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
<td bordercolor="#808080">&nbsp;<p>&nbsp;</p>
<p>&nbsp;</td>
</tr>
</table>
<table border="1" width="90%" cellpadding="0" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">&nbsp;</td>
</tr>
</table>

<?php

// Start looping table row
while($rows = mysql_fetch_array($result)){

?>

<table border="0" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0">
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600">
<p align="center"><?php echo $key1; ?></td>
<td bordercolor="#808080" style="border-style: solid; border-width: 1px" bgcolor="#FF6600">
<p align="center"><?php echo $product1; ?></php></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600">
<p align="center"><?php echo $detail1; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600">
<p align="center"><?php echo $select1; ?></td>
</tr>
<tr>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p align="center">
<? echo $rows['key']; ?></td>
<td bordercolor="#808080" style="border-style: solid; border-width: 1px">
<p align="center"><? echo $rows['product']; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p align="center">
<?php echo $rows['detail']; ?><?php echo $rows['new']; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p align="center">
<? echo $rows['select']; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p align="center">
<? echo $rows['category']; ?></td>
<td style="border-style: solid; border-width: 1px" bordercolor="#808080">
<p align="center">
<? echo $rows['date']; ?></td>
</tr>
</table>
</div>

<div align="center">
<table border="1" width="90%" cellpadding="0" style="border: 2px solid #FFFFFF">
<tr>
<td bordercolor="#808080">
<p align="center">&nbsp;</p>
<p align="center"></p>
<p align="center">&nbsp;</td>
</tr>
</table>
</div>

</body>

</html>
<?php } ?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum