0
votes

I'm having trouble getting my code to connect to my sql. I am creating in aptana with a wamp stack. When running, the web page only displays:

cannot connect to DB: mysql_error(). " ); mysql_select_db ("q4u!") or die ("cannot select db"); echo " Connected!

"; $INSERT_sql = "insert into customer (cust_Fname, cust_Lname, cust_Phone, cust_alt_phone, cust_Email, cust_notification_preference) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[phonenumber]','$_POST[altphone]','$_POST[emailaddress]','$_POST[notipref]')"; mysql_query($INSERT_sql); ?>

my code looks like

    <?php 
    mysql_connect("localhost:3306", "root", "") or die ("<p>cannot connect to DB: mysql_error().</p>" );
    mysql_select_db ("q4u!") or die ("cannot select db");

    echo "<p>Connected!</p>";


    $INSERT_sql = "insert into customer (cust_Fname, cust_Lname, cust_Phone, cust_alt_phone, cust_Email, cust_notification_preference)
    VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[phonenumber]','$_POST[altphone]','$_POST[emailaddress]','$_POST[notipref]')";


    mysql_query($INSERT_sql);  
?>
2

2 Answers

1
votes

PHP is not installed or the file extension is not .php

1
votes

Try this $db = mysqli_connect('localhost:3306','root',''); do not include the mysql_select_db anymore.