confused and dazed Posted December 21, 2011 Share Posted December 21, 2011 Hello internet. I am finding it difficult to find any information on how to actually select just one row of data based on the user supplying two specific entries. Any suggestions? I have tried to use select but cannot get it to work to pull a row out with the user specifying which row by entering two specific entries. Please help. Link to comment Share on other sites More sharing options...
niche Posted December 21, 2011 Share Posted December 21, 2011 Please post your code. It would be difficult to help you without it. Link to comment Share on other sites More sharing options...
confused and dazed Posted December 21, 2011 Author Share Posted December 21, 2011 O.K. so here is my code. It removes an entry but does not inform the user if thier entries were not matched with anything in the database. So I thought I could use select to confirm the data but cannot figure out how to do it. In the end I want the user to enter two peices of data and have the script delete that row but if there are no matches it would return a message that there were no matches. I have not included the .html but that is straight forward with text fields for the user to enter data. <?php$con = mysql_connect("xxx","xxx","xxx");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("xxx", $con);$sql="DELETE FROM testsqlWHERE name='$_POST[rname]' AND total='$_POST[rtotal]'"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "1 record removed"; mysql_close($con)?> Link to comment Share on other sites More sharing options...
JamesB Posted December 21, 2011 Share Posted December 21, 2011 you could check how many rows were deleted with mysql_affected_rows(): if (mysql_affected_rows($con) == 0) { // no row was removed}else { // 1 or more rows were removed} or run a select count before hand: $query = "SELECT COUNT(*) FROM testsql WHERE name='$_POST[rname]' AND total='$_POST[rtotal]'";$result = mysql_query($query, $con); $row = mysql_fetch_row($result);$rowCount = $row[0]; if ($rowCount == 0) { // row not found}else { // row found} Link to comment Share on other sites More sharing options...
confused and dazed Posted December 21, 2011 Author Share Posted December 21, 2011 JamesB Thanks for the suggestion. The following code works perfectly!!! if (mysql_affected_rows($con) == 0) {echo "no row was removed";}else {echo "1 or more rows were removed";} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.