I am not experienced with mysql or php and i keep mentioning that in my questions but people keep saying you need mysql injection protection and I've looked it up and i really don't get it. Can anyone help me? I am so new to mysql and am having a bit of trouble with it
Here is my code:
How can it be improved? When i go to view my source code by right clicking on the site, none of the php/mysql appears.
<?php
$conn = mysql_connect("", "", "");
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
$search = "%".$_POST["search"]."%";
$searchterm = "%".$_POST["searchterm"]."%";
if (!mysql_select_db("")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
$sql = "SELECT name,lastname,email
FROM test_mysql
WHERE name LIKE '%".$search."%' AND lastname LIKE '%".$searchterm."%'";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if(empty($_GET['search'])){ // or whatever your field's name is
echo 'no results';
} else {
performSearch(); // do what you're doing right now
}
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
while ($row = mysql_fetch_assoc($result)) {
echo '<br><br><div class="data1">';
echo $row["name"];
echo '</div><br><div class="data2">';
echo $row["lastname"];
echo '</div><br><div class="data3">';
echo $row["email"];
echo '</div>';
}
mysql_free_result($result);
?>