Jump to content

Simple database update issue


Shadowing

Recommended Posts

I cant figure out why im having this problem.

i stuck this at the top of my page on its own and it wont update the row to read

 

 <?php
mysql_query("UPDATE pm SET read= 'read' WHERE pm_id = '".mysql_real_escape_string($_GET['pm_id'])."'");
?> 

 

I echo $_GET['pm_id']; and that turn out correct and the number matches the pm_id on the row.

everything is lowercase

I typed read manually into the column and echo that and it showed read

also I have this same exact line of code on another script that works fine.

 

does someone see something im over looking? this is driving me crazy :)

 

 

http://localhost/stargate/users/view.php?pm_id=1376672&inbox=2

 

 <?php require("menu.php"); ?>

<html>
<body>
  

<?php
mysql_query("UPDATE pm SET read= 'read' WHERE pm_id = '".mysql_real_escape_string($_GET['pm_id'])."'");

?>



</body>
</html> 

Link to comment
https://forums.phpfreaks.com/topic/253998-simple-database-update-issue/
Share on other sites

yah i know its not case sensitive but mention it anyways lol

 

added more details in my first post

 

I even tried

 

 <?php mysql_query("UPDATE pm SET read= 'read'"); ?> 

 

that should make every row set to read right?

 

the column is set to length of 6 and type VARCHAR

Stop embedding the query string in the query execution. Form it in a variable, then use the variable to execute the query so you can echo the query string when things like this happen. Check to make sure the query executes successfully and if not, echo the query string and mysql_error(). Post any errors returned by MySQL.

 

$query = "SELECT field FROM table";
if( $result = mysql_query($query) ) {
     // do whatever you need to do for a successful query execution
} else {
     echo "<br>Query: $query<br>Produced error: " . mysql_error() . '<br>';
}

yah i need to start debugging more. this will help me out alot in the future

 

Query: UPDATE pm SET read= 'read' WHERE pm_id = '1376672'

Produced error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read= 'read' WHERE pm_id = '1376672'' at line 1

 

 <?php 
$query = ("UPDATE pm SET read= 'read' WHERE pm_id = '".mysql_real_escape_string($_GET['pm_id'])."'");
			if( $result = mysql_query($query) ) {


} else {     

                                    echo "<br>Query: $query<br>Produced error: " . mysql_error() . '<br>';} ?> 

wierd

 

i have this code in another script that works fine

 

 <?php mysql_query("UPDATE users SET monitor= 'mod' WHERE goauld = '".mysql_real_escape_string($_POST['add_mod'])."'");
?> 

Huge help Pikachu

thanks so much

now i can debug stuff in the future

 

I solved it with this

 

 <?php $query = ("UPDATE `pm` SET `read`= 'read' WHERE `pm_id` = '".mysql_real_escape_string($_GET['pm_id'])."'"); ?> 

 

I'll read the link you just gave me too

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.