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";

 

 

 

Link to comment
Share on other sites

// 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
... 

Link to comment
Share on other sites

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);

 

 

?>

 

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.