You are viewing our Forum Archives. To view or take place in current topics click here.
This doesn't post but but doesn't give a error message help?
Posted:
This doesn't post but but doesn't give a error message help?Posted:
Status: Offline
Joined: Dec 28, 201310Year Member
Posts: 85
Reputation Power: 3
Status: Offline
Joined: Dec 28, 201310Year Member
Posts: 85
Reputation Power: 3
heres my code it doesn't post and it doesn't give me a error message
any ideas
<?php
$mysqli = new mysqli("localhost", "root", "", "bbm");
$name = $_POST['Name'];
$pin = $_POST['pin'];
$Gender = $_POST['Gender'];
$sql = "INSERT INTO `pins` (`id`, `Name`, `Date`, `pin`, `gender`) VALUES (NULL, $name, null, $pin, $Gender);";
?>
#2. Posted:
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83
Well why would it do anything? all you've done is declared and assigned a couple of variables. I see nowhere in that script where you have actually executed the query.
There are a lot of points to note here though:
- Set the id as a primary key with an auto increment attribute, this way you don't even have to worry about the id field on inserts.
- Always, always use binded parameters or there is no point even using mysqli in the first place, this pretty much means all your parameters ($_POST['Name'] etc..) are not passed as part of the mysql query.
- Don't insert null values, just don't insert any at all for those columns and have their default value set to empty, 0 etc.. (for time-stamps you can set default for current date-time)
- For gender it's more appropriate to use either enums or a seperate table linked with a foreign key.
From all this it's safe to say you need to learn the very basics. When you're more competent with php then you could move into integration with databases.
There are a lot of points to note here though:
- Set the id as a primary key with an auto increment attribute, this way you don't even have to worry about the id field on inserts.
- Always, always use binded parameters or there is no point even using mysqli in the first place, this pretty much means all your parameters ($_POST['Name'] etc..) are not passed as part of the mysql query.
- Don't insert null values, just don't insert any at all for those columns and have their default value set to empty, 0 etc.. (for time-stamps you can set default for current date-time)
- For gender it's more appropriate to use either enums or a seperate table linked with a foreign key.
From all this it's safe to say you need to learn the very basics. When you're more competent with php then you could move into integration with databases.
<?php
$mysqli = new mysqli("localhost", "root", "", "bbm");
$Name = $_POST['Name'];
$Pin = $_POST['pin'];
$Gender = $_POST['Gender'];
if($stmt = $mysqli->prepare("INSERT INTO `pins` (`Name`,`pin`,`gender`) VALUES (?,?,?)")){
$stmt->bind_param('sis',$Name,$pin,$Pin);
$stmt->execute();
$stmt->close();
}else{
echo 'failed to execute query';
}
?>
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.