I am getting this error. This is my code

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /studhome/0/1104107/public_html/mysql_connect.php on line 33

I HAVE NO IDEA WHAT I AM MISSING!!!!!!!!!!!

<?php
$hostname = "localhost"; 
$username = "1104107";
$password = "r940c1";
$database = "db1104107";
//echo '24';

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password);
$db = mysql_select_db($database, $dbhandle)
  or die("Unable to connect to MySQL");
//echo "Connected to MySQL<br>";

$query_createTemporaryTable = "CREATE TEMPORARY TABLE temp(temp_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 
                                                           ArtistName VARCHAR(20), NAME of the DVD VARCHAR(30)"; 

$result_createtemptable = mysql_query($query_createTemporaryTable ,$dbhandle );

$query_insertintotable = "INSERT INTO everything (ArtistName, NAME of the DVD) VALUES ('RIHANNA', 'SHAWSHANK')";

$result_insertintotable = mysql_query($query_insertintotable ,$dbhandle);

$query_selecttemptable = "SELECT ArtistName,NAME of the DVD FROM temp";

$result_selecttemptable = mysql_query( $query_selecttemptable,$dbhandle);

$row_selecttemptable = mysql_fetch_array($result_selecttemptable, $dbhandle);

while($row_selecttemptable = mysql_fetch_array($result_selecttemptable, $dbhandle)){
      echo $row_selecttemptable
      or die mysql_error("Error");
  }


?>

Recommended Answers

All 17 Replies

I did not understand you.

@Mohamed don't worry about her, she's a spammer.

Regarding your problem, try to change this:

$result_selecttemptable = mysql_query( $query_selecttemptable,$dbhandle);
$row_selecttemptable = mysql_fetch_array($result_selecttemptable, $dbhandle);
while($row_selecttemptable = mysql_fetch_array($result_selecttemptable, $dbhandle)){
      echo $row_selecttemptable
      or die mysql_error("Error");
  }

To:

$result_selecttemptable = mysql_query($query_selecttemptable,$dbhandle) or die(mysql_error());

while($row_selecttemptable = mysql_fetch_array($result_selecttemptable))
{
    echo $row_selecttemptable['ArtistName'];
}

Hello, can you help me with my problem?

Oh Thanks. I shall flag her comments

Yes, try the suggestions in my previous post and let us know the results.

Edit

Hmm looking better at your code, I doubt that this would work:

"SELECT ArtistName,NAME of the DVD FROM temp";

Can you show us the structure of this table? Run explain temp; from a MySQL table and paste here the result.

Yes, I changed it. But, i am getting a different error now :
Parse error: syntax error, unexpected T_LOGICAL_OR in /studhome/0/1104107/public_html/mysql_connect.php

I am getting a error on this line "$result_selecttemptable = mysql_query( $query_selecttemptable,$dbhandle); or die"

$result_selecttemptable = mysql_query( $query_selecttemptable,$dbhandle); or die
mysql_error("error");

Without the semi-colon at the end of mysql_query():

$result_selecttemptable = mysql_query($query_selecttemptable, $dbhandle) or die(mysql_error());

And with die(mysql_error()) which is more useful because it will display the actual error or the query.

My SQL tables are on the PhpMyAdmin. Should I run the "explain.temp" there?

Yes, without the dot, just explain temp;

It just says

SQL query:

EXPLAIN temp

MySQL said: Documentation

1146 - Table 'db1104107.temp' doesn't exist

Does that mean I am supposed to create a table called temp on PhpMyAdmin?

Yes, create the table with the columns you need and then post the result of the explain command here, or just post the create statement. After that we can fix your queries.

Ok, Now the code works. But I am getting a error message. I dont think i am creating the table correctly.

Table 'db1104107.temp' doesn't exist.

By the way, thank you for all your help.

SQL query:
EXPLAIN temp;

Field Type Null Key Default Extra
Temp ID varchar(7) NO PRI NULL
ArtistName varchar(20) NO NULL
NAMEOfTheDVD varchar(30) NO NULL

Also the name of a column cannot contain whitespace, use underscores instead, so Name of the DVD becomes name_of_the_dvd. That's probably why your temporary table does not work, you can change the first query to:

$query_createTemporaryTable = "CREATE TEMPORARY TABLE temp(temp_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, ArtistName VARCHAR(20), name_of_the_dvd VARCHAR(30))"; 
$result_createtemptable = mysql_query($query_createTemporaryTable , $dbhandle) or die(mysql_error());

yh, that "Name of the DVD" was causiing me problems. I changed that and now it works.

Just out of curiousity, can we not create Tables using PHP code? I had to create the table in PhpMyAdmin. I just thought that you can create tables using PHP.

Thank you again for all your help.

YOUR TRULY AWESOME!!!!!!!

Ok, if you still want to create a temporary table, use my suggestion, change your code, then modify the insert query to:

$query_insertintotable = "INSERT INTO everything (ArtistName, NAMEoftheDVD) VALUES ('RIHANNA', 'SHAWSHANK')";
$result_insertintotable = mysql_query($query_insertintotable, $dbhandle) or die(mysql_error());

Where NAME of the DVD is NAMEoftheDVD or name_of_the_dvd as in my example.

Note that the temporary table will be deleted at the end of the script.

OK, its done. It works perfectly.

Thank You.

I am going to mark this as resolved

can we not create Tables using PHP code?

Yes, it is possible, but you need a persistent connection otherwise create this table with another engine, you could use the memory engine for example, it should work fine because is deleted when the server is reloaded or when you drop the table.

Also, you should move to MySQLi or PDO, the MySQL library is going to be removed from PHP.

I'm glad it's fine, bye! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.