Re: Select and compare problems still ...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 7/1/09 10:29 AM, "Andrew Ballard" <aballard@xxxxxxxxx> wrote:

$data = array($ucName, $ucAddress, $inDate, $inType, $notes,
> $critical, $cleanViolations, $noncritical);
>
> $sql = vprintf("INSERT INTO `restaurants` (name, address, inDate,
> inType, notes, critical, cviolations, noncritical) VALUES ('%s', '%s',
> '%s', '%s', '%s', '%s', '%s', '%s')",
> array_map('mysql_real_escape_string', $data));
>
> $result = mysql_query($sql) or die(mysql_error());

Well I had wondered about the escape_string and did it like this, now I have a new problem, it is inserting all the records in the database (making duplicates) I want it to match the records and only insert the ones not there...

Here's my code so far:

$cleanViolations = str_replace('*', '', $cviolations);    $ucName = ucwords($name);    $ucAddress = ucwords($address);    $mysql_name = mysql_escape_string($ucName);    $mysql_address = mysql_escape_string($ucAddress);    $mysql_inDate = mysql_escape_string($inDate);    $mysql_inType = mysql_escape_string($inType);    $mysql_notes = mysql_escape_string($notes);    $mysql_critical = mysql_escape_string($critical);    $mysql_cviolations = mysql_escape_string($cleanViolations);    $mysql_noncritical = mysql_escape_string($noncritical);               echo "$ucName <br>";        echo "$ucAddress <br>";        echo "$inDate <br>";        echo "$inType <br>";        echo "$notes <br>";        echo "$critical <br>";        //echo "$cviolations <br>";        echo "$cleanViolations <br>";        echo "$noncritical <br><hr>";                 //compare entries and insert new inspections to the database //call what is in the database    $query = "SELECT * FROM  restaurants  WHERE name LIKE '$mysql_name' AND address LIKE '$mysql_address' AND inDate LIKE '$mysql_inDate' AND inType LIKE '$mysql_inType'" ;     $result = mysql_query($query) or die(mysql_error());          echo $result;     $row = mysql_numrows($result);          if ($row == 0){        $sql = "INSERT INTO `restaurants` (name, address, inDate, inType, notes, critical, cviolations, noncritical)  VALUES (" ;  $sql .= " '$ucName', '$ucAddress', '$inDate', '$inType', '$notes', '$critical', '$cleanViolations', '$noncritical')";            $result = mysql_query($sql) or die(mysql_error());    }  /**/ };

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux