Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 01-28-2022, 11:53 AM   #1
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,140
Why isnt this CREATE page working?

I'm trying to put together a simple domain managament database.

Its telling me that something went wrong when I try to add a new domain name record, yet it isnt highlighting any form fields with an error:

Quote:
<?php
// Include config file
require_once "config.php";

// Define variables and initialize with empty values
$Registrar = $DomainName = $Registration = $Expiration = $NameServer1 = $NameServer2 = $Status = $Notes = "";
$Registrar = $DomainName_err = $Registration_err = $Expiration_err = $NameServer1_err = $NameServer2_err = $Status_err = $Notes_err = "";

// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){

// Validate registrar
$input_Registrar = trim($_POST["Registrar"]);
if(empty($input_Registrar)){
$Registrar_err = "Please enter Registrar.";
} else{
$Registrar = $input_Registrar;
}

// Validate domainname
$input_DomainName = trim($_POST["DomainName"]);
if(empty($input_DomainName)){
$DomainName_err = "Please enter DomainName.";
} else{
$DomainName = $input_DomainName;
}
// Validate registration
$input_Registration = trim($_POST["Registration"]);
if(empty($input_Registration)){
$Registration_err = "Please enter Registration Date.";
} else{
$Registration = $input_Registration;
}
// Validate expiration
$input_Expiration = trim($_POST["Expiration"]);
if(empty($input_Expiration)){
$Expiration_err = "Please enter Expiration Date.";
} else{
$Expiration = $input_Expiration;
}
// Validate nameserver1
$input_NameServer1 = trim($_POST["NameServer1"]);
if(empty($input_NameServer1)){
$NameServer1_err = "Please enter NS1.";
} else{
$NameServer1 = $input_NameServer1;
}
// Validate nameserver2
$input_NameServer2 = trim($_POST["NameServer2"]);
if(empty($input_NameServer2)){
$NameServer2_err = "Please enter NS2.";
} else{
$NameServer2 = $input_NameServer2;
}
// Validate status
$input_Status = trim($_POST["Status"]);
if(empty($input_Status)){
$Status_err = "Please enter Domain Status.";
} else{
$Status = $input_Status;
}
// Validate notes
$input_Notes = trim($_POST["Notes"]);
if(empty($input_Notes)){
$Notes_err = "Please enter Notes.";
} else{
$Notes = $input_Notes;
}

// Check input errors before inserting in database
if(empty($Registrar_err) && empty($DomainName_err) && empty($Registration_err) && empty($Expiration_err) && empty($NameServer1_err) && empty($NameServer2_err) && empty($Status_err) && empty($Notes_err)){
// Prepare an insert statement
$sql = "INSERT INTO DomainManagement (Registrar, DomainName, Registration, Expiration, NameServer1 NameServer2 Status Notes) VALUES (?, ?, ?, ?, ?, ?, ?)";

if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "sss", $param_Registrar, $param_DomainName, $param_Registration, $param_Expiration, $param_NameServer1, $param_NameServer2, $param_Status, $param_Notes);

// Set parameters
$param_Registrar = $Registrar;
$param_DomainName = $DomainName;
$param_Registration = $Registration;
$param_Expiration = $Expiration;
$param_NameServer1 = $NameServer1;
$param_NameServer2 = $NameServer2;
$param_Status = $Status;
$param_Notes = $Notes;

// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Close statement
mysqli_stmt_close($stmt);
}
// Records created successfully. Redirect to landing page
header("location: index.php");
exit();
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}

// Close connection
mysqli_close($link);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<meta charset="UTF-8">
<title>Create Record</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
.wrapper{
width: 600px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<h2 class="mt-5">Create Record</h2>
<p>Please fill this form and submit to add new domain to the database.</p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">

<div class="form-group">
<label>Registrar</label>
<textarea name="Registrar" class="form-control <?php echo (!empty($Registrar_err)) ? 'is-invalid' : ''; ?>"><?php echo $Registrar; ?></textarea>
<span class="invalid-feedback"><?php echo $Registrar_err;?></span>
</div>
<div class="form-group">
<label>Domain</label>
<input type="text" name="DomainName" class="form-control <?php echo (!empty($DomainName_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $DomainName; ?>">
<span class="invalid-feedback"><?php echo $DomainName_err;?></span>
</div>
<div class="form-group">
<label>Registration</label>
<input type="text" name="Registration" class="form-control <?php echo (!empty($Registration_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $Registration; ?>">
<span class="invalid-feedback"><?php echo $Registration_err;?></span>
</div>
<div class="form-group">
<label>Expiration</label>
<input type="text" name="Expiration" class="form-control <?php echo (!empty($Expiration_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $Expiration; ?>">
<span class="invalid-feedback"><?php echo $Expiration_err;?></span>
</div>
<div class="form-group">
<label>NameServer1</label>
<input type="text" name="NameServer1" class="form-control <?php echo (!empty($NameServer1_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $NameServer1; ?>">
<span class="invalid-feedback"><?php echo $NameServer1_err;?></span>
</div>
<div class="form-group">
<label>NameServer2</label>
<input type="text" name="NameServer2" class="form-control <?php echo (!empty($NameServer2_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $NameServer2; ?>">
<span class="invalid-feedback"><?php echo $NameServer2_err;?></span>
</div>
<div class="form-group">
<label>Status</label>
<input type="text" name="Status" class="form-control <?php echo (!empty($Status_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $Status; ?>">
<span class="invalid-feedback"><?php echo $Status_err;?></span>
</div>
<div class="form-group">
<label>Notes</label>
<input type="text" name="Notes" class="form-control <?php echo (!empty($Notes_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $Notes; ?>">
<span class="invalid-feedback"><?php echo $Notes_err;?></span>
</div>
<input type="submit" class="btn btn-primary" value="Submit">
<a href="index.php" class="btn btn-secondary ml-2">Cancel</a>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
Yet I'm about 90% certain everything is coded how it should be (although I may have messed up with the validation rules perhaps?).

Everything in the config.php is 100% correct.

Can anyone see where the error above is and, if so, could you point me in the right direction to fixing it?
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-28-2022, 12:02 PM   #2
ZTT
Confirmed User
 
ZTT's Avatar
 
Industry Role:
Join Date: Apr 2019
Posts: 657
Can't help you, but I just remembered I'm out of bolognese.
__________________
__________________
ZTT is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-28-2022, 01:25 PM   #3
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,091
Quote:
$sql = "INSERT INTO DomainManagement (Registrar, DomainName, Registration, Expiration, NameServer1 NameServer2 Status Notes) VALUES (?, ?, ?, ?, ?, ?, ?)";

if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "sss", $param_Registrar, $param_DomainName, $param_Registration, $param_Expiration, $param_NameServer1, $param_NameServer2, $param_Status, $param_Notes);
1. In the $sql= statement you are missing commas between the last 4 filednames: NameServer1 NameServer2 Status Notes)

2. In the same statement you only list 7 parameters but in the bind you list 8 vars:
(?, ?, ?, ?, ?, ?, ?)
$param_Registrar, $param_DomainName, $param_Registration, $param_Expiration, $param_NameServer1, $param_NameServer2, $param_Status, $param_Notes


I did not look any further than that.

.
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-28-2022, 01:30 PM   #4
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,140
Quote:
Originally Posted by sarettah View Post
1. In the $sql= statement you are missing commas between the last 4 filednames: NameServer1 NameServer2 Status Notes)

2. In the same statement you only list 7 parameters but in the bind you list 8 vars:
(?, ?, ?, ?, ?, ?, ?)
$param_Registrar, $param_DomainName, $param_Registration, $param_Expiration, $param_NameServer1, $param_NameServer2, $param_Status, $param_Notes


I did not look any further than that.

.
Motherfuck, thank you.

Sorry I've been up 38 hours working so missing the basics, must be time to call it a night.

Thank you again for the help!
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-28-2022, 01:40 PM   #5
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,140
Sorry, one more question.

Do I need to add a bind param for the 'ID' column too in the SQL DB? Or becajse its set to auto increment will that be added to the table anyway?
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-28-2022, 01:54 PM   #6
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,091
Quote:
Originally Posted by Publisher Bucks View Post
Sorry, one more question.

Do I need to add a bind param for the 'ID' column too in the SQL DB? Or becajse its set to auto increment will that be added to the table anyway?
Nope, you are correct, it is autoincrement so you do not want to include it in your insert. Let the db do it's thing.

.
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-28-2022, 08:46 PM   #7
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,140
Meh :/

Now i'm having an issue with it not writing to the database, any suggestions on where the issue may lay?

It's not throwing any errors and appears to be working how it is supposed to, it's just not storing the data in SQL

Quote:
<?php
// Include config file
require_once "config.php";

// Define variables and initialize with empty values
$Registrar = $DomainName = $Registration = $Expiration = $NameServer1 = $NameServer2 = $Status = $Notes = "";
$Registrar = $DomainName_err = $Registration_err = $Expiration_err = $NameServer1_err = $NameServer2_err = $Status_err = $Notes_err = "";

// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){

// Validate registrar
$input_Registrar = trim($_POST["Registrar"]);
if(empty($input_Registrar)){
$Registrar_err = "Please enter Registrar.";
} else{
$Registrar = $input_Registrar;
}

// Validate domainname
$input_DomainName = trim($_POST["DomainName"]);
if(empty($input_DomainName)){
$DomainName_err = "Please enter DomainName.";
} else{
$DomainName = $input_DomainName;
}
// Validate registration
$input_Registration = trim($_POST["Registration"]);
if(empty($input_Registration)){
$Registration_err = "Please enter Registration Date.";
} else{
$Registration = $input_Registration;
}
// Validate expiration
$input_Expiration = trim($_POST["Expiration"]);
if(empty($input_Expiration)){
$Expiration_err = "Please enter Expiration Date.";
} else{
$Expiration = $input_Expiration;
}
// Validate nameserver1
$input_NameServer1 = trim($_POST["NameServer1"]);
if(empty($input_NameServer1)){
$NameServer1_err = "Please enter NS1.";
} else{
$NameServer1 = $input_NameServer1;
}
// Validate nameserver2
$input_NameServer2 = trim($_POST["NameServer2"]);
if(empty($input_NameServer2)){
$NameServer2_err = "Please enter NS2.";
} else{
$NameServer2 = $input_NameServer2;
}
// Validate status
$input_Status = trim($_POST["Status"]);
if(empty($input_Status)){
$Status_err = "Please enter Domain Status.";
} else{
$Status = $input_Status;
}
// Validate notes
$input_Notes = trim($_POST["Notes"]);
if(empty($input_Notes)){
$Notes_err = "Please enter Notes.";
} else{
$Notes = $input_Notes;
}

// Check input errors before inserting in database
if(empty($Registrar_err) && empty($DomainName_err) && empty($Registration_err) && empty($Expiration_err) && empty($NameServer1_err) && empty($NameServer2_err) && empty($Status_err) && empty($Notes_err)){
// Prepare an insert statement
$sql = "INSERT INTO DomainManagement (Registrar, DomainName, Registration, Expiration, NameServer1, NameServer2, Status, Notes) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";

if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "sss", $param_Registrar, $param_DomainName, $param_Registration, $param_Expiration, $param_NameServer1, $param_NameServer2, $param_Status, $param_Notes);

// Set parameters
$param_Registrar = $Registrar;
$param_DomainName = $DomainName;
$param_Registration = $Registration;
$param_Expiration = $Expiration;
$param_NameServer1 = $NameServer1;
$param_NameServer2 = $NameServer2;
$param_Status = $Status;
$param_Notes = $Notes;

// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Close statement
mysqli_stmt_close($stmt);
}
// Records created successfully. Redirect to landing page
header("location: index.php");
exit();
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}

// Close connection
mysqli_close($link);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<meta charset="UTF-8">
<title>Add New Domain Name | Admin Management System</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
.wrapper{
width: 600px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<h2 class="mt-5">Add New Domain Name</h2>
<p>Complete the form below to add a new domain name to the system.</p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">

<div class="form-group">
<label>Registrar</label>
<textarea name="Registrar" class="form-control <?php echo (!empty($Registrar_err)) ? 'is-invalid' : ''; ?>"><?php echo $Registrar; ?></textarea>
<span class="invalid-feedback"><?php echo $Registrar_err;?></span>
</div>
<div class="form-group">
<label>Domain Name</label>
<input type="text" name="DomainName" class="form-control <?php echo (!empty($DomainName_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $DomainName; ?>">
<span class="invalid-feedback"><?php echo $DomainName_err;?></span>
</div>
<div class="form-group">
<label>Reg Date</label>
<input type="text" name="Registration" class="form-control <?php echo (!empty($Registration_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $Registration; ?>">
<span class="invalid-feedback"><?php echo $Registration_err;?></span>
</div>
<div class="form-group">
<label>Exp Date</label>
<input type="text" name="Expiration" class="form-control <?php echo (!empty($Expiration_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $Expiration; ?>">
<span class="invalid-feedback"><?php echo $Expiration_err;?></span>
</div>
<div class="form-group">
<label>NS1 Record</label>
<input type="text" name="NameServer1" class="form-control <?php echo (!empty($NameServer1_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $NameServer1; ?>">
<span class="invalid-feedback"><?php echo $NameServer1_err;?></span>
</div>
<div class="form-group">
<label>NS2 Record</label>
<input type="text" name="NameServer2" class="form-control <?php echo (!empty($NameServer2_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $NameServer2; ?>">
<span class="invalid-feedback"><?php echo $NameServer2_err;?></span>
</div>
<div class="form-group">
<label>Domain Status</label>
<input type="text" name="Status" class="form-control <?php echo (!empty($Status_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $Status; ?>">
<span class="invalid-feedback"><?php echo $Status_err;?></span>
</div>
<div class="form-group">
<label>Notes</label>
<input type="text" name="Notes" class="form-control <?php echo (!empty($Notes_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $Notes; ?>">
<span class="invalid-feedback"><?php echo $Notes_err;?></span>
</div>
<input type="submit" class="btn btn-primary" value="Submit">
<a href="index.php" class="btn btn-secondary ml-2">Cancel</a>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-29-2022, 03:17 AM   #8
zerovic
Confirmed User
 
zerovic's Avatar
 
Industry Role:
Join Date: Apr 2010
Posts: 1,097
If it's a simple insert query why do you have to use mysqli_prepare, mysqli_stmt_bind_param, mysqli_stmt_execute etc? I prefer using mysqli_query when inserting simple data to db..
zerovic is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-29-2022, 04:27 AM   #9
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,140
Quote:
Originally Posted by zerovic View Post
If it's a simple insert query why do you have to use mysqli_prepare, mysqli_stmt_bind_param, mysqli_stmt_execute etc? I prefer using mysqli_query when inserting simple data to db..
Because eventually, this will be used across multiple machines (with multiple IPs) so I'd rather screw about with security issues now while its still relatively small, than have to deal with rewriting it at a later date to fix any potential security issues (while I'm still learning to code).

This is just my test project, the ultimate use for this will be to allow multiple employees to add data to a larger database that controls a multitude of content based websites from a central admin management system.
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-29-2022, 07:12 AM   #10
celandina
Too lazy to set a custom title
 
Industry Role:
Join Date: Jun 2006
Posts: 11,408
Quote:
Originally Posted by sarettah View Post
1. In the $sql= statement you are missing commas between the last 4 filednames: NameServer1 NameServer2 Status Notes)

2. In the same statement you only list 7 parameters but in the bind you list 8 vars:
(?, ?, ?, ?, ?, ?, ?)
$param_Registrar, $param_DomainName, $param_Registration, $param_Expiration, $param_NameServer1, $param_NameServer2, $param_Status, $param_Notes


I did not look any further than that.

.
You are fucking genius
celandina is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-29-2022, 07:38 AM   #11
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,091
It looks to me like you have your ifs screwed up:

You have:
Quote:
if($stmt = mysqli_prepare($link, $sql))
{
// Bind variables to the prepared statement as parameters

// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt))
{
// Close statement
mysqli_stmt_close($stmt);
}
// Records created successfully. Redirect to landing page
header("location: index.php");
exit();
}
else
{
echo "Oops! Something went wrong. Please try again later.";
}
You hit the redirect whether the insert worked properly or not. Your errror message is only if the prepare did not work.

Using what you have you would need something more like:

if($stmt = mysqli_prepare($link, $sql))
{
// Bind variables to the prepared statement as parameters

// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt))
{
// Close statement
mysqli_stmt_close($stmt);
// Records created successfully. Redirect to landing page
header("location: index.php");
exit();
}
else
{
echo 'insert failed....';
}
}
else
{
echo "prepare failed";
}

I don't know that that is the only issue.

.
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
create, record, domain, form, database, add, error, highlighting, [quote], fields, margin, fill, submit, auto;, width, 600px;, .wrapper, simple, managament, page, telling, wrong



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.