![]() |
|
|
|
|
|
|
8
20th October 00:45
External User
Posts: 1
|
I won't say anything about what others have already warned you about, but here is what I would do.
<?php $request_id = intval($_GET['id']); $current_user = substr($_SERVER['AUTH_USER'], 13); $lock_query = " SELECT id, locked_by_user FROM locked_payments WHERE id = '{$request_id}'"; $lock_result = mssql_query($lock_query) or die('MSSQL ERROR: Lock Query Failed<br />'. mssql_get_last_message()); # ## here is the key to making this work... # checking to make sure that the query returned 0 (zero) results # http://us3.php.net/mssql_num_rows if ( mssql_num_rows($lock_result) == 0 ) { $set_lock = "INSERT INTO locked_payments (id,locked_by_user) VALUES ('{$request_id}','{$current_user}')"; mssql_query($set_lock) or die ('MSSQL ERROR: Insert failed:<br />'. mssql_get_last_message()); } ?> -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare |
|
|
9
20th October 00:46
External User
Posts: 1
|
I wouldn't check for an empty array, but rather if affected rows > 0
-- like so: // check to see if there is a record for this page $query = "SELECT * FROM pages WHERE page_id = $page_id"; $result = mysql_query($query) or die('Error, query 1 failed ' . mysql_error(). $query); $seg = mysql_real_escape_string($segment); if (mysql_affected_rows() > 0) // if record exist then add data to it { $query = "UPDATE pages SET segment_id= '$seg' WHERE page_id= '$page_id' "; $result = mysql_query($query) or die('Error, query 2 failed ' .. $query); } else // else create new record and then add data to it { $query = "INSERT INTO pages ($page_id, segment_id) VALUES ( '$page_id' , '$seg' )"; $result = mysql_query($query) or die('Error, query 3 failed ' .. mysql_error()); } Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |
|
|
10
20th October 00:46
External User
Posts: 1
|
if you don't actually need to know inside of PHP whether or not it
exists, you can skip the PHP work and have mysql do it for you: http://dev.mysql.com/doc/refman/5.0/...duplicate.html |
|