Jump to content

problem getting 2 queries to work together ...


Frank100

Recommended Posts

Hi,

when I try to create 2 tables through a .php file like this it doesn’t work. Can somebody give me a hint ? It’s only the 2 querys which make problems, the rest of the file (not shown here) works … when I use just 1 query the .php file works fine and creates the desired table.

 

Regards,

Frank

 

 

 

 

$query = "

 

CREATE TABLE company (

company_id INT(10) unsigned NOT NULL auto_increment primary key ,

company_registerdate TIMESTAMP NOT NULL

) ENGINE = innodb";

 

 

$query = "

 

CREATE TABLE lessor (

lessor_id INT(10) unsigned NOT NULL auto_increment primary key ,

lessor_registerdate TIMESTAMP NOT NULL ,

) ENGINE = innodb";

 

 

 

// establish connection to database, select database, then ...
$query = ".... first query ...";
$result = mysql_query($query); // execute first query

$query = ".... second query ...";
$result = mysql_query($query); // execute second query
... 

Hi Andy,

thx again ! I've tried it out but it seems that I still make a mistake ... no tables are created.

Here's my whole .php file.

 

Regards,

Frank

 

 

 

<?php

 

/* connect database */

 

$link = mysqli_connect("localhost", "root", "abc", "test");

 

/* check connection */

 

if (!$link) {

    printf("Connect failed: %s\n", mysqli_connect_error());

    exit();

}

 

// establish connection to database, select database, then ...

 

$query = "

CREATE TABLE placesx (

 

place_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,

place_picture_01 VARCHAR(30) NOT NULL ,

place_picture_02 VARCHAR(30) NOT NULL

) ENGINE = innodb";

 

$result = mysql_query($query); // execute first query

 

 

 

 

$query = "

CREATE TABLE renterx (

renter_id INT(10) unsigned NOT NULL auto_increment primary key ,

renter_first_name VARCHAR(30) NOT NULL ,

renter_last_name VARCHAR(30) NOT NULL

 

) ENGINE = innodb";

 

$result = mysql_query($query); // execute second query

...

 

 

 

/* check query */

 

if (mysqli_query($link, $query)=== TRUE) {

 

    printf("Table successfully created.\n");

 

}

 

/* disconnect database */

 

mysqli_close($link);

 

 

?>

 

 

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.