Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6248211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:00:55+00:00 2026-05-24T13:00:55+00:00

I’m new to PHP, and I have stumble on the problem which I don’t

  • 0

I’m new to PHP, and I have stumble on the problem which I don’t know how to solve. I’m 99% it is due my poor knowledge of PHP ( I’m PHP user since last Monday:) )

Just in front I will declarate that:

  • db conncetion is working
  • table does exist
  • values are saved correctly to the db

I have following form:

<form id="loginForm" name="loginForm" method="post" action="../exe/news-exec.php">
      <input name="live" type="checkbox" class="textfield" id="live" />
      <input name="content" type="text" class="textfield" id="content" />
      <input type="submit" name="Submit" value="Register" />
</form>

And following file is executing this:

<?php
    //Start session
    session_start();

    //Include database connection details
    require_once('../inc/config.php');

    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
        die("Unable to select database");
    }

    //Function to sanitize values received from the form. Prevents SQL injection
    function clean($str) {
        $str = @trim($str);
        if(get_magic_quotes_gpc()) {
            $str = stripslashes($str);
        }
        return mysql_real_escape_string($str);
    }

    //Sanitize the POST values
    $live = clean($_POST['live']);
    $content = clean($_POST['content']);



    if(isset($live)) { $live = 1;}
    if(!isset($live)) { $live = 0;}



    //Create INSERT query
    $qry = "INSERT INTO news(live, content) VALUES('$live','$content') ";
    $result = @mysql_query($qry);

    //Check whether the query was successful or not
    if($result) {
        echo $live."<br /><br />";
        echo '<a href="../">Index File</a>';

        exit();
    }else {
        die("Query failed");
    }
?>

What the form should do:

  • if the checkbox is checked – save the value of ‘1’ into field ‘live’ in the table ‘news’
  • if the checkbox is NOT checked – save the value of ‘0’

If the checkbox has been checked everything is working fine, but if the checkbox is not checked (should echo $live = 0 ), but is displaying value = 1 and following notice: Notice: Undefined index: live in C:\wamp\www\exe\news-exec.php on line 30

Line 30: $live = clean($_POST['live']);

I’m 99% sure the problem are those declaration:

if(isset($live)) { $live = 1;}

if(!isset($live)) { $live = 0;}

What I’m doing wrong? Any suggestion much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:00:56+00:00Added an answer on May 24, 2026 at 1:00 pm

    Try this:

    if (isset($_POST['live'])) $live=1; else $live=0;
    

    Line 30: $live = clean($_POST['live']);
    causes isset($live) to be true, no matter if $_POST['live'] is set or not, so you have to check $_POST['live'] directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a text area in my form which accepts all possible characters from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.