First ever PHP/MySQL script not working.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
spvn
Forum Newbie
Posts: 2
Joined: Fri Dec 05, 2008 3:24 am

First ever PHP/MySQL script not working.

Post by spvn »

Hi everyone, I just started learning php like last week and tried typing out my first ever piece of code involving MySQL (I've done HTML before) and though it's such a simple code, I can't seem to find the problem. I've already included all the error reporting stuff but when I try to run this piece of code nothing comes up and nothing appears in my MySQL databases when I try the SELECT query.

Code: Select all

<html>
<body>
<?php
    error_reporting(E_ALL);
    $host = "localhost";
    $user = "root";
    $password = "password";
    $db = "test";
    $cxn = mysqli_connect($host,$user,$password,$db) or die(mysql_error());
    $sql = "insert into posts (Title,Content) values ("test","test")";
    $result = mysqli_query($cxn,$sql) or die(mysql_error());
    var_dump($result);
?>
</body>
</html>
    
   
I'm sorry to bother everyone with such simple code, but I've been fretting over nothing but this for the past few hours and really need someone to advise me.

Thanks in advance.
Last edited by spvn on Fri Dec 05, 2008 10:03 am, edited 1 time in total.
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: First every PHP/MySQL script not working.

Post by pbs »

You want to use SELECT or INSERT query?. You mentioned SELECT query and you have used INSERT query in the code. And try to use mysql_query(), mysql_connect() etc
spvn
Forum Newbie
Posts: 2
Joined: Fri Dec 05, 2008 3:24 am

Re: First every PHP/MySQL script not working.

Post by spvn »

I want to use INSERT in the quote. I mean when I check my MySQL database with the "SELECT * from tablename" query it gives me a blank table.

I thought mysqli was a better version of mysql_connect() etc? And I do have the required versions of software to run it...
Post Reply