-2

Here is the code:

<?php
$con=mysql_connect('localhost', 'itorras', 'passwordhere');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


mysql_select_db( "my_db" ) or die( 'Error'. mysql_error() );

$sql="INSERT INTO Brackets(have things here)
VALUES(and here)";

if (!mysqli_query($con,$sql))
  {
  die('Error with adding row: ' . mysqli_error($con));
  }
echo "Thank you, your bracket has been submited.";
echo "<a href='index.html'>Click here to go back to home page</a>";

 ?>

I am using the username and password that is given the rights to mess with the database. So when i try to submit something into the file none of the top errors run but then the bottom error prints error with adding row and nothing more. This file worked fine on my local server but has not worked on the web host. I am using godaddyweb hosting, so phpmyadmin and cpanelx. If you need any more info let me know. Have been at this for a couple hours.

itorras
  • 3
  • 1
  • 3
  • 1
    There is **no more support** for `mysql_*` functions, they are [**officially deprecated**](https://wiki.php.net/rfc/mysql_deprecation), **no longer maintained** and will be [**removed**](http://php.net/manual/en/function.mysql-connect.php#warning) in the future. You should update your code with [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) to ensure the functionality of your project in the future. – Amal Murali Mar 31 '14 at 16:30
  • 2
    You seem to be mixing both `mysql_*` and `mysqli_*` functions here. **Just use `mysqli_*`** (preferably with [prepared statements](http://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php)). Also, [enable error reporting](http://stackoverflow.com/a/6575502/1438393) to get useful error messages during development. – Amal Murali Mar 31 '14 at 16:32
  • This question appears to be off-topic because it is about mixing MySQL functions – Funk Forty Niner Mar 31 '14 at 16:34
  • $con=mysqli_connect('localhost', 'itorras', 'password','my_db'); if (!$con) { die('Could not connect: ' . mysqli_error()); } Thats what i changed it to and then the other mysqls to mysqlis an d it worked! thanks – itorras Mar 31 '14 at 17:01

2 Answers2

3

You are using mysql_connect but mysqli_query. You are mixing mysql and mysqli. Use only mysqli_*.

Halcyon
  • 57,230
  • 10
  • 89
  • 128
0

It appears you are using two different libraires at the same time

The original mysql API is deprecated for various reasons and you should not use it in new code

Instead, use PDO or mysqli

In your code, you are using the original mysql for the db connect, and then you use mysqli for the query. Instead you should only use mysqli

Replace the following code :

$con=mysql_connect('localhost', 'itorras', 'passwordhere');
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}

With :

$db = new mysqli('localhost', 'user', 'pass', 'demo');

if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}

Then you can query the database with something similar :

$sql = <<<SQL
    SELECT *
    FROM `users`
    WHERE `live` = 1 
SQL;

if(!$result = $db->query($sql)){
     die('There was an error running the query [' . $db->error . ']');
 }

For a complete overview, you can take a look at the documentation

http://ca2.php.net/mysqli