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 6648289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:38:17+00:00 2026-05-26T00:38:17+00:00

I am having an issue with one of my .php pages. adddata.php has a

  • 0

I am having an issue with one of my .php pages.

adddata.php has a form which allows a user to submit certain data to the database however each time the page loads or is refreshed, the empty form is submitted (creating a row of blank values in the DB).

I have little experience with PHP so apologies in advance for any novice mistakes – here is the code:

<html>
<head>
<title>Project IPAM - Add Data</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="container" class="container" style="width:980px">


<?php

include('./templates/header.php'); 
include('./templates/dbconnect.php');


?>



<?php
if(isset($_POST['submit']))
{
    $name = $_POST['address_v4'];
    echo "Successful submitted";

}
?>

<div id="content" style="background-color:#ABCDEF;height:500px;width:980px">

<!--  This is a example submit form to add data to the database !-->



<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form method="post" action="adddata.php">
<table width="" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="3"><strong>Insert Data Into mySQL Database </strong></td>
</tr>
<tr>
<td>IP(v4)</td>
<td>:</td>
<td><input name="address_v4" type="text" id="address_v4" maxlength="15"></td>
</tr>
<tr>
<td>Hostname</td>
<td>:</td>
<td><input name="hostname" type="text" id="hostname" maxlength="32"></td>
</tr>
<tr>
<td>Type</td>
<td>:</td>
<td><select name="type">
<option value="static">Static</option>
<option value="dhcp">DHCP</option>
<option value="reserved">Reserved</option>
</td>
</tr>
<tr>
<td>Updated By</td>
<td>:</td>
<td><input name="updated_by" type="text" id="updated_by" maxlength="16"></td>
</tr>
<tr>
<td>Notes</td>
<td>:</td>
<td><input name="notes" type="text" id="notes" maxlength="128"></td>
</tr>
<tr>
<td>Location</td>
<td>:</td>
<td><textarea cols="17" rows="7" name="location" type="text" id="location" maxlength="64"></textarea></td>
</tr>
<tr>
<td>Default Gateway</td>
<td>:</td>
<td><input name="default_gateway" type="text" id="default_gateway" maxlength="15"></td>
</tr>
<tr>
<td>Subnet Mask</td>
<td>:</td>
<td><input name="subnet_mask" type="text" id="subnet_mask" maxlength="15"></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>


<?php


// Connect to the DB
include_once('./templates/dbconnect.php');

// Get values from form and checks whether values have been initilized using the isset() function.
$address=isset($_POST['address_v4']);
$hostname=isset($_POST['hostname']);
$type=isset($_POST['type']);
$updated_by=isset($_POST['updated_by']);
$notes=isset($_POST['notes']);
$location=isset($_POST['location']);
$default_gateway=isset($_POST['default_gateway']);
$subnet_mask=isset($_POST['subnet_mask']);



// Insert data into mysql 
$sql="INSERT INTO $tbl_name(address_v4, hostname, type, updated_by, notes, location, default_gateway, subnet_mask)
        VALUES('$address','$hostname','$type','$updated_by','$notes','$location','$default_gateway','$subnet_mask')";


if (!mysql_query($sql,$con))//
  {
  die('Error: ' . mysql_error());
  }


mysql_close($con)
?>








</div>
<div id="footer" style="background-color:#FFA500;clear:both;text-align:center;">
Copyright © 2011 Richard Day
</div>
</div>
</body>
</html>
  • 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-26T00:38:18+00:00Added an answer on May 26, 2026 at 12:38 am

    The problem is where you’re checking is your $_POST variables are set, eg.:

    $address=isset($_POST['address_v4']);
    

    isset returns a boolean (true or false) value, not the data that’s in the variable you’re checking against. Change you’re lines to something like this:

    $address=isset($_POST['address_v4']) ? mysql_real_escape_string($_POST['address_v4']) : '';
    

    mysql_real_escape_string will help prevent SQL injection attacks being carried out against your website.

    EDIT

    If I understand you right you also need to check to see if a form has actually been submitted before running your database statement, at the moment you’re running it regardless of whether or not the form has been submitted. Move all of your PHP code from the bottom of the document inside the if(isset($_POST['submit'])) statement at the top, that should sort it out.

    if(isset($_POST['submit'])) {
      $name = $_POST['address_v4'];
      echo "Successful submitted";
    
      // Now the code from the bottom, minus the database file include as you've already got that further up in the code
      $address=isset($_POST['address_v4']) ? mysql_real_escape_string($_POST['address_v4']) : '';
    
      // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're having an issue on one of our fairly large websites with spam bots.
I'm having an issue with one of my controller's AJAX functionality. Here's what I
I'm having an issue setting up one of my projects in TeamCity (v4.0), specifically
One of my users is having an issue when trying to open an Excel
I'm having an issue bending my head around this one. I have a table
In PHP 5.2.x, mySQL 5.x Im having a bit of an issue wrapping my
i am still having the same issue as before but this one is more
I am having an issue with one of my variables, and I cant seem
I am having some issues returning data from on page, using jQuery, PHP and
I have an application which is used for data analysis and I'm having a

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.