Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Development Tools
 ASP.NET
 Update Database help
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sauder84
Starting Member

1 Posts

Posted - 10/10/2013 :  14:32:19  Show Profile  Reply with Quote
I am trying to update the database with the following code but I keep getting the following error

"Incorrect syntax near the keyword 'where'. (severity 15)"

And here is my code written in php:

Thanks in advance for the help!

FILE #1
<script language="javascript">

function reload(form)

{

var val=form.fn.options[form.fn.options.selectedIndex].value;

var val2=form.itemcode.options[form.itemcode.options.selectedIndex].value;

//var val3=form.price.options[form.price.options.selectedIndex].value;

self.location='priceupdate2.php?fn=' + val +
'&itemcode=' + val2 + '&price=' ;

}



</script>

</head>
<style type = "text/css">
body {color: #000080;
background: #C0C0C0}
</style>
<center>

<div id="wrapper">
<div id="header">
<center><h1>Customer Price Update</center></h1>
</div>
<div id="subheader">
<?php ?>
</div>
<div id="leftmenu">

<?php


require_once('config.php');
ini_set('error_reporting', E_ALL ^ E_NOTICE);
ini_set('display_errors', 'on');

$conn= mssql_connect($servername, $username, $password) or
die ("Can't connect to SQL Server");
mssql_select_db($database, $conn) or die ("Can't connect to database");

$fnName=@$_GET['fnName'];
$fn = $_GET['fn'];
$itemcode=@$_GET['itemcode'];
$price=@$_GET['price'];

///////// Getting the data from sql table for first list box//////////
@$quer=mssql_query("Select fnname, fn
from TESTING.DBO.feeds
");
///////////// End of query for first list box////////////

/////// for second drop down list we will check if fnname
//is selected else we will display all the itemcodes/////
if(isset($fn) and strlen($fn) > 0){
@$quer2=mssql_query("select itemcode from TESTING.DBO.feed_pricelist
where fn = '$fn'");
}else{
$quer2=mssql_query("select itemcode from TESTING.DBO.feed_pricelist
where fn = '$fn'");
}
////////// end of query for second itemcode drop down list box

///// third drop down box query again check if the
//category has been selected else we will display all the subcategory

//if(isset($itemcode) and strlen($itemcode) > 0){
//@$quer3=mssql_query("SELECT price FROM TESTING.DBO.feed_pricelist
// where fn = '$fn' and itemcode = '$itemcode'");
//}else{
// $quer3=mssql_query("SELECT price FROM TESTING.DBO.feed_pricelist
// where fn= '$fn' and itemcode = '$itemcode'"); }
//
//end of form////


echo "<form method=post name=f1 action='dd-check.php'>";
echo "<table> <tr><td>";

////////// Starting of first drop downlist /////////

echo "Customer Name";
echo"</td><td>";
echo "<select name='fn' onchange=\"reload(this.form) \">";
if ($fn == ''){
echo "<option value=''>Select One</option>";
$selected = '';
while($result = mssql_fetch_array($quer)) {
echo "<option value='$result[fn]' >$result[fnname]</option><br>";}
}else {
$sql = "select fn, fnname from TESTING.DBO.feeds where fn = '$fn'";

$resultsfn = mssql_query($sql);

while($result = mssql_fetch_array($quer)) {
if($result['fn']==$fn){
$selected = 'selected';}
else{
$selected = '';}
echo "<option value='$result[fn]'
$selected>$result[fnname]</option><br>";}
}
echo "</select></td></tr><tr><td>";
////////////////// This will end the first drop down list ///////////
////////////////// Starting of second drop downlist ////////////////
echo "Item Code";
echo"</td><td>";
echo "<select name='itemcode' onchange=\"reload(this.form) \">";
if ($itemcode == ''){
echo "<option value=''>Select One</option>";
$selected1 = '';
while($result1 = mssql_fetch_array($quer2)) {
echo "<option value='$result1[itemcode]' >$result1[itemcode]</option><br>";}
}else {
$sql2 = "select itemcode from TESTING.DBO.feed_pricelist where fn = '$fn'";

$resultsitem = mssql_query($sql2);

while($result1 = mssql_fetch_array($quer2)) {
if($result1['itemcode']==$itemcode){
$selected1 = 'selected';}
else{
$selected1 = '';}
echo "<option value='$result1[itemcode]'
$selected1>$result1[itemcode]</option><br>";}
//echo "<option value = '$resultsitemcode[itemcode]'>
// $resultsitemcode[itemcode]</option>"."<BR>";
}

echo "</select></td></tr><tr><td>";
////////////////// This will end the second drop down list ///////////
///////////////// starting text box for price//////
$sql3 = "select price from TESTING.DBO.feed_pricelist
where fn = '$fn' and itemcode = '$itemcode' ";
$resultprice = mssql_query($sql3);
$resultpriceitem = mssql_fetch_array($resultprice);
$price = $resultpriceitem['price'];
if($price != ''){
echo " Current Price ";
echo "</td><td>";
echo "$";
echo "$price" ;

}

echo "</select></td></tr><tr><td>";
echo "</form>";

?>


<?php
echo '<html>
<body>
<div>
<style type = "text/css">
</style>
<form name = "input" action = "update_customer_price.php" method = "get">
Update Price </td><td><input type = "text" name = priceUpdate >


<input type = "submit" value = "Update">




</div>
</body>
</html>
'
?>

FILE#2

<head>
<style type = "text/css">
body {color: #000080;
background: #C0C0C0}
</style>
</head>

<?php

require_once('config.php');
ini_set('error_reporting', E_ALL ^ E_NOTICE);
ini_set('display_errors', 'on');

$conn= mssql_connect($servername, $username, $password) or die ("Can't connect to SQL Server");
mssql_select_db($database, $conn) or die ("Can't connect to database");

$fn = $_POST['fn'];
$itemcode = $_POST['itemcode'];
$price = $_POST['price'];



$sql = "UPDATE TESTING.DBO.feed_pricelist SET
price = CONVERT(INT, price)";

$result = mssql_query($sql);

$sql1 = "UPDATE TESTING.DBO.feed_pricelist SET
fn = '$fn',
itemcode = '$itemcode',
price = $price
where fn = '$fn' ";

$result1 = mssql_query($sql1);

echo $price;


//echo "<h3> Customer Price has been updated</h3>"
?>
<h3>Customer price has been updated!</h3>
<h3>Do you need to update another?</h3>
<form name="input" action="PriceUpdate2.php" method="post">
<input type="submit" value="Enter"></form>
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000