-1

New to php and am connecting form attributes to php to connect to a godaddy mysql. Every attempt ends in a blank screen with no error messages. Is there any syntax errors the jump out? My sublime text wont register php syntax, but thats another problem for another time. I may need to call up godaddy support? the password has been removed for privacy.

<?php

$servername = "localhost";
$dbusername = "jaysenhenderson";
$dbpassword = "xxxxx";
$dbname = "EOTDSurvey";


$con = new mysqli ($servername, $dbusername, $dbpassword, $dbname);
mysql_select_db('EOTDSurvey', $con)

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo("Connected successfully");


$_POST['BI1']
$_POST['BI2']
$_POST['BI3']
$_POST['BI4']
$_POST['BI5']
$_POST['BI6']
$_POST['BI7']
$_POST['BI8']
$_POST['BI9']
$_POST['BI10']
$_POST['BI11']
$_POST['BI12']
$_POST['BI13']
$_POST['BI14']
$_POST['BI15']

$sql = "INSERT INTO Survey1(BI1)"
$sql = "INSERT INTO Survey1(BI2)"
$sql = "INSERT INTO Survey1(BI3)"
$sql = "INSERT INTO Survey1(BI4)"
$sql = "INSERT INTO Survey1(BI5)"
$sql = "INSERT INTO Survey1(BI6)"
$sql = "INSERT INTO Survey1(BI7)"
$sql = "INSERT INTO Survey1(BI8)"
$sql = "INSERT INTO Survey1(BI9)"
$sql = "INSERT INTO Survey1(BI10)"
$sql = "INSERT INTO Survey1(BI11)"
$sql = "INSERT INTO Survey1(BI12)"
$sql = "INSERT INTO Survey1(BI13)"
$sql = "INSERT INTO Survey1(BI14)"
$sql = "INSERT INTO Survey1(BI15)"

if ($conn->query<$sql) === TRUE) {
    echo "IT FUCKING WORKS.";
}
else{
    echo "didnt workkkkkk";
}
$conn->close();

 ?>
jaysen769
  • 11
  • 2

3 Answers3

0

please connect database like this...

$connection = mysqli_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
die("Database connection failed: " . mysqli_error());
}

// 2. Select a database to use 
$db_select = mysqli_select_db($connection, DB_NAME);
if (!$db_select) {
die("Database selection failed: " . mysqli_error());
}

And Use mysqli_select_db instead of mysql_select_db And insert semi-colon (;) after every line end according to php code standard.

akdesigner
  • 31
  • 6
0

There are a lot of issues with this code, as mentioned the mysqli_select_db issue. The $_POST['BIx'] will also cause errors because there is no semi-colon after each statement. You're missing a '(' on the line if ($conn->query<$sql) === TRUE) { not to mention that line will not work anyway because you're logically comparing a resource type (I think) to a string.

You're also never executing the insert statements. All around I seriously think you should practice PHP coding some more and read up on how to use mysqli properly: see here.

Regards

EDIT: You also have a closing PHP tag at the end of your script which is generally not a good idea as explained here

EDIT 2: Also using an IDE such as Netbeans is always a good idea as it can highlight syntax errors instead of asking SO to do it for you ;)

Community
  • 1
  • 1
Adam
  • 88
  • 6
0
<?php

$servername = "localhost";
$dbusername = "jaysenhenderson";
$dbpassword = "xxxxx";
$dbname = "EOTDSurvey";


$con = new mysqli ($servername, $dbusername, $dbpassword, $dbname);
mysqli_select_db('EOTDSurvey', $con);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo("Connected successfully");


############# Function For Insert ##############


function insert($tableName='',$data=array())
  {
    $query = "INSERT INTO `$tableName` SET";
    $subQuery = '';
    foreach ($data as $columnName => $colValue) {
      $subQuery .= " `$columnName`='$colValue',";
    }
    $subQuery = rtrim($subQuery,', ');
    $query .= $subQuery;
    pr($query);
    mysqli_query($con,$query) or die(mysqli_error());
    return mysqli_insert_id();
  }//end insert

#########################################  
if(isset($_POST['submit'])){
    unset($_POST['submit']);
    //print_r($_POST);
    $result=insert('Survey1',$_POST);

if($result){

 echo '<script>window.alert("Success!");</script>';
 echo "<script>window.location.href = 'yourpage.php'</script>";
}   
}

$conn->close();

 ?>
Divakarcool
  • 473
  • 6
  • 20