Jump to content

Recommended Posts

I'm facing database submission issues, please can someone with a good heart help me. Below is my code I don't know what I did wrong it won't submit mydata to the database it gives me error.   Notice: Undefined variable: error in /home/psdelive/public_html/admin/add package.php on line 118

 

<?php 
include('../connection.php');

session_start();


if (isset($_POST['submit'])){
$date  = $_POST['date'];
$location  = $_POST['location'];
$time = $_POST['time'];
$track = $_POST['track'];

$activity = $_POST['activity'];
$details = $_POST['details'];

{
        $query = "INSERT INTO package(date,location,time,track_code,activity,details)VALUES('$date','$location','$time','$track','$activity','$details')";
$check = mysqli_query($dbConn,$query);
if($check)
{
    header('location:success_package');
}
else
{
$error = '<div class="alert-warning" style="height:60px;">

<p style="line-height:40px;">Error in posting</p>
</div>';

}
}
}

$sele = "SELECT * from details";
$query = mysqli_query($dbConn,$sele);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Add Package</title>

<link type="text/css" rel="stylesheet" href="bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap.css" />

<link type="text/css" rel="stylesheet" href="bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap.min.css" />

<link type="text/css" rel="stylesheet"  href="bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap-theme.css" />

<link type="text/css" rel="stylesheet" href="bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap-theme.min.css" />

<script src="bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/js/bootstrap.js"></script>

<script src="bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>

<script src="bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/js/npm.js"></script>
</head>

<style>
body
{
    background:#EEE;
}
</style>

<body>

<div class="container-fluid" style="background:green; height:70px;">

</div>


<div class="container-fluid" style=" min-height:500px;">

<div class="row" style=" min-height:80px;"> 

<div class="col-lg-2" style="background:gray; height:1100px;">


<a class="btn btn-success" style="width:100%; margin-top:20px;" href="dashboard">Dashboard</a>

<a class="btn btn-success" style="width:100%; margin-top:20px;" href="add user">Add Users</a>

<a class="btn btn-success" style="width:100%; margin-top:20px;" href="add package">Add Packages</a>

<a class="btn btn-success" style="width:100%; margin-top:20px;" href="all packages">View Packages</a>

<a class="btn btn-success" style="width:100%; margin-top:20px;" href="send">Send Mail</a>

<a class="btn btn-success" style="width:100%; margin-top:20px;" href="logout">Logout</a>

</div>


<div class="col-lg-10" style="background:#EEE; height:670px;">


<?php

echo $error;
?>


<div class="container" style=" margin-top:60px;background:white; box-shadow:5px 5px 5px gray; width:60%;">


<form class="" action="add package.php" method="post">


<div class="form-group">
<label>Track Number</label>
<select class="form-control" name="track">
<?php
while($row = mysqli_fetch_array($query))
{

?>

<option><?php echo $row['track_code']; ?></option>

<?php
}
?>
</select>

</div>

<div class="form-group">
<label>Date</label>
<input type="text" class="form-control" name="date" style="height:40px;" placeholder="Date" />
</div>


<div class="form-group">
<label>Time</label>
<input type="text" class="form-control" name="time" style="height:40px;" placeholder="Time" />
</div>


<div class="form-group">
<label>Activity</label>
<input type="text" class="form-control" name="activity" style="height:40px;" placeholder="Activity" />
</div>


<div class="form-group">
<label>Location</label>
<input type="text" class="form-control" name="location" style="height:40px;"  placeholder="Location" />
</div>


<div class="form-group">
<label>Details</label>
<input type="text" class="form-control" name="details" style="height:40px;"  placeholder="Details" />
</div>


<div class="container" style=" width:30%; margin-bottom:20px;">
<input class="btn btn-success" style="width:100%;" type="submit" name="submit" value="Save" />
</div>

</form>


</div>


</div>


</div>


</div>


</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/309817-im-facing-database-submission-issues/
Share on other sites

35 minutes ago, gw1500se said:

First please use the code icon (<>) and choose PHP. It makes your code much easier to read. Which is line 118? Did you echo all your variables to make sure they contain what you expect?

<?php 
include('../connection.php');

session_start();


if (isset($_POST['submit'])){
$date  = $_POST['date'];
$location  = $_POST['location'];
$time = $_POST['time'];
$track = $_POST['track'];

$activity = $_POST['activity'];
$details = $_POST['details'];

{
        $query = "INSERT INTO package(date,location,time,track_code,activity,details)VALUES('$date','$location','$time','$track','$activity','$details')";
$check = mysqli_query($dbConn,$query);
if($check)
{
    header('location:success_package');
}
else
{
$error = '<div class="alert-warning" style="height:60px;">

<p style="line-height:40px;">Error in posting</p>
</div>';

}
}
}

$sele = "SELECT * from details";
$query = mysqli_query($dbConn,$sele);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Add Package</title>

<link type="text/css" rel="stylesheet" href="bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap.css" />

<link type="text/css" rel="stylesheet" href="bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap.min.css" />

<link type="text/css" rel="stylesheet"  href="bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap-theme.css" />

<link type="text/css" rel="stylesheet" href="bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap-theme.min.css" />

<script src="bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/js/bootstrap.js"></script>

<script src="bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>

<script src="bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/js/npm.js"></script>
</head>

<style>
body
{
    background:#EEE;
}
</style>

<body>

<div class="container-fluid" style="background:green; height:70px;">

</div>


<div class="container-fluid" style=" min-height:500px;">

<div class="row" style=" min-height:80px;"> 

<div class="col-lg-2" style="background:gray; height:1100px;">


<a class="btn btn-success" style="width:100%; margin-top:20px;" href="dashboard">Dashboard</a>

<a class="btn btn-success" style="width:100%; margin-top:20px;" href="add user">Add Users</a>

<a class="btn btn-success" style="width:100%; margin-top:20px;" href="add package">Add Packages</a>

<a class="btn btn-success" style="width:100%; margin-top:20px;" href="all packages">View Packages</a>

<a class="btn btn-success" style="width:100%; margin-top:20px;" href="send">Send Mail</a>

<a class="btn btn-success" style="width:100%; margin-top:20px;" href="logout">Logout</a>

</div>


<div class="col-lg-10" style="background:#EEE; height:670px;">


<?php

echo $error;\\this is the line I'm having issue with 
?>


<div class="container" style=" margin-top:60px;background:white; box-shadow:5px 5px 5px gray; width:60%;">


<form class="" action="add package.php" method="post">


<div class="form-group">
<label>Track Number</label>
<select class="form-control" name="track">
<?php
while($row = mysqli_fetch_array($query))
{

?>

<option><?php echo $row['track_code']; ?></option>

<?php
}
?>
</select>

</div>

<div class="form-group">
<label>Date</label>
<input type="text" class="form-control" name="date" style="height:40px;" placeholder="Date" />
</div>


<div class="form-group">
<label>Time</label>
<input type="text" class="form-control" name="time" style="height:40px;" placeholder="Time" />
</div>


<div class="form-group">
<label>Activity</label>
<input type="text" class="form-control" name="activity" style="height:40px;" placeholder="Activity" />
</div>


<div class="form-group">
<label>Location</label>
<input type="text" class="form-control" name="location" style="height:40px;"  placeholder="Location" />
</div>


<div class="form-group">
<label>Details</label>
<input type="text" class="form-control" name="details" style="height:40px;"  placeholder="Details" />
</div>


<div class="container" style=" width:30%; margin-bottom:20px;">
<input class="btn btn-success" style="width:100%;" type="submit" name="submit" value="Save" />
</div>

</form>


</div>


</div>


</div>


</div>


</body>

</html>

I'm facing database submission issues, please can someone with a good heart help me. Below is my code I don't know what I did wrong it won't submit mydata to the database it gives me error.   Notice: Undefined variable: error in /home/psdelive/public_html/admin/add package.php on line 118

 

 

Edited by Barand
Moved text out of code

???

Now that you have used the code icon you can see there are syntax errors. Your <?PHP and ?> tags are messed up/missing.

There are other glaring flaws in your code. Never ever put user data directly into a database. You are wide open to injection attacks. Use prepared statements and validate the data. I am guessing that you are not validating anything on the web page before submitting it and I see nothing that validates your data in your PHP script.

Edited by gw1500se
Just now, gw1500se said:

???

Aside from the fact you did not answer my questions there are other glaring flaws in your code. Never ever put user data directly into a database. You are wide open to injection attacks. Use prepared statements as validate the data. I am guessing that you are not validating anything on the web page before submitting it and I see nothing that validates your data in your PHP script.

Thank you sir, for now I'm concerning for the code to work properly like submitting the data to my database. My other file adding user works fine but this file having almost the same code is not submitting just giving me this error. Notice: Undefined variable: error in /home/psdelive/public_html/admin/add package.php on line 118

 

Sir, I can give you the link to help me look into it.

In this code

if($check)
{
    header('location:success_package');
}
else
{
    $error = '<div class="alert-warning" style="height:60px;">
    <p style="line-height:40px;">Error in posting</p>
    </div>';

}

$error is set only if $check is false.

Later on (where you get the error) you try to echo it when it hasn't been set.

Also, you need to exit() from the script after that header() call to prevent the rest of the script from executing. Change the code to...

$error = '';
if($check)
{
    header('location:success_package');
    exit;
}
else
{
    $error = '<div class="alert-warning" style="height:60px;">
    <p style="line-height:40px;">Error in posting</p>
    </div>';

}

 

Just now, gw1500se said:

I suggest you learn to read. I already told you what is wrong. Did you bother to look at the formatted code you posted and the colors? It is very obvious if you just look. That is the point of the the formatter.

Okay Sir, I'm still a newbie. I'm trying it out now, so much thanks for your concern. 

  • Barand changed the title to I'm facing database submission issues

As a newbie you need to learn to focus your post on the parts that are giving you the problem.  Posting a hundred lines of html code is not going to get the attention you need on the PHP code that is the source of your problem.  Limit your posts to the parts you want us to help you with and since this is a PHP forum, all that extraneous html code is a lot of code to wade thru.

Thank you sir,

 

Here is the place I'm having issue.

 

Quote

if (isset($_POST['submit'])){
$date  = $_POST['date'];
$location  = $_POST['location'];
$time = $_POST['time'];
$track = $_POST['track'];

$activity = $_POST['activity'];
$details = $_POST['details'];



{
		$query = "INSERT INTO package(date,location,time,track_code,activity,details)VALUES('$date','$location','$time','$track','$activity','$details')";
$check = mysqli_query($dbConn,$query);
if($check)
{
    header('location:success_package');
    exit;
}
else
{
    $error = '<div class="alert-warning" style="height:60px;">
    <p style="line-height:40px;">Error in posting</p>
    </div>';

}



}
}

And at the line 122 when I want to echo the error gives error Notice: Undefined variable: error

 

Just now, ginerjm said:

As a newbie you need to learn to focus your post on the parts that are giving you the problem.  Posting a hundred lines of html code is not going to get the attention you need on the PHP code that is the source of your problem.  Limit your posts to the parts you want us to help you with and since this is a PHP forum, all that extraneous html code is a lot of code to wade thru.

Thank you, I  showed the full part incase is needed my problem is to insert the datas on the database. Is still giving me error Sir.

You need to figure out why $error is not being set. As a workaround initialize $error to something at the beginning of your code. In any case that has nothing to do with your database not being updated. Which problem are you trying to solve?

Just now, gw1500se said:

You need to figure out why $error is not being set. As a workaround initialize $error to something at the beginning of your code. In any case that has nothing to do with your database not being updated. Which problem are you trying to solve?

When I submit the form it goes to the $error instead of success and it doesn't update in the database.

You still haven't ensured that error is always defined

$error = '';                                       // <----------- YOU MISSED HIS LINE TO DEFINE $error
if($check)
{
    header('location:success_package');
    exit;
}
else
{
    $error = '<div class="alert-warning" style="height:60px;">
    <p style="line-height:40px;">Error in posting</p>
    </div>';

}

 

Please

Just now, gw1500se said:

Obviously the query is failing. You need to echo mysqli_error to determine why.

Please can you add the mysqli_error to my code here

if (isset($_POST['submit'])){
$date  = $_POST['date'];
$location  = $_POST['location'];
$time = $_POST['time'];
$track = $_POST['track'];

$activity = $_POST['activity'];
$details = $_POST['details'];



{
		$query = "INSERT INTO package(date,location,time,track_code,activity,details)VALUES('$date','$location','$time','$track','$activity','$details')";
$check = mysqli_query($dbConn,$query);
if($check)
{
    header('location:success_package');
    exit;
}
else
{
    $error = '<div class="alert-warning" style="height:60px;">
    <p style="line-height:40px;">Error in posting</p>
    </div>';

}



}
}

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.