FINALLY SEEKING HELP
Ok, ive been programming in php for a while now , but i cant seem to get databases in my head , please give me some advice, i have watched countless youtube videos and read countless articles , ive googled for hours , seems like such a stupid question and stupid problem, the best help ive gotten is from php.net .
This is what i have: <?php
$database=mysqli_connect('localhost','root','','database') or die('did not work1');
$query="INSERT INTO table(name,surname,email,password) VALLUES('This_is_a_NAME','This_is_a_surname','email@internet.com','password123')" or die("did not work2");
$result=$database->query($query)or die("did not work3");
?>
before i added die() , i got no error messages, but the data wasn’t saved ,at the moment this gives me a “did not work3”;
Please any help will be appreciated.
Thank you flabbyrabbit, i misspelled vallues because i retyped this so many times i didnt even check when i posted xD , it didn’t solve my problem, what did solve it was mysqli_error() .<?php
$database=mysqli_connect('localhost','root','','database') or die('did not work1');
$query="INSERT INTO `database`.`table` (
`name` ,
`surname` ,
`email` ,
`password`
)
VALUES (
'jena', 'one', 'int@mail.com', 'pass111'
);";
$database->query($query)or die(mysqli_error($database));
?>
I wanted to get the php and my mysql to work before i started with my new book , a Guide to SQL by Pratt Last. Thank you i think i am going to enjoy it :) .
Yea, well database is not a good name for a database and table isn’t a good name for a table (imho). Both of those have special meanings and you have to use backticks with them, if you choose them… But I’m sure you know all that now :)
- daMage
Use pdo and all your problems are solved. Mysql_connect will soon be deprecated. Pdo is the save, oop way to connect to virtually any db. http://php.net/manual/en/book.pdo.php
[quote=gudgip]Pdo is the save, oop way[/quote]
assuming s/v/f
anyhow.. That’s not entirely true, people can (and I’m sure will) fuck it up with PDO::exec and PDO::query, for example:
```
// $conn is the pdo object:
$foobar = $conn->query(“select * from users where id = ‘” . $_GET['id’] . “‘”);
$rows = $conn->exec(‘update users set password = ’“ . $POST[‘password’] . ”‘ where id = “ . $POST['id’]);
```
- daMage
Just to be clear gudgip (not sure if i am being an idiot here), i didn’t use mysql_connect, i used mysqli_connect, mysql_connect has been deprecated since PHP 5.5.0. But i am going to read up on pdo for sure .