I'm trying to print one line of text in my database code and i want it to print under a button i have made in html.

<button id="gen" type="button">Generate tables by clicking here!</button>
<div id="response"></div>
$('#gen').click(function(){
		$('#response').load('createtable.php');			
	});

And this code appears in createtable.php

echo "Tables were set up correctly.";

The problem is that nothing is showing up. If i change the line to

echo "<br>Tables were set up correctly.";

it will print everything after the <br> including the ";?> that closes the php code.

Anyone has any idea why?

Member Avatar

diafol

Show the contents of createtable.php. You may have unbalanced quotes, braces or other errors.

Here is the full code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
/* ----------INITIALIZE VARIABLES----------*/

$hname = 'localhost';
$uname = 'root';
$pass = '';
$dbname = 'cs336';

//connect to mySQL
$dbcon = mysql_connect($hname, $uname, $pass) or die("Cannot connect to the database");

/* ----------START OF DB AND TABLE CREATION---------- */
//now make sure that we are using the correct db
mysql_select_db($dbname, $dbcon) or die(mysql_error($dbcon));

//create table for WebPage
$q = 'CREATE TABLE if not exists WebPage (
		Title VARCHAR(50) PRIMARY KEY, 
		URL VARCHAR(50), 
		Owner VARCHAR(20), 
		Restricted BOOL, U
		UploadDate DATETIME, 
		LastUpdate DATETIME, 
		PageRank INT, 
		NumViews INT,  
		LastViewed DATETIME, 
		Status TINYINT)';
		
mysql_query($q, $dbcon) or die(mysql_error($dbcon));

//create table for Image
$q = 'CREATE TABLE if not exists Image (
		Title VARCHAR(50) PRIMARY KEY, 
		URL VARCHAR(50), 
		Owner VARCHAR(20), 
		Restricted BOOL, 
		UploadDate DATETIME, 
		LastUpdate DATETIME, 
		NumViews INT,  
		LastViewed DATETIME, 
		Status TINYINT)';

mysql_query($q, $dbcon) or die(mysql_error($dbcon));

//create table for Complaint
$q = 'CREATE TABLE if not exists Complaint (
		ComplaintID INT AUTO_INCREMENT PRIMARY KEY, 
		Date DATETIME, 
		Reason VARCHAR(500))';

mysql_query($q, $dbcon) or die(mysql_error($dbcon));

//create table for User
$q = 'CREATE TABLE if not exists User (
		FirstName VARCHAR(20), 
		LastName VARCHAR(20), 
		Username VARCHAR(15) PRIMARY KEY, 
		Email VARCHAR(30))';

mysql_query($q, $dbcon) or die(mysql_error($dbcon));

//create table for WU
$q = 'CREATE TABLE if not exists WU (
		Username VARCHAR(15) PRIMARY KEY, 
		Status TINYINT)';
		
mysql_query($q, $dbcon) or die(mysql_error($dbcon));

//create table for PU
$q = 'CREATE TABLE if not exists PU (
		Username VARCHAR(15) PRIMARY KEY, 
		JoinDate DATETIME, 
		LastLogin DATETIME, 
		Credit DECIMAL(2,1), 
		Status TINYINT)';
		
mysql_query($q, $dbcon) or die(mysql_error($dbcon));

//create table for SU
$q = 'CREATE TABLE if not exists SU (
		Username VARCHAR(15) PRIMARY KEY, 
		JoinDate DATETIME, 
		LastLogin DATETIME, 
		Credit DECIMAL(2,1), 
		Status TINYINT, 
		Rank TINYINT)';
		
mysql_query($q, $dbcon) or die(mysql_error($dbcon));

echo "<br>Tables were set up correctly.";

?>
</body>
</html>
Member Avatar

diafol

Why are you including head/html - these should be present in your main file. Just include the php code.

I took out the html tags and code and left the php but it's still giving me the same problems.

Here's my main file if that helps

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
<script type="text/javascript">
$(document).ready(function(){
	$('#gen').click(function(){
		$('#response').load('createtable.php');			
	});
	
	$('#q1').click(function(){
		var Title = $('input[name="1Title"]').val();
		var Owner = $('input[name="1Owner"]').val();
		var Restricted = $('input[name="1Restricted"]').val();
		
		$('#select1').load('query.php?queryNo=1&Title='+encodeURIComponent(Title)+'&Owner='+encodeURIComponent(Owner)+'&Restricted='+encodeURIComponent(Restricted));
	});
	
	$('#q2').click(function(){
		var Title = $('input[name="2Title"]').val();
		var Owner = $('input[name="2Owner"]').val();
		var Restricted = $('input[name="2Restricted"]').val();
		
		$('#select2').load('query.php?queryNo=2&Title='+encodeURIComponent(Title)+'&Owner='+encodeURIComponent(Owner)+'&Restricted='+encodeURIComponent(Restricted));
	});
	
	$('#q3').click(function(){
		var  ComplaintID = $('input[name="3ComplaintID"]').val();
		var  Reason = $('input[name="3Reason"]').val();
		
		$('#select3').load('query.php?queryNo=3&ComplaintID='+encodeURIComponent(ComplaintID)+'&Reason='+encodeURIComponent(Reason));
	});
	
	$('#q4').click(function(){
		var  FirstName = $('input[name="4FirstName"]').val();
		var  LastName = $('input[name="4LastName"]').val();
		var  Username = $('input[name="4Username"]').val();
		var  Email = $('input[name="4Email"]').val();
		
		$('#select4').load('query.php?queryNo=4&FirstName='+encodeURIComponent(FirstName)+'&LastName='+encodeURIComponent(LastName)+'&Username='+encodeURIComponent(Username)+'&Email='+encodeURIComponent(Email));
	});
	
	$('#q5').click(function(){
		var  FirstName = $('input[name="5FirstName"]').val();
		var  LastName = $('input[name="5LastName"]').val();
		var  Username = $('input[name="5Username"]').val();
		var  Email = $('input[name="5Email"]').val();
		
		$('#select5').load('query.php?queryNo=5&FirstName='+encodeURIComponent(FirstName)+'&LastName='+encodeURIComponent(LastName)+'&Username='+encodeURIComponent(Username)+'&Email='+encodeURIComponent(Email));	
	});
	
	$('#q6').click(function(){
		var  FirstName = $('input[name="6FirstName"]').val();
		var  LastName = $('input[name="6LastName"]').val();
		var  Username = $('input[name="6Username"]').val();
		var  Email = $('input[name="6Email"]').val();
		
		$('#select6').load('query.php?queryNo=6&FirstName='+encodeURIComponent(FirstName)+'&LastName='+encodeURIComponent(LastName)+'&Username='+encodeURIComponent(Username)+'&Email='+encodeURIComponent(Email));		
	});
	
	$('#q7').click(function(){
		var Title = $('input[name="7Title"]').val();
		var Owner = $('input[name="7Owner"]').val();
		
		$('#select7').load('query.php?queryNo=7&Title='+encodeURIComponent(Title)+'&Owner='+encodeURIComponent(Owner));
	});
	
	$('#q8').click(function(){
		var Title = $('input[name="8Title"]').val();
		var Owner = $('input[name="8Owner"]').val();
		
		$('#select8').load('query.php?queryNo=8&Title='+encodeURIComponent(Title)+'&Owner='+encodeURIComponent(Owner));	
	});
	
	$('#q9').click(function(){
		var  ComplaintID = $('input[name="3ComplaintID"]').val();
		
		$('#select9').load('query.php?queryNo=9&ComplaintID='+encodeURIComponent(ComplaintID));	
	});
		

});
</script>

<style type="text/css">
body{
	background-color:skyblue;
}
</style>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CSc336</title>
</head>

<body>
<h1>Database Final Project</h1>
<button id="gen" type="button">Generate tables by clicking here!</button>
<div id="response"></div>

<!--<img src="ER.png" alt="dia" align="right" width="1100" height="650"/>-->

<th><h3>Choose one of the following queries:</h3></th>

<li><font size="4">1. Add a WebPage.</font></li><br />
Title: <input type="text" name="1Title" /><br />
Owner: <input type="text" name="1Owner" /><br />
Restricted*: <input type="text" name="1Restricted" /><br />
<font size="2">*write true if restricted or false othwerwise</font><br />
<input type="submit" id="q1" /><br /><br />
<div id="select1"></div>

<li><font size="4">2. Add an Image.</font></li><br />
Title: <input type="text" name="2Title" /><br />
Owner: <input type="text" name="2Owner" /><br />
Restricted*: <input type="text" name="2Restricted" /><br />
<font size="2">*write true if restricted or false othwerwise</font><br />
<input type="submit" id="q2" /><br /><br />
<div id="select2"></div>

<li><font size="4">3. Add a Complaint.</font></li><br />
Complaint ID: <input type="text" name="3ComplaintID" /><br />
Reason: <input type="text" name="3Reason" /><br />
<input type="submit" id="q3" /><br /><br />
<div id="select3"></div>

<li><font size="4">4. Add a Waiting User.</font></li><br />
First Name: <input type="text" name="4FirstName" /><br />
Last Name: <input type="text" name="4LastName" /><br />
Username: <input type="text" name="4Username" /><br />
Email: <input type="text" name="4Email" /><br />
<input type="submit" id="q4" /><br /><br />
<div id="select4"></div>

<li><font size="4">5. Add a Privileged User.</font></li><br />
First Name: <input type="text" name="5FirstName" /><br />
Last Name: <input type="text" name="5LastName" /><br />
Username: <input type="text" name="5Username" /><br />
Email: <input type="text" name="5Email" /><br />
<input type="submit" id="q5" /><br /><br />
<div id="select5"></div>

<li><font size="4">6. Add a Super User.</font></li><br />
First Name: <input type="text" name="6FirstName" /><br />
Last Name: <input type="text" name="6LastName" /><br />
Username: <input type="text" name="6Username" /><br />
Email: <input type="text" name="6Email" /><br />
<input type="submit" id="q6" /><br /><br />
<div id="select6"></div>

<li><font size="4">7. Search for a WebPage by its Title and Owner.</font></li><br />
Title: <input type="text" name="7Title" /><br />
Owner: <input type="text" name="7Owner" /><br />
<input type="submit" id="q7" /><br /><br />
<div id="select7"></div>

<li><font size="4">8. Search for an Image by its Title and Owner.</font></li><br />
Title: <input type="text" name="8Title" /><br />
Owner: <input type="text" name="8Owner" /><br />
<input type="submit" id="q8" /><br /><br />
<div id="select8"></div>

<li><font size="4">9. Search for a Complaint by its Complaint ID.</font></li><br />
Complaint ID: <input type="text" name="9ComplaintID" /><br />
<input type="submit" id="q9" /><br /><br />
<div id="select9"></div>


</body>
</html>
Member Avatar

diafol

Doesn't help me, I'm afraid. Anybody else?

Try to simplify the problem, create an empty file, without MySQL, write:

<?php
echo "<br>Tables were set up correctly.";
?>

And see what it happens. Bye.

That creates the same problem so I'm guessing it's not the code.

$('#response').load('createtable.php');

this go's wrong if creatatble.php contains things like <html>, <title>, or <head>
for creatatble.php use cereals code and noting else.

Yes, I took out the html tags from that file and only the php code is left but that did not solve the problem.

Tested your main with cereals createtable.php
works fine for me

what do you get if you execute createtable.php directly?

If i open createtable.php in a browser it just display the line:

Tables were set up correctly."; ?>

Hmm. Apache is running, right?

Yes, I'm using the whole WAMP server.

Ok, so apparently I was running the server wrong and that was the reason for the error...

Thanks to everyone who tried to help!