Jump to content

Recommended Posts

Dear

i m using this two code.

 

form.php

 

<form enctype="multipart/form-data" action="add.php" method="POST">

Name: <input type="text" name="name"><br>

E-mail: <input type="text" name = "email"><br>

<!-- MAX_FILE_SIZE must precede the file input field -->

    <input type="hidden" name="MAX_FILE_SIZE" value="3072000" />

File: <input type="file" name = "file"><br>

Photo: <input type="file" name="photo"><br>

<input type="submit" value="Add">

</form>

 

add.php

 

<?php

 

//This is the directory where images will be saved

$target = "images/";

$target = $target . basename($_FILES['photo']['name']);

 

$target1 = "images/";

$target1 = $target1 . basename($_FILES['file']['name']);

 

//babar addition

if (!eregi(".sis$", $target1)) {

    print "Sorry, only Sis files here (with a .sis extention).

        Please use your back button";

    exit;

}

 

 

 

if (!eregi(".gif$", $target) && !eregi(".jpg$", $target)) {

    print "Sorry, only Image files here (with a .jpg and .gif extentions).

        Please use your back button";

    exit;

}

 

 

 

 

//This gets all the other information from the form

$name=$_POST['name'];

$email=$_POST['email'];

$file=($_FILES['file']['name']);

$pic=($_FILES['photo']['name']);

 

// Connects to your Database

mysql_connect("localhost", "v2073_v2073", "alpha123") or die(mysql_error());

mysql_select_db("v2073_phpabout") or die(mysql_error());

 

//Writes the information to the database

mysql_query("INSERT INTO employees VALUES ('$name', '$email', '$file', '$pic')");

 

//Writes the photo to the server

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target) && move_uploaded_file($_FILES['file']['tmp_name'], $target1))

{

 

//Tells you if its all ok

echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";

 

}

else {

 

//Gives and error if its not

echo "Sorry, there was a problem uploading your file.";

}

?>

 

What more i want from this script is that if a person don't have pic, he just leave this field empty in form.php and a nopreview.gif is automatically added to the mysql database.Please don't just identify what i need to do.Please write the complete code and where i should insert that code to achieve my objective.

I m waiting.thanks

Link to comment
https://forums.phpfreaks.com/topic/42086-urgent-help-in-this-php-code/
Share on other sites

Please don't just identify what i need to do.Please write the complete code and where i should insert that code to achieve my objective.

 

Sorry, like kenrbnsn said, we are not here to write the code for you. We're more than happy to help you LEARN HOW TO DO IT YOURSELF.

 

Now on to your problem.

 

I would think that it would be easier to place the default picture in the code where you are displaying the picture. e.g.

 

<?php

//code grabbing your users info from database here

if($picture_link_in_db ==""){
//show default picture here

}else{
//show picture user uploaded

}

?>

 

I hope that makes sense to you, if not then I suggest grabbing a book and start learning PHP before you try to mess with someone else's code.

This can be handled by MySQL it self. Give your picture column a default value of nopreview.gif

 

So when you insert the data into the database MySQL will place nopreview.gif as the value of the picture column if the picture column is given a null value. If you weant to do this method read up on creating tables with mysql and using the default option for columns.

 

However you can do it with PHP as well by doing something like this:

$pic = (isset($_FILES['photo']['name']) && !empty($_FILES['photo']['name'])) ? $_FILES['photo']['name'] : 'nopreview.gif';

 

It is not a complicated process to do what you are trying to do. It is just basic stuff with checking the value of variables. Then checking that variable is not empty if it is give it a value of nopreview.gif

 

If we give you the code and tell exactly what to do you are not going to learn for yourself how to do it. If you want someone to do it for your then take a trip to the freelancing forum.

 

I have given a few simple possibilities for what you are trying to do. Its now down to you to implement these into your app.

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.