Click here to Skip to main content
15,894,262 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
When running mysql queries in php, they seem to fail if they create tables or insert data into tables. Mysql_error does not display anything, and i have checked the connection. If i copy-paste the query into phpmyadmin, it works. I am logging in with the same user as in the php scropt. Is it a setting i have to change?
Posted
Comments
Kreagan Naicker 30-Jan-12 16:29pm    
Hi.

A code snippet of what you are doing would certainly help.
At the moment, i can't tell if you have a setting problem or if you have a query / syntax problem.

Have you displayed the query string as an output?
Are you using the outputted query string in your execution in PHPMyAdmin or are you simply re-typing the query?
Member 8607653 31-Jan-12 0:54am    
Updating - please wait

Hi, logged in from another pc, so name is different. But here is the code snippet(Cannot edit?)

PHP
$continue = 1;
			echo "Checking details:<br />";
			echo "Connect to " . $_POST["host"] . "... ";
			$connection = mysql_connect($_POST["host"], $_POST["username"], $_POST["pass"]);
			if($connection)
			{
				echo '<font color="00ff00">sucess!</font><br />';
			}
			else
			{
				echo '<font color="ff0000">fail!</font><br />';
				$continue = 0;
			}
			echo "Select Database " . $_POST["db"] . "... ";
			$db = mysql_select_db($_POST["db"], $connection);
			if($db)
			{
				echo '<font color="00ff00">sucess!</font><br />';
			}
			else
			{
				if($continue == 0)
				{
					echo '<font color="ff0000">fail(Because connect failed)!</font><br />';
				}
				else
				{
					echo '<font color="ff0000">fail!</font><br />';
				}
				$continue = 0;
			}
			if($continue == 0)
			{
				echo '<br /><font color="ff0000">Installation failed. Please fix the problems and do the setup again</font>';
			}
			else
			{
				echo "<br /><br />Installing playr:<br />";
				echo "Setting up MySql database:<br />";
				echo "..." . $_POST["prefix"] . "songs... ";
				$name = $_POST["prefix"] . "songs";
				$sql = "CREATE TABLE Persons
				(
				FirstName varchar(15),
				LastName varchar(15),
				Age int
				);";
				if(mysql_result($query, $connection))
				{
					echo '<font color="00ff00">Sucess!</font>';
				}
				else
				{
					echo '<font color="ff0000">Failed!</font>';
					mysql_error();
					$continue = 0;
				}
				//Last check
				if($continue == 0)
				{
					echo '<br /><br /><font color="ff0000">Installation failed. Please fix the problems and do the setup again</font>';
				}
			}
 
Share this answer
 
Hi Liam

Check the lines of code below, i believe this is where you issue lies.

$sql = "CREATE TABLE Persons(FirstName varchar(15), LastName varchar(15), Age int);";

if(mysql_result($query, $connection))

The line above (in bold) is the problem, you are executing the variable $query, yet you assign your SQL statement to the variable $sql.

Change the code to the following:

if(mysql_result($sql, $connection))

Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900