Page 1 of 1

inserting data into mySQL with upload image name

Posted: Tue Aug 21, 2007 3:36 pm
by cybergirl
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello,

I just need to fix my code to work. I have an upload.html file and an load.php file. On the html file, I just need to know if the selection option dropdown will correspond properly with the code on the upload form. On the upload form, I'm trying to figure out if I have it written properly overall, and I suspect my SQL code is wrong as well. here are the two code examples:

upload.html
[syntax="html"]
<form action=load.php method=post enctype="multipart/form-data">
<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="90000">
<table>
<tr>
  <td colspan="2">Featured Clients Upload Form </td>
  </tr>
<tr>
<td width="13%">Title:</td>
<td width="87%"><input type="text" name="title" size="28"></td>
</tr>

<tr>
  <td>Company Name: </td>
  <td><input type="text" name="company" size="28" /></td>
</tr>
<tr>
  <td>Contact Info :</td>
  <td><textarea rows="5" name="address" cols="23"></textarea></td>
</tr>
<tr>
  <td colspan="2">Featured the listing spot:</td>
  </tr>
<tr>
  <td>&nbsp;</td>
  <td><label>
    <select name="feature_num">
      <option  value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
      <option value="6">6</option>
      <option value="7">7</option>
      <option value="8">8</option>
      <option value="9">9</option>
      <option value="10">10</option>
      <option value="11">11</option>
      <option value="12">12</option>
      <option value="13">13</option>
      <option value="14">14</option>
      <option value="15">15</option>
    </select>
  </label></td>
</tr>
<tr>
  <td>Category</td>
  <td><input type="text" name="category" size="28" /></td>
</tr>
<tr>
  <td colspan="2">Tour Images : </td>
  </tr>
<tr>
  <td>Tour Image #1 </td>
  <td><input type="file" name="tourimage01" size="28" /></td>
</tr>
<tr>
  <td>Tour Image #2 </td>
  <td><input type="file" name="tourimage02" size="28" /></td>
</tr>
<tr>
  <td>Tour Image #3 </td>
  <td><input type="file" name="tourimage03" size="28" /></td>
</tr>
<tr>
  <td>Tour Image #4</td>
  <td><input type="file" name="tourimage04" size="28" /></td>
</tr>
<tr>
  <td>Tour Image #5 </td>
  <td><input type="file" name="tourimage05" size="28" /></td>
</tr>
<tr>
  <td colspan="2">Tour Thumbnails (thumb # must correspond to the above Tour Image) </td>
  </tr>
<tr>
  <td>Tour Thumbnail #1 </td>
  <td><input type="file" name="tourimage01thumb" size="28" /></td>
</tr>
<tr>
  <td>Tour Thumbnail #2</td>
  <td><input type="file" name="tourimage02thumb" size="28" /></td>
</tr>
<tr>
  <td>Tour Thumbnail #3</td>
  <td><input type="file" name="tourimage03thumb" size="28" /></td>
</tr>
<tr>
  <td>Tour Thumbnail #4 </td>
  <td><input type="file" name="tourimage04thumb" size="28" /></td>
</tr>
<tr>
  <td>Tour Thumbnail #5</td>
  <td><input type="file" name="tourimage05thumb" size="28" /></td>
</tr>
<tr>
  <td colspan="2">Company ( logo must be small): </td>
  </tr>
<tr>
  <td>Logo:</td>
  <td><input type="file" name="logo" size="28" /></td>
</tr>
<tr>
<td width="13%">Description:</td>
<td width="87%"><textarea rows="5" name="desc" cols="23"></textarea></td>
</tr>
</table>
<p align="center"><input type=submit name=action value="Load"><input type="reset" value="Reset" name="B2"></p>
</form>

load.php[/syntax]

Code: Select all

<?php

if ($action == "Load")
 {

$folder = "/home/dtours3/public_html/tours/tourimages/";
  @copy("$tourimage01" , "$folder/$tourimage01_name");
  @copy("$tourimage02" , "$folder/$tourimage02_name");
  @copy("$tourimage03" , "$folder/$tourimage03_name");
  @copy("$tourimage04" , "$folder/$tourimage04_name");
  @copy("$tourimage05" , "$folder/$tourimage05_name");
  @copy("$tourimage01thumb" , "$folder/$tourimage01thumb_name");
  @copy("$tourimage02thumb" , "$folder/$tourimage02thumb_name");
  @copy("$tourimage03thumb" , "$folder/$tourimage03thumb_name");
  @copy("$tourimage04thumb" , "$folder/$tourimage04thumb_name");
  @copy("$tourimage05thumb" , "$folder/$tourimage015thumb_name");
  @copy("$logo" , "$folder/$logo_name");
  echo "
  <br><p align=center>File <b><i>$tourimage01_name</i></b><br>
  <br><p align=center>File <b><i>$tourimage02_name</i></b><br>
  <br><p align=center>File <b><i>$tourimage03_name</i></b><br>
  <br><p align=center>File <b><i>$tourimage04_name</i></b><br>
  <br><p align=center>File <b><i>$tourimage05_name</i></b><br>
 
  <br><p align=center>File <b><i>$tourimage01thumb_name</i></b><br>
  <br><p align=center>File <b><i>$tourimage02thumb_name</i></b><br>
  <br><p align=center>File <b><i>$tourimage03thumb_name</i></b><br>
  <br><p align=center>File <b><i>$tourimage04thumb_name</i></b><br>
  <br><p align=center>File <b><i>$tourimage05thumb_name</i></b><br>
 
  <br><p align=center>File <b><i>$logo_name</i></b><br>
   loaded...";
 $result = mysql_connect("localhost", "dtours3_deb", "cybergirl") or die("Could not connect: " . mysql_error());

  @mysql_select_db("dtours3_rich") or die("Could not select database");
  @mysql_query("INSERT into tours (tourid, title, company, address, feature_num, category, desc, tourimage01, tourimage02, tourimage03, tourimage04, tourimage05, tourimage01thumb, tourimage02thumb, tourimage03thumb, tourimage04thumb, tourimage05thumb, logo) VALUES('', 'tourid', 'title', 'company', 'address', 'category', 'feature_num', 'desc', '$tourimage01_name', '$tourimage02_name', '$tourimage03_name', '$tourimage04_name', '$tourimage05_name', '$tourimage01thumb_name', '$tourimage02thumb_name', '$tourimage03thumb_name', '$tourimage04thumb_name', '$tourimage05thumb_name', '$logo_name') ");
 
  if($result) { echo "Featured Client profile and image names saved into database"; }


 }

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Aug 21, 2007 3:40 pm
by Theory?
The "Submit" form element submits no values when the form is submitted. Usually, an easy workaround is to submit a "hidden" field with the name/value combination you'd want.

Code: Select all

<input type="hidden" name="foo" value="bar" />

Posted: Tue Aug 21, 2007 10:05 pm
by califdon
I see a lot of problems with your scripts. Let's start with load.php. Where does the value $action come from? You could pass that as a GET variable or you could get it from a hidden Input element in the form, but it's got to come from somewhere; it doesn't magically appear by itself.

Then you have to read the POST variables into regular PHP variables before you can use variables like $tourimage01. The syntax would be something like:

Code: Select all

$tourimage01 = $_POST['tourimage01']
$tourimage02 = $_POST['tourimage02']
...
Then where in the world do you get values for variables like $tourimage01_name??

In your SQL statement, you have a blank value at the beginning of your VALUES clause that doesn't seem to have a matching field name in your fields list.

You can start by fixing those things.

help

Posted: Tue Aug 21, 2007 10:44 pm
by cybergirl
I'm a beginner I'm reading books, I'm trying to learn this, and honestly, I find it very hard. Please help.

Posted: Wed Aug 22, 2007 12:46 pm
by cybergirl
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


ok, I'm starting anew today. I got 2 simple forms: upload.html and load.php

upload.html

[syntax="html"]
<html>
<body>
<head>
<title>Load</title>
</head>
<p>
<form action=load.php method=post enctype="multipart/form-data">
<table border="0" cellspacing="0" align=center cellpadding="3" bordercolor="#cccccc">
<tr>
<td>File:</td>
<td><input type="file" name="tourimage01" size=45></td>
</tr>
<tr>
<td colspan=2><p align=center>
<input type=submit name=action value="Load">
</td>
</tr>
</table>
</form>

</body>
</html>

load.php[/syntax]

Code: Select all

<?php

if ($action == "Load")
 {

$folder = "/home/dtours3/public_html/tours/tourimages/";
  @copy("$tourimage01" , "$folder/$tourimage01_name");
  echo "<br><p align=center>File <b><i>$tourimage01_name</i></b> loaded...";
 $result = mysql_connect("localhost", "dtours3_deb", "cybergirl") or die("Could not connect: " . mysql_error());

  @mysql_select_db("dtours3_rich") or die("Could not select database");
  @mysql_query("INSERT into tours (tourimage01) VALUES('$tourimage01_name')");
  if($result) { echo "Image name saved into database"; }


 }

?>
How do I make this multiple uploads, and then add record data into the database with it as well?

That's what I'm trying to do

Here is my list of fields:

tablename: tours

fields: tourid, title, company, contact, category, feature_num, desc, tourimage01, tourimage02, tourimage03, tourimage04, tourimage05, tourimage01thumb, tourimage02thumb, tourimmage03thumb, tourimage04thumb, tourimage05thumb, logo

both tourimage05 and tourimage05thumb are optional, meaning it can be null of the field.


Of the above fields these are all images

tourimage01, tourimage02, tourimage03, tourimage04, tourimage05, tourimage01thumb, tourimage02thumb, tourimmage03thumb, tourimage04thumb, tourimage05thumb, logo


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Aug 23, 2007 8:03 pm
by califdon
It's perfectly okay that you are just starting to learn -- we all had to. But you've ignored every one of the problems that I pointed out the first time. That's not exactly a good way to learn.

I'll try again:

Your upload script looks basically correct.

When the user presses the Submit button, the "action=" script (load.php) is called and a $_POST array is sent to the server, containing the names and values of the controls in your form. It is up to you, the programmer, to assign values to variables such as $action or $tourimage01. Those variables will contain no information until you put it into them! So the very first statement in your load.php script says if ($action == "Load") and since you have assigned no value to $action, that statement will always evaluate False. You have to supply the value in the script before you can test its value. Similarly, when you just, out of nowhere, try to use $tour_image01 in your script, it has no value unless you assigned a value earlier -- which you didn't (unless you're only showing a part of your script). The usual way to do that is like this:

Code: Select all

$tourimage01 = $_POST['tourimage01'];

Posted: Thu Aug 23, 2007 11:47 pm
by Theory?
califdon wrote:It's perfectly okay that you are just starting to learn -- we all had to. But you've ignored every one of the problems that I pointed out the first time. That's not exactly a good way to learn.

I'll try again:

Your upload script looks basically correct.

When the user presses the Submit button, the "action=" script (load.php) is called and a $_POST array is sent to the server, containing the names and values of the controls in your form. It is up to you, the programmer, to assign values to variables such as $action or $tourimage01. Those variables will contain no information until you put it into them! So the very first statement in your load.php script says if ($action == "Load") and since you have assigned no value to $action, that statement will always evaluate False. You have to supply the value in the script before you can test its value. Similarly, when you just, out of nowhere, try to use $tour_image01 in your script, it has no value unless you assigned a value earlier -- which you didn't (unless you're only showing a part of your script). The usual way to do that is like this:

Code: Select all

$tourimage01 = $_POST['tourimage01'];
The problem I see is that you're trying to use the submit button to initialize the variable "action" which is a mistake. The submit button doesn't send any information to the script, this is what I said about the "hidden" form field. I gave the code demonstration above, I won't retype it. Simply add that field to your form and you will have the variable $_POST['action'] with the value "Load", which you can then assign to the variable "$action" if you so desire, or, more simply, say:

Code: Select all

if ($_POST['action'] == "Load") {//etc}