Check if a line exists, another one

Motive: I just want to cross a string with the given data if one with the same data doesn't exist. The thing I've tried so far is

CODE:

<?php
if(empty($_GET['a'])) {$xyz ="new";} else{$xyz=$_GET['a'];}
$servername = "mysql.soemwhere.com";
$username = "u130204422_acb";
$password = "YES-I-KNOW";
$dbname = "u130204422_acb";


$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$output ="SELECT * FROM trailers
WHERE url='$xyz' LIMIT 1";
$result = mysqli_query($conn,$output);
while($row = mysqli_fetch_array($result)) {
 $pid=$row["title"];
echo $pid;}
if (mysqli_num_rows($result) > 0) {echo 'yes';}
else{
$msql = "INSERT INTO `trailers`(`url`,`title`) VALUES ('$xyz','dekhlia')";
if ($conn->query($msql) === TRUE) {
    echo "New record created successfully. Refrsh the page and it will echo dekhlia";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;}
echo "hehe";
$conn->close();} 
?>

      

I cannot figure out why this code is not working.

+3


source to share


1 answer


There is no need to add concatenation to the SQL string.

This is part of the sting, so remove it.

Edit



$output ="SELECT * FROM trailers
WHERE url='.$xyz.' LIMIT 1";

      

To:

$output ="SELECT * FROM trailers
WHERE url='$xyz' LIMIT 1";

      

+2


source







All Articles