-1

I am having a very weird problem with PHP while trying to send a query to MYSQL. Here is my code

$newlogforuser="CREATE TABLE ".$username."-log (date CHAR(30),time CHAR(30),ipaddress CHAR(30))";

// Execute query
if (mysql_query($conl,$newlogforuser))
{
  echo "Response from server: Log created successfully";
}
else
{
  echo "Response from server: Error creating log: " . mysql_error();
}

The Error: Warning: mysql_query() expects parameter 1 to be string

I know that I am successfully connected to my MYSQL database, so that is not an issue. I know that there are many posts about the same issue on StackOverflow, but one of them fix my problem. Please help!

Shadowpat
  • 3,577
  • 2
  • 14
  • 14
  • 3
    Please **don't use `mysql_*` functions in new code** ([why?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)), they are [deprecated](https://wiki.php.net/rfc/mysql_deprecation). Use [PDO or MySQLi](http://php.net/manual/en/mysqlinfo.api.choosing.php) instead – kero Mar 26 '13 at 20:02
  • Yeah, i know, i just haven't had time to change it yet – Shadowpat Mar 26 '13 at 20:05
  • mysql_query($newlogforuser, $conl) – tuffkid Mar 26 '13 at 20:05

3 Answers3

1

mysql_query expects the first parameter to be string. The resource has to be the second parameter

kero
  • 10,647
  • 5
  • 41
  • 51
0

just use mysql_query($query), use mysql_connect for connecting to your db. where $query = $newlogforuser here's mysql_query manual

pedro cepeda
  • 41
  • 1
  • 6
0

Try this code It will help you... Take Table name separatly as variable and put variable in mysql query

<?php
     $con= mysql_connect("your host","username","password");
     $db=mysql_select_db("Your database");
    $tableName = $username."-log";
    $newlogforuser="CREATE TABLE '".$tableName."'(date CHAR(30),time CHAR(30),ipaddress CHAR(30))";
$sqlst=mysql_query($con,$newlogforuser);
    if($sqlst)
    { 
    echo "Response from server: Log created successfully";} 
    else { echo "Response from server: Error creating log: " . mysql_error(); 
    }
    ?>