Page 1 of 1

First ever PHP/MySQL script not working.

Posted: Fri Dec 05, 2008 3:27 am
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.

Re: First every PHP/MySQL script not working.

Posted: Fri Dec 05, 2008 5:01 am
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

Re: First every PHP/MySQL script not working.

Posted: Fri Dec 05, 2008 5:15 am
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...