Page 1 of 1

No output result without php -mysql script syntax error

Posted: Sat Aug 09, 2008 3:38 pm
by kdao
Here is a test table products:
prod_id | prod_name | prod_desc | prod_img | prod_price | prod_quan | prod_shipping |
+---------+--------------+---------------------------------+---------------+------------+-----------+---------------+
| 1 | OpenBSD 4.3 | OpenBSD system from BC Canada | openbsd.png | 5.00 | 8 | 1.00 |
| 2 | OPenBSD 4.2 | Unix like OS from Canada | openbsd.png | 4.00 | 2 | 1.00 |
| 3 | NetBSD 4.0 | NetBSD.org | netbsd.png | 4.00 | 2 | 1.00 |
| 4 | FreeBSD 7.0 | FreeBSD unix like OS | freebsd.png | 4.00 | 2 | 1.00 |
| 5 | Slackware 12 | Slack 12 distro based BSD style | slackware.png | 3.00 | 1 | 1.00 |
| 6 | Debian 4.0 | Debian linux distribution | debian.png | 3.00 | 1 | 1.00 |
| 7 | OpenSuse 10 | OpenSuse from Novell | opensuse.png | 5.00 | 2 | 1.00

and here is the script
// final - lesson15 - php-mysql 1
// script name: update_a_product.php
//
include("/usr/local/apache2/htdocs/SCHOOL/oreilly/head_15.inc");

function check_in($updateProduct)
{

if ($updateProduct['prod_id'] &&
$updateProduct['prod_name'] &&
$updateProduct['prod_desc'] &&
$updateProduct['prod_img'] &&
$updateProduct['prod_price'] &&
$updateProduct['prod_quan'] &&
$updateProduct['prod_shipping'])
{ return 1 ;
}
else { return 0;
}
}

// define connection host
$server='localhost';
$user='kdao';
$pass='khaidao';
$db_name='kdao';
$tablename='products';
//

if (check_in($_POST)) { # if checkin valid, enter data into sql table
$submission = $_POST['submit'];
$prod_id = $_POST['prod_id'];
$prod_name = $_POST['prod_name'];
$prod_desc = $_POST['prod_desc'];
$prod_img = $_POST['prod_img'];
$prod_price = $_POST['prod_price'];
$prod_quan = $_POST['prod_quan'];
$prod_shipping=$_POST['prod_shipping'];

$conn = mysql_connect($server,$user,$pass)
or die("cannot connect to database server". mysql_error());

mysql_select_db($db_name,$conn)
or die("Cannot connect to database");

$query = "UPDATE $tablename SET
prod_name = $prod_name,
prod_desc = $prod_desc,
prod_img = $prod_img,
prod_price = $prod_price,
prod_quan = $prod_quan,
prod_shipping = $prod_shipping
WHERE prod_id = $prod_id";

$result = mysql_query($query);

print "<center><B>$tablename ,$prod_name , $prod_id has been $submission successfully Thank You.</B></center>" . "<br>";
}
else {
print "<center><BLINK>$prod_name has not been $submission due to errors.Please try again</BLINK></center>"."<br>";
}
mysql_close($conn);
?>
<?php
include("/usr/local/apache2/htdocs/SCHOOL/oreilly/tail_15.inc");
?>

and here is the form:

<?php
// update product
// scriptname: updateProd.php form
//
include "head_15.inc"
?>

<html>
<head><title> addProduct - lesson15 php-mysql 1 </title></head>
<body>
<h2>Update Product</h2>
<form method ='POST' action=/php/update_a_product.php>
<table border=0>
<tr><td>ProdutID:</td>
<td><input type=text name=prod_id size=5></td> </tr>
<tr><td>ProdutName:</td>
<td><input type=text name=prod_name size=30></td> </tr>
<tr><td>ProductDescrition:</td>
<td><input type=text name=prod_desc size=50></td></tr>
<tr><td>ProductImage:</td>
<td><input type=text name=prod_img size=30></td> </tr>
<tr><td>ProductPrice:</td>
<td><input type=text name=prod_price size=10></td></tr>
<tr><td>ProductQuanity:</td>
<td><input type=text name=prod_quan size=10></td></tr>
<tr><td>ProductShipping</td>
<td><input type=text name=prod_shipping size=10></td></tr>
<td><input type=submit name=submit value="update">


</td>
</tr>
</table>
</form>
</html>
<?php
include "tail_15.inc"


Problems: the script show no error: in fact,
it says: "Table products, $product_name, $product_id has updated successfully.

but actually it does not thing.
I want to update prod_id number 5 for example =100 but nothing has changed even scripts say yes/?

what/where is the errors??????

Thanks for HELP. 8)

Re: No output result without php -mysql script syntax error

Posted: Sun Aug 10, 2008 7:17 am
by acidHL
Could you put your code in code tags please. Makes it easier for us to read :).

Re: No output result without php -mysql script syntax error

Posted: Sun Aug 10, 2008 9:37 am
by kdao
I have changed your quote tags to code tags. If you post further code, please note the difference.

Code: Select all

// script name: update_a_product.php
//
include("/usr/local/apache2/htdocs/SCHOOL/oreilly/head_15.inc");
 
function check_in($updateProduct)
{
 
if ($updateProduct['prod_id'] &&
$updateProduct['prod_name'] &&
$updateProduct['prod_desc'] &&
$updateProduct['prod_img'] &&
$updateProduct['prod_price'] &&
$updateProduct['prod_quan'] &&
$updateProduct['prod_shipping'])
{ return 1 ;
}
else { return 0;
}
}
 
// define connection host
$server='localhost';
$user='kdao';
$pass='khaidao';
$db_name='kdao';
$tablename='products';
//
 
if (check_in($_POST)) { # if checkin valid, enter data into sql table
$submission = $_POST['submit'];
$prod_id = $_POST['prod_id'];
$prod_name = $_POST['prod_name'];
$prod_desc = $_POST['prod_desc'];
$prod_img = $_POST['prod_img'];
$prod_price = $_POST['prod_price'];
$prod_quan = $_POST['prod_quan'];
$prod_shipping=$_POST['prod_shipping'];
 
$conn = mysql_connect($server,$user,$pass)
or die("cannot connect to database server". mysql_error());
 
mysql_select_db($db_name,$conn)
or die("Cannot connect to database");
 
$query = "UPDATE $tablename SET
prod_name = $prod_name,
prod_desc = $prod_desc,
prod_img = $prod_img,
prod_price = $prod_price,
prod_quan = $prod_quan,
prod_shipping = $prod_shipping
WHERE prod_id = $prod_id";
 
$result = mysql_query($query);
 
print "<center><B>$tablename ,$prod_name , $prod_id has been $submission successfully Thank You.</B></center>" . "<br>";
}
else {
print "<center><BLINK>$prod_name has not been $submission due to errors.Please try again</BLINK></center>"."<br>";
}
mysql_close($conn);
?>
<?php
include("/usr/local/apache2/htdocs/SCHOOL/oreilly/tail_15.inc");
?>
 
and here is the form:
 
<?php
// update product
// scriptname: updateProd.php form
//
include "head_15.inc"
?>
 
<html>
<head><title> addProduct - lesson15 php-mysql 1 </title></head>
<body>
<h2>Update Product</h2>
<form method ='POST' action=/php/update_a_product.php>
<table border=0>
<tr><td>ProdutID:</td>
<td><input type=text name=prod_id size=5></td> </tr>
<tr><td>ProdutName:</td>
<td><input type=text name=prod_name size=30></td> </tr>
<tr><td>ProductDescrition:</td>
<td><input type=text name=prod_desc size=50></td></tr>
<tr><td>ProductImage:</td>
<td><input type=text name=prod_img size=30></td> </tr>
<tr><td>ProductPrice:</td>
<td><input type=text name=prod_price size=10></td></tr>
<tr><td>ProductQuanity:</td>
<td><input type=text name=prod_quan size=10></td></tr>
<tr><td>ProductShipping</td>
<td><input type=text name=prod_shipping size=10></td></tr>
<td><input type=submit name=submit value="update">
 
 
</td>
</tr>
</table>
</form>
</html>
<?php
include "tail_15.inc"
 

Re: No output result without php -mysql script syntax error

Posted: Sun Aug 10, 2008 9:45 am
by kdao
I 've got this result. the problem of missing quote in UPDATE starement . It should be like this. Thanks.
$query = "UPDATE $tablename ".
" prod_name = $prod_name, ".
" prod_desc = $prod_desc, " .
" prod_img = $prod_img, " .
" prod_price = $prod_price, " .
" prod_quan = $prod_quan, " .
" prod_shipping = $prod_shipping " .
" WHERE prod_id = $prod_id";