Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL database isn't updated, but no errors using PHP

Status
Not open for further replies.

tentious

Technical User
Joined
Jun 19, 2003
Messages
3
Location
US
I am able to input my data from the previous script and the script will actually process the data and tell me that the order was updated. If I view the database, nothing has changed! Everything else works, I've just been working on this for 2 days straight and i've gotten no where. I know it is in this part of the script. Please let me know if anything obvious sticks out.

Thanks in advance,
Nic

Here is the code:



<html><head><title>Orderboard</title></head>
<body>
<?php
$user=$_POST['username'];
$pass=$_POST['pass'];
$ud_id=$_POST['ud_id'];
$ud_requested=$_POST['ud_requested'];
$ud_needby=$_POST['ud_needby'];
$ud_qty=$_POST['ud_qty'];
$ud_description=$_POST['ud_description'];
$ud_cost=$_POST['ud_cost'];
$ud_price=$_POST['ud_price'];
$ud_notes=$_POST['ud_notes'];
$ud_vendor=$_POST['ud_vendor'];
$ud_placedorder=$_POST['ud_placedorder'];
$ud_orderedby=$_POST['ud_orderedby'];
$query=&quot;UPDATE placeorder WHERE id='$ud_id' SET requested=$ud_requested, needby=$ud_needby, qty=$ud_qty, description=$ud_description, cost=$ud_cost, price=$ud_price, notes=$ud_notes, vendor=$ud_vendor, placedorder=$ud_placedorder, orderedby=$ud_orderedby&quot;;

$db=&quot;orderboard&quot;;
$link = mysql_connect(&quot;localhost&quot;, &quot;root&quot;);
if (! $link)
die(&quot;Couldn't connect to MySQL&quot;);
mysql_select_db($db, $link)
or die(&quot;Couldn't open $db: &quot;.mysql_error());
mysql_query($query);
echo &quot;Order Updated&quot;;
mysql_close();
?>
<form method=&quot;POST&quot; action=&quot;orderboard_update_form.php&quot;>
<input type=&quot;hidden&quot; name=&quot;username&quot; value=&quot;<?php print $_POST['username']?>&quot;>
<input type=&quot;hidden&quot; name=&quot;pass&quot; value=&quot;<?php print $_POST['pass']?>&quot;>
<input type=&quot;submit&quot; value=&quot;Change Another&quot;>
</form>

</body>
</html>
 
Hi,

Replace your $query line with this one:

$query=&quot;UPDATE `placeorder` SET `requested` = $ud_requested, `needby` = $ud_needby, `qty` = $ud_qty, `description` = $ud_description, `cost` = $ud_cost, `price` = $ud_price, `notes` = $ud_notes, `vendor` = $ud_vendor, `placedorder` = $ud_placedorder, `orderedby` = $ud_orderedby WHERE id = $ud_id&quot;;

You need ticks around the row names and when you update by id (presuming it's an INT) you don't put ticks around that variable.

Hope this helps!

Nate

mainframe.gif

 
I Tried replacing the query line with the above and the query seems to go through in the browers, but when I look at the actual data, it isn't there.

Thanks,
Nic
 
query=&quot;UPDATE placeorder SET requested='$ud_requested', needby='$ud_needby', qty='$ud_qty', description='$ud_description', cost='$ud_cost', price='$ud_price', notes='$ud_notes', vendor='$ud_vendor', placedorder='$ud_placedorder', orderedby='$ud_orderedby' WHERE id=$ud_id&quot;;
U need a ' around the value ur updating to, if the column ur updating is not of INT type.



--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
tentious,

Make it a bit easier for yourself and let MySQL tell you what's wrong: add error checking after the query is issued.
Code:
mysql_query($query) OR die(mysql_error());

Another good trick is to echo out the SQL and then paste it into PHPMyAdmin or a similar tool.
 
Hum..... none of the above worked.... when I view the contents of the my table.... nothing has change, but again, no error message from mySQL or php. I tried adding the mysql_query($query) OR die(mysql_error()); that didn't give me an error. Thanks for you help guys!

-Nic
 
The &quot;or die(mysql_error())&quot; clause will invoke if there is an SQL error in the query you pass to the database server.

However, if no records match your where clause and no records are changed, that is not an error.

I recommend you output your query to the browser and examine it. Make sure all your variables are being properly added to the string.

If that's okey, cut-and-paste the output the query to your preferred MySQL admin tool. Run the query and see how many records are to be changed by the query.

Want the best answers? Ask the best questions: TANSTAAFL!
 
As far as I know mysql_error() includes messages about missing credentials and privileges.
 
If you don't have permission to the database to which you're trying to connect, warnings will be thrown by mysql_connect() and mysql_select_db(). Whether PHP displays them is dependent on PHP's error reporting configuration.

I use PHP's error-handling mechanism (see set_error_handler(): around blocks of MySQL code so that I get automatic error messages in my preferred format. Sample code is in my FAQ: faq434-2999

Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top