FINALLY SEEKING HELP

Pinkponyprincess
11 years ago

0

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.

8replies
4voices
225views
Luke [flabbyrabbit]
11 years ago

0

You have errors in your SQL … spelling of values for instance.

Luke [flabbyrabbit]
11 years ago

0

Replacing “did not work3” with mysqli_error() will tell you what is going wrong.

Pinkponyprincess
11 years ago

0

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 :) .

daMage
11 years ago

0

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 :)

gudgip
11 years ago | edited 11 years ago

0

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

daMage
11 years ago

0

[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’]);
```

Pinkponyprincess
11 years ago

0

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 .

gudgip
11 years ago | edited 11 years ago

0

Yes. You are right. Still, I’d go with pdo. ;-)

@damage: yep. It’s pitty to see people avoiding prepared statements. Ah well, we won’t be workless!

You must be logged in to reply to this discussion. Login
1 of 9

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss