Jump to content

How Do I Return A Specific Row Of Data In Mysql Database


confused and dazed
 Share

Recommended Posts

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

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)?>

Edited by confused and dazed
Link to comment
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...