Stuck on Couldn't execute query error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi:

I am working on a computer with RedHat Linux 7.2
I am running Apache web server and MySQL and Netscape browser
I am working local as the root

I am working through exercises from the book
PHP Essentials 1st edition by Julie C Meloni.

I am having difficulty with an exercise
in chapter 4 regarding Create a Database Table.

I was receiving a Couldn't connect to server.
in Netscape browser.

I edited script error and now I am stuck
with Couldn't execute query.

So I guess I am able to connect to the server
and the database, but not execute the query.

The following is the do_creatable.php script:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Create a Database Table: Step 3</TITLE></HEAD>
<BODY>

<h1>Adding table <?php echo "$table_name"; ?></h1>

<?php

$sql = "CREATE TABLE $table_name (";

for ($i = 0; $i < count($field_name); $i++) {

$sql .= "$field_name[$i] $field_type[$i]";

		if ($field_length[$i] != "") {
			$sql .= " ($field_length[$i]),";
		} else {
			$sql .= ",";
		}
	}

$sql = substr($sql, 0, -1);

$sql .= ")";

	$connection = mysql_connect("hostname","username","password")
		or die("Couldn't connect to server.");

	$db = mysql_select_db("database_name", $connection)
		or die("Couldn't select database.");

	$sql_result = mysql_query($sql,$connection)
		or die("Couldn't execute query.");

	if (!$sql_result) {
		echo "<P>Couldn't create table!";
	} else {
		echo "<P>$table_name has been created!";
	}
?>
</BODY>
</HTML>

Any suggestions?

Thanks in advance.

Vip

_________________________________________________________________
Get a FREE online virus check for your PC here, from McAfee. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux