Reputation: 63
httPHP Mysqli condition block is not working.. Earlier it was working, later i added few more scripts thn its not working.. I'm new to PHP.
note : Database insertion is working. only the condition is not working
<?php
if (!$_GET)
{
header('location:index.php');
}
else
{
$language['english'] = array(
'url' => 'http://example.com'
);
$language['chinese'] = array(
'url' => 'http://example.com'
);
$language['japanese'] = array(
'url' => 'http://example.com'
);
if (isset($_POST['submit']))
{
$count_me_in = sanitize($_POST['con_in']);
$email = sanitize($_POST['email']);
$comments = sanitize($_POST['comments']);
$ip = $_SERVER['REMOTE_ADDR'];
$sql = "INSERT INTO $table_name (count_me_in, email, comments, REMOTE_Addr) VALUE (" . PrepSQL($count_me_in) . ", " . PrepSQL($email) . ", " . PrepSQL($comments) . ", " . PrepSQL($ip) . ")";
$query = mysqli_query($conn, $sql);
var_dump($query);
if ($query)
{ /// this condition not working
echo "Thanks for submitting";
// echo "<script type='text/javascript'>alert('Thank you for your feedback');</script>";
}
else
{
echo "Error: " . $sql . "<br />" . mysqli_error($conn);
}
}
function sanitize($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
function PrepSQL($value)
{
// Stripslashes
if (get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
include 'connect.php';
// Quote
$value = "'" . mysqli_real_escape_string($conn, $value) . "'";
return ($value);
}
?>
<html>My html program <html>
<?php
}
?>
Upvotes: 0
Views: 53
Reputation: 662
Use the below code. You have missed the closing brace
if(!$_GET){
header('location:index.php');
}else{
$language['english'] = array('url' => 'http://example.com');
$language['chinese'] = array('url' => 'http://example1.com');
$language['japanese'] = array('url' => 'http://example2.com');
if(isset($_POST['submit'])){
$count_me_in = sanitize($_POST['con_in']);
$email = sanitize($_POST['email']);
$comments = sanitize($_POST['comments']);
$ip = $_SERVER['REMOTE_ADDR'];
include 'connect.php';
$sql = "INSERT INTO $table_name (count_me_in, email, comments, REMOTE_Addr) VALUE (".
PrepSQL($count_me_in) . ", " .
PrepSQL($email) . ", " .
PrepSQL($comments) . ", " .
PrepSQL($ip) . ")";
if(mysqli_query($conn, $sql)){ /// this condition not working
echo "Thanks for submitting";
//echo "<script type='text/javascript'>alert('Thank you for your feedback');</script>";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
}
Upvotes: 1