sorry about my lack of explination guys ill try to do better now here goes
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$conn = mysql_connect("localhost","root","Whatevermann123") or die(mysql_error());
mysql_select_db("customerdirectory",$conn) or die(mysql_error());
$next_program = "added.php";
$sql = "INSERT INTO merchant values('$_POST[merchant_num]',
'$_POST[date_recieved]',
'$_POST[merchant_name]',
'$_POST[purchase_type]',
'$_POST[lease_score]',
'$_POST[amex]',
'$_POST[app_id]',
'$_POST[discover]',
'$_POST[user_name]',
'$_POST[check_conversion]',
'$_POST[gift_loyalty]',
'$_POST[app_type]',
'$_POST[terminal]',
'$_POST[serial_num]',
'$_POST[nms]',
'$_POST[ckmerchant_num]',
'$_POST[giftmerchant_num]',
'$_POST[comments]')";
all im doin in this first part is first reporting my errors then inserting the fields on my form into the database with the INSERT query
Code: Select all
$check_num = $_POST['merchant_num'];
(much thanks to everah for the original write of this half

)
here a im taking the value of the number or merchant_num that is being posted and giving it the variable name $check_num
Code: Select all
// Validate $check_num here
// Validation complete
$sql = "SELECT `merchant_num` FROM `merchant` WHERE `merchant_num` = '". mysql_real_escape_string($check_num)."'";
if (!$result = mysql_query($sql, $conn))
{
die(mysql_error());
}
this is where i actually make the comparison of the number entered in text field merchant_num to the numbers stored in the database under the column merchant_num
Code: Select all
if (mysql_num_rows($result) > 0)
{
echo 'The merchant number ' . $check_num . ' has already exists. Please check merchant information and try again';
}
else
{
header("Location: $next_program");
}
this last part finds that row saying that if the that number exist or $result >0 then give me that message
but thats all i wanted to do....originally the script would say something went wrong if a similar number was entered in merchant_num...which it should because merchant_num is the primary key in the database...but i wanted to find a way so that when someone does that it tells them why something is wrong....instead of telling them something is wrong which was originally a message for me that i screwed up somewhere in my coding via this
Code: Select all
/*else if(mysql_query($sql, $conn))
{
header("Location: $next_program");
}
else
{
echo "something went wrong";
}*/
//commented out because i couldnt figure out a way to use it with my other if without php throwing a fit at me
?>
theres my explanation guys...thanks to all of you for your help