Hi Guys
I'm only new at php and im having problems with a simple update (so im told). I can retrieve but i now want to be able to update the data that appears and display errors if no data there to show etc... Any help is much appreciated! Heres the code below.
Jen.
<?php
if ($customer_search)
{
$db = mysql_connect("localhost", "fineart");
mysql_select_db("fineart", $db);
$result = mysql_query("select * from customer where customerid = $customer_search" );
$row = mysql_fetch_array($result);
$customer_search = $row['customerID'];
}
if($btnupdate)
$db = mysql_connect("localhost", "fineart");
mysql_select_db("fineart",$db);
$sql = "UPDATE customer SET title = '$title', fname = '$fname', lname = '$lname',
address1 = '$address1', phonenumber = '$phonenumber' WHERE customer_search = $customerid";
$result = mysql_query($sql);
echo $result;
<script language = "Javascript">
alert("Thank you! Information Updated");
</script>
?>
Simple Update
Moderator: General Moderators
Just from looking at your code, u have left off the { and } at the if($btnupdate) segment..
Hope that helps,
PhIrUs
Hope that helps,
PhIrUs
Code: Select all
<?php
if ($customer_search)
{
$db = mysql_connect("localhost", "fineart");
mysql_select_db("fineart", $db);
$result = mysql_query("select * from customer where customerid = $customer_search" );
$row = mysql_fetch_array($result);
$customer_search = $rowї'customerID'];
}
if($btnupdate){
$db = mysql_connect("localhost", "fineart");
mysql_select_db("fineart",$db);
$sql = "UPDATE customer SET title = '$title', fname = '$fname', lname = '$lname',
address1 = '$address1', phonenumber = '$phonenumber' WHERE customer_search = $customerid";
$result = mysql_query($sql);
echo $result;
}
<script language = "Javascript">
alert("Thank you! Information Updated");
</script>
?>- chiefmonkey
- Forum Commoner
- Posts: 25
- Joined: Sat Apr 20, 2002 5:21 am
- Location: Glasgow UK
How about adding mysql_error() as well,
$result = mysql_query($sql) or die(mysql_error());
I am a great believer in building in some type of error checking when testing scripts.
Try writing a simple function which returns mysql_error() and mysql_errorno() and your original query and include it on your production pages then run all your mysql queries through it, obviously remove it when you publish your code
George
$result = mysql_query($sql) or die(mysql_error());
I am a great believer in building in some type of error checking when testing scripts.
Try writing a simple function which returns mysql_error() and mysql_errorno() and your original query and include it on your production pages then run all your mysql queries through it, obviously remove it when you publish your code
George
I think this is more along the line of what you are trying to do...
Hope that helps,
PhIrUs
Code: Select all
<?
// Database constants
define("DATABASE_HOST", "localhost");
define("DATABASE_USER", "** YOUR_USER **");
define("DATABASE_PASSWORD", "** YOUR_PASS **");
define("DATABASE_NAME", "fineart");
$dbLink = mysql_connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD);
if(!$dbLink) {
print "Unable to connect to the database, please contact Sysadmin asap.";
} else {
$dbUse = mysql_select_db(DATABASE_NAME, $dbLink);
}
if(isset($customer_search)){
$result = mysql_query("SELECT * FROM customer WHERE customerid = $customer_search");
$row = mysql_fetch_array($result);
$customer_search = $rowї'customerID'];
}
if(isset($btnupdate)){
$iqry_update = mysql_query("UPDATE customer SET title = '$title', fname = '$fname', lname = '$lname', address1 = '$address1', phonenumber = '$phonenumber' WHERE customer_search = $customerid")
echo "<script language="Javascript">alert("Thank you! Information Updated");</script>";
}
?>PhIrUs