-2
  • Every time i try to insert value in my mysql database from php script, the query fails.
  • Here are my codes.

    if ( empty($_POST)) {
    echo '<script type="text/javascript">
        alert("Tricky, you must have left something empty. That is why you are now will be redirected to Main page. Try again ;)");
        window.location.href ="index.php"</script>';
    
    
    }else {
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $email_id = $_POST['email_id'];
    $your_info = $_POST['your_info'];
    $title = $_POST['title'];
    $feed_area = $_POST['feed_area'];
    $remote_addr = $_SERVER['REMOTE_ADDR'];
    $type = $_POST['type'];   
     if(!empty($first_name) || !empty($last_name) || !empty($email_id) || !empty($your_info) || !empty($title) || !empty($feed_area) || !empty($type))
     {
        echo '<div id="header">
        <div id="middle_heading">Confirmed!!!</div></div>';
        $dbc = mysqli_connect('localhost', 'root', '', 'feed_update');
        $query = "INSERT INTO feed_info (id, first_name, last_name, email_id, your_info, title,type, feed_area, feed_date, remote_addr)" VALUES (0, '$first_name', '$last_name', '$email_id', '$your_info', '$title', '$type', '$feed_area', NOW(), '$remote_addr')";
       mysqli_query($dbc, $query)
       or die("<script type='text/javascript'>alert('query error alert');</script>");   
       mysqli_close($dbc);
       echo '<script type="text/javascript">window.location.href ="index.php"</script>';
       }else {
         echo '<script type="text/javascript">
         alert("Tricky, you must have left something empty. That is why you are now will be redirected to Main page. Try again ;)");
         window.location.href ="index.php"</script>';
          }
        }
        ?>
    

Note:

  • the html is not php self form.
  • I also installed wordpress in my database, is there any problem with it too ?
Virbhadrasinh
  • 529
  • 6
  • 19
MihirUj
  • 43
  • 1
  • 11

1 Answers1

-1

Got the answer , my data needs to be escaped. Short and Sweet use mysql_real_escape_string

for ex. $first_name = mysql_real_escape_string($_POST['first_name']); $last_name = mysql_real_escape_string($_POST['last_name']); and i know you must be thinking, i use mysqli but, when i tried mysqli_real_espace_string() it shows error.

Sorry, for disturbing you people.

MihirUj
  • 43
  • 1
  • 11