Jump to content

[SOLVED] php script to perform mysql table insert


Jago6060

Recommended Posts

If its in a loop...feature_images  needs to be a variable, it its static, its only ever going to insert to one table

 

Make $tablename dynamic in relation to what ever your loop is pullin out

 

$sql = "INSERT INTO $tablename (img_dir)values('$target_path')";

$result=mysql_query($sql);

Link to comment
Share on other sites

<?
include 'connect.php';

// Where the file is going to be placed 
$target_path = "./uploads/images/";

/* Add the original filename to our target path.  
Result is "/uploads/images/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
$_FILES['uploadedfile']['tmp_name'];  

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
    @mysql_select_db($database) or die( "Unable to select database");
    $sql = "INSERT INTO feature_images (img_dir)values('$target_path')";
    $result=mysql_query($sql);
    mysql_close();
    header ('Location: logout.php');
}else{
    echo "There was an error uploading the file, please try again!";
    echo "<a href=upload_feature_form.php>Back</a>";
}
?>

 

heres the full script

Link to comment
Share on other sites

Like I said, turn feature_images  into a variable which will contain your table name

 

Using the loop, it needs to switch from feature_images to your other table name

 

If it looks twice thats 2 seperate inserts into 2 seperate tables providing the table names have been set

Link to comment
Share on other sites

ok, sorry to be a pain but I just wanted to clarify this.  The format I should use is...

 

$feature = "feature_images";
$images = "crc_images";

$sql = "INSERT INTO $feature (img_dir)values('$target_path')";
$sql2 = "INSERT INTO $images (img_dir)values('$target_path')";

$result=mysql_query($sql);
$result=mysql_query($sql2);

 

right?

Link to comment
Share on other sites

Correct, if your not putting them in a loop, no need to even make them variables

 

I only said that because I thought it was in a loop

 

if your just placing it in the script, you can statically assign the table names to the query

 

No big deal though, what you have above will work fine

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.