•
•
•
•
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
![]() |
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
and the code i have used to update the database 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); ?>
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation:
Rep Power: 8
Solved Threads: 227
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*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation:
Rep Power: 8
Solved Threads: 227
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*
*PM asking for help will be ignored*
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.
is this code correct because when i run it i do not get anything showing up on the pages
<?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
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation:
Rep Power: 8
Solved Threads: 227
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.
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.
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation:
Rep Power: 8
Solved Threads: 227
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*
*PM asking for help will be ignored*
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
is the print in the correct place?
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?
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
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
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
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
- Previous Thread: foreign keys
- Next Thread: creating tables



Linear Mode