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 402,095 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 2,467 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: Programming Forums
Views: 353 | Replies: 5
Reply
Join Date: Feb 2008
Posts: 296
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Question is my code correct?

  #1  
Mar 17th, 2008
i am adding elements to my db and the elemtents which have been add will be displayed on a different page. i am using an upload page which creates a thumb nail of an uploaded image and then stores the path for this image in a variable called $thumb_name. the code i have used to enter the image into the db is

  1. include "db.php";
  2.  
  3. $con = mysql_pconnect("$dbhost","$dbusername","$dbpasswd")
  4. or die ("QUERY ERROR: ".mysql_error());
  5.  
  6. $db = mysql_select_db("$database_name", $connection)
  7. or die("QUERY ERROR: ".mysql_error());
  8.  
  9. // Create table in $database_name database
  10. mysql_select_db("$database_name", $connection);
  11. $sql = "CREATE TABLE images
  12. (imageID int NOT NULL AUTO_INCREMENT, Broad1 varchar(50), Broad2 varchar(50), Broad3 varhar(50))";
  13.  
  14. mysql_query("INSERT INTO images (Broad1) VALUES ('$thumb_name')");
  15. ?>

and the code to display the image on the next page looks like this

  1. <?php
  2. include"db.php";
  3.  
  4. $result = mysql_query("SELECT * FROM images WHERE 'Broad1'='$thumb_name'");
  5. {
  6. echo $row['Broad1'];
  7. echo "<br />";
  8. }
  9. ?>
Last edited by peter_budo : Mar 18th, 2008 at 6:11 am. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: is my code correct?

  #2  
Mar 17th, 2008
Everything is correct.. But this is wrong.
$result = mysql_query("SELECT * FROM images WHERE 'Broad1'='$thumb_name'");
{
echo $row['Broad1'];
echo "<br />";
}
?>
This should be
  1. $result = mysql_query("SELECT * FROM images WHERE 'Broad1'='$thumb_name'");
  2. $row= mysql_fetch_array($result);
  3. echo $row['Broad1'];
  4. echo "<br />";
  5. ?>
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: Dec 2007
Posts: 112
Reputation: mwasif is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 13
mwasif mwasif is offline Offline
Junior Poster

Re: is my code correct?

  #3  
Mar 17th, 2008
And
  1. $result = mysql_query("SELECT * FROM images WHERE 'Broad1'='$thumb_name'");
Should be
  1. $result = mysql_query("SELECT * FROM images WHERE Broad1='$thumb_name'");
No quotes around Broad1.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: is my code correct?

  #4  
Mar 18th, 2008
Originally Posted by mwasif View Post
And
  1. $result = mysql_query("SELECT * FROM images WHERE 'Broad1'='$thumb_name'");
Should be
  1. $result = mysql_query("SELECT * FROM images WHERE Broad1='$thumb_name'");
No quotes around Broad1.


Ah! correct.. I couldn't spot that one!
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: 296
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Question Re: is my code correct?

  #5  
Mar 18th, 2008
i have correct the few lines of code which were wrong but it is now saying that the table i have created does not exist. the code i have used to create the table is

[code=php]include "db.php";

$con = mysql_pconnect("$dbhost","$dbusername","$dbpasswd")
or die ("QUERY ERROR: ".mysql_error());

$db = mysql_select_db("$database_name", $connection)
or die("QUERY ERROR: ".mysql_error());

// Create table in $database_name database
mysql_select_db("$database_name", $connection);
$sql = "CREATE TABLE images (imageID int NOT NULL AUTO_INCREMENT, Broad1 varchar(50), Broad2 varchar(50), Broad3 varhar(50))";

mysql_query("INSERT INTO images (Broad1) VALUES ('$thumb_name')");[code]

were have i gone wrong?
Last edited by peter_budo : Mar 18th, 2008 at 6:13 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: is my code correct?

  #6  
Mar 18th, 2008
You aren't executing the create table query.
$sql = "CREATE TABLE images (imageID int NOT NULL AUTO_INCREMENT, Broad1 varchar(50), Broad2 varchar(50), Broad3 varhar(50))";
After this, you need to have mysql_query($sql);
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  
Reply

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

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

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

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