Using php form to submit to mysql database with mysqli [duplicate]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0
















This question already has an answer here:




  • When to use single quotes, double quotes, and back ticks in MySQL

    12 answers



  • How to get MySQLi error information in different environments

    1 answer



  • How can I prevent SQL injection in PHP?

    28 answers




I am just fooling around with some sample web pages as I haven't touched form to database submissions for some time and I've noticed mysql_* is no longer widely used and has been replaced with mysqli_*. I have what I believe to be a simple form(can post if needed but I don't think the problem lies within the form). My connection code for the database is as follows,



<?php 
//addslash() for sanitization
ExtendedAddslash($_POST);

//correct form name's for data to be inserted
$name = $_POST['name'];
$specName = $_POST['specName'];
$weight = $_POST['weight'];
$weightUnits = $_POST['weight-units'];
$description = $_POST['description'];

$conn = mysqli_connect("localhost","root","CENSORED","testDB");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL :" . mysqli_conect_error();
}
else {
echo "Connection was OK!n";
}

$result = mysqli_query($conn,"INSERT into 'testDB.users' (name, specName, description, weight, weightUnits) VALUES ('$name','$specName','$description', '$weight', '$weightUnits')");
if ($result) {
echo "Successn";
}
else {
echo "Errorn";
}

mysqli_close($conn);
?>


In the past this worked out pretty straight forward but I have changed some of the syntax to match mysqli standards. The connection test always results in "Connection was OK" however I always seem to get the "Error". Is the problem the $result variable? or am I just not executing this query properly.










share|improve this question













marked as duplicate by mario php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 21:20


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Please leave a comment wherever you found that ExtendedAddSlashes() code.

    – mario
    Nov 24 '18 at 21:28


















0
















This question already has an answer here:




  • When to use single quotes, double quotes, and back ticks in MySQL

    12 answers



  • How to get MySQLi error information in different environments

    1 answer



  • How can I prevent SQL injection in PHP?

    28 answers




I am just fooling around with some sample web pages as I haven't touched form to database submissions for some time and I've noticed mysql_* is no longer widely used and has been replaced with mysqli_*. I have what I believe to be a simple form(can post if needed but I don't think the problem lies within the form). My connection code for the database is as follows,



<?php 
//addslash() for sanitization
ExtendedAddslash($_POST);

//correct form name's for data to be inserted
$name = $_POST['name'];
$specName = $_POST['specName'];
$weight = $_POST['weight'];
$weightUnits = $_POST['weight-units'];
$description = $_POST['description'];

$conn = mysqli_connect("localhost","root","CENSORED","testDB");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL :" . mysqli_conect_error();
}
else {
echo "Connection was OK!n";
}

$result = mysqli_query($conn,"INSERT into 'testDB.users' (name, specName, description, weight, weightUnits) VALUES ('$name','$specName','$description', '$weight', '$weightUnits')");
if ($result) {
echo "Successn";
}
else {
echo "Errorn";
}

mysqli_close($conn);
?>


In the past this worked out pretty straight forward but I have changed some of the syntax to match mysqli standards. The connection test always results in "Connection was OK" however I always seem to get the "Error". Is the problem the $result variable? or am I just not executing this query properly.










share|improve this question













marked as duplicate by mario php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 21:20


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Please leave a comment wherever you found that ExtendedAddSlashes() code.

    – mario
    Nov 24 '18 at 21:28














0












0








0









This question already has an answer here:




  • When to use single quotes, double quotes, and back ticks in MySQL

    12 answers



  • How to get MySQLi error information in different environments

    1 answer



  • How can I prevent SQL injection in PHP?

    28 answers




I am just fooling around with some sample web pages as I haven't touched form to database submissions for some time and I've noticed mysql_* is no longer widely used and has been replaced with mysqli_*. I have what I believe to be a simple form(can post if needed but I don't think the problem lies within the form). My connection code for the database is as follows,



<?php 
//addslash() for sanitization
ExtendedAddslash($_POST);

//correct form name's for data to be inserted
$name = $_POST['name'];
$specName = $_POST['specName'];
$weight = $_POST['weight'];
$weightUnits = $_POST['weight-units'];
$description = $_POST['description'];

$conn = mysqli_connect("localhost","root","CENSORED","testDB");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL :" . mysqli_conect_error();
}
else {
echo "Connection was OK!n";
}

$result = mysqli_query($conn,"INSERT into 'testDB.users' (name, specName, description, weight, weightUnits) VALUES ('$name','$specName','$description', '$weight', '$weightUnits')");
if ($result) {
echo "Successn";
}
else {
echo "Errorn";
}

mysqli_close($conn);
?>


In the past this worked out pretty straight forward but I have changed some of the syntax to match mysqli standards. The connection test always results in "Connection was OK" however I always seem to get the "Error". Is the problem the $result variable? or am I just not executing this query properly.










share|improve this question















This question already has an answer here:




  • When to use single quotes, double quotes, and back ticks in MySQL

    12 answers



  • How to get MySQLi error information in different environments

    1 answer



  • How can I prevent SQL injection in PHP?

    28 answers




I am just fooling around with some sample web pages as I haven't touched form to database submissions for some time and I've noticed mysql_* is no longer widely used and has been replaced with mysqli_*. I have what I believe to be a simple form(can post if needed but I don't think the problem lies within the form). My connection code for the database is as follows,



<?php 
//addslash() for sanitization
ExtendedAddslash($_POST);

//correct form name's for data to be inserted
$name = $_POST['name'];
$specName = $_POST['specName'];
$weight = $_POST['weight'];
$weightUnits = $_POST['weight-units'];
$description = $_POST['description'];

$conn = mysqli_connect("localhost","root","CENSORED","testDB");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL :" . mysqli_conect_error();
}
else {
echo "Connection was OK!n";
}

$result = mysqli_query($conn,"INSERT into 'testDB.users' (name, specName, description, weight, weightUnits) VALUES ('$name','$specName','$description', '$weight', '$weightUnits')");
if ($result) {
echo "Successn";
}
else {
echo "Errorn";
}

mysqli_close($conn);
?>


In the past this worked out pretty straight forward but I have changed some of the syntax to match mysqli standards. The connection test always results in "Connection was OK" however I always seem to get the "Error". Is the problem the $result variable? or am I just not executing this query properly.





This question already has an answer here:




  • When to use single quotes, double quotes, and back ticks in MySQL

    12 answers



  • How to get MySQLi error information in different environments

    1 answer



  • How can I prevent SQL injection in PHP?

    28 answers








php mysqli






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 21:16









MikelMikel

488




488




marked as duplicate by mario php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 21:20


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by mario php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 21:20


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Please leave a comment wherever you found that ExtendedAddSlashes() code.

    – mario
    Nov 24 '18 at 21:28



















  • Please leave a comment wherever you found that ExtendedAddSlashes() code.

    – mario
    Nov 24 '18 at 21:28

















Please leave a comment wherever you found that ExtendedAddSlashes() code.

– mario
Nov 24 '18 at 21:28





Please leave a comment wherever you found that ExtendedAddSlashes() code.

– mario
Nov 24 '18 at 21:28












0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

這個網誌中的熱門文章

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Xamarin.form Move up view when keyboard appear

JBPM : POST request for execute process go wrong