User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 373,379 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,657 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 1005 | Replies: 32 | Solved
Reply
Join Date: Feb 2008
Posts: 269
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Table aready exists

  #1  
Mar 31st, 2008
Hello i am having a problem with trying to create a table on the server every time a try to enter data into the database i get the message table already exists. I have moved the code to create the table on to its own page and only recall that page when the data is being entered into the data base the first time. the code i have used for the create table looks like this

			$sql="CREATE TABLE `images_broad` (
			
			`broad1` varchar(100),
			`broad2` varchar(100)
		)";	
		mysql_query($sql) or die (mysql_error());	

and the code i have used to update the database looks like this

	<?php
		include "table_create.php";
		

			
		$sql="UPDATE images_broad SET broad1='$thumb_name'";
		$query = mysql_query($sql);
		?>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is online now Online
Posting Sensei

Re: Table aready exists

  #2  
Mar 31st, 2008
Why do you want to create a table from php anyway ? Everytime you run your script, it will include table_create.php and tries to create the table all the time. Check this link . Add 'if not exists' in your create table query.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Feb 2008
Posts: 269
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: Table aready exists

  #3  
Mar 31st, 2008
i will check that now i thought it had something to do with the code being executed more than once. That is why i tried putting it on a different page and only tried to recall it when i wanted the table to be populated.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is online now Online
Posting Sensei

Re: Table aready exists

  #4  
Mar 31st, 2008
Since you are including the script which creates the table, whenever you include that script, it tries to create the table causing the error.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Feb 2008
Posts: 269
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: Table aready exists

  #5  
Mar 31st, 2008
thanks for that. the code i have used should be putting the data into the database now and this code should be getting the data out of the database.

	<?php
						
	         $sql= "SELECT * FROM images_broad";
		$query = mysql_query($sql);
	        $result = mysql_fetch_array($query) or die (mysql_error());
		echo $result ['$thumb_name'];
						
	     ?>


is this code correct because when i run it i do not get anything showing up on the pages
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is online now Online
Posting Sensei

Re: Table aready exists

  #6  
Mar 31st, 2008
It should be echo $result['thumb_name'];
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Feb 2008
Posts: 269
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: Table aready exists

  #7  
Mar 31st, 2008
i tried changing the echo line to how you said but it still does not place anything on the page. i have set $thumb_name a variable which stores the image at first and this is used to display the image that has been created on the upload page. I want to then store this variable in the table i have created and then recall the data from the tablew on a different page.

When i use the select statement i get nothing out of the database and the code for the rest of the page does not complete so i end up with half a page. i have tried putting the or die statement at the end but it does not give me any error messages so i do not no were it is going wrong.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is online now Online
Posting Sensei

Re: Table aready exists

  #8  
Mar 31st, 2008
Hmm.. Print out your query ( print $sql; )and execute it in mysql console or phpmyadmin. See if it returns any row. If it doesn't, then the problem is not with the query and there are no records. If it returns an error, post that error.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Feb 2008
Posts: 269
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: Table aready exists

  #9  
Mar 31st, 2008
when i have put the print statement at the end of the update statement it has given me this line underneath the upload button.

UPDATE images_broad SET broad1='..'

the update code now looks like this

	   $sql="UPDATE images_broad SET broad1='.$thumb_name.'";
		$query = mysql_query($sql);
		print $sql;

is the print in the correct place?
Reply With Quote  
Join Date: Feb 2008
Posts: 269
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: Table aready exists

  #10  
Mar 31st, 2008
once the upload section has been ran it then gives this line

UPDATE images_broad SET broad1='image/thumbs/thumb_1206960238.gif'

to me it looks like the image is being placed in the table but why would it not be displayed on the page i have asked it to?

the code i use to display the image is

	$sql= "SELECT broad1 FROM images_broad";
	     $query = mysql_query($sql)or die (mysql_error());
	     $result = mysql_fetch_array($query) or die (mysql_error());
	     echo $result ['$thumb_name'];

could it have something to do with the data types set in the create table section as i have set broad1 to be a varchar
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Other Threads in the MySQL Forum

All times are GMT -4. The time now is 3:14 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC