Hi all,..

Need help for my script, i want to make update form for my database so i make script as follows

update.php

<form id="form1" name="Update" method="post" action="add.php">
<table border="0" cellspacing="10">
<tr>
<td>Asm Manual Id:</td> <td><input type="text" name="id"></td>
</tr>
<tr>
<td>Asm Manual name:</td> <td><input type="text" name="sheetname"></td>
</tr>
<tr>
<td>Image URL(Link):</td> <td><input type="text" name="link"></td>
</tr>
<tr>
<td><INPUT TYPE="Submit" VALUE="Update Asm Manual" NAME="Submit"></td>
</tr>
</table>

add.php

<?php
$con = mysql_connect("localhost", "sigit_p", "h4ngg401");
if (!$con)
{
die('Could not connect to DB: ' . mysql_error() );
}
mysql_select_db ("kdplnseries", $con);
$sql="INSERT INTO asmmanual (id, sheetname, link)
VALUES ('$_POST[id]','$_POST[sheetname]','$_POST[link]')";
if (!mysql_query($sql,$con))
{
die ('Error: ' . mysql_error());
}
echo "Record added";

//showing database record
$result = mysql_query("SELECT * FROM asmmanual")
or die(mysql_error());  

$fields_num = mysql_num_fields($result);

echo "<table border='0'><tr>";
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
while($row = mysql_fetch_row($result))
{
    echo "<tr>";
    foreach($row as $cell)
        echo "<td>$cell</td>";

    echo "</tr>\n";
}
mysql_free_result($result);
    mysql_close($con)
    ?>

what i want as follows : ,..

input type and stored text in database setting uppercase

for upload image file there is browse button after we chooses the file and automatically stored to specific folder in server (in database colomn contain link to image stored folder exp http://localhost/image/test.png).

thanks

Member Avatar for diafol

For your form you could do this. Note the enctype attribute for form - A MUST if you want to upload files. The input type for files is "file".

<form id="form1" name="Update" method="post" action="add.php" enctype="multipart/form-data">
<table border="0" cellspacing="10">
<tr>
<td>Asm Manual Id:</td> <td><input type="text" name="id"></td>
</tr>
<tr>
<td>Asm Manual name:</td> <td><input type="text" name="sheetname"></td>
</tr>
<tr>
<td>Upload Image:</td> <td><input type="file" name="file"></td>
</tr>
<tr>
<td><input type ="submit" value="Update Asm Manual" name="Submit"></td>
</tr>
</table>

i've tried your script then error appear

Notice: Undefined index: link in D:\wamp\www\add.php on line 9

my goals is like this :

id sheetname link
A2-1C1-3B SIDECOVER ASM LH http://localhost/nseries/A2-1C1-3B.png
A2-1C1-1B SIDECOVER ASM RH http://localhost/nseries/A2-1C1-1B.png
A2-5F-999 test

last data is not i expected, is it possible to upload image and automatically stored image in specific folder ??

thanks

Member Avatar for diafol

Notice: Undefined index: link in D:\wamp\www\add.php on line 9

If you notice, I've changed the name of the field from 'link' to 'file', as this better describes the field type. Your file will be saved in a temp folder unless you actively save it to a folder with a file command like:

move_uploaded_file()

Once you have confirmed the existence of the file in your folder with php, write the new location to the DB.

i've search for move_upload_file, example like this from this website:

<?php
    if (move_uploaded_file($_FILES['userfile']['tmp_name'], "/place/for/file")) {
        print "Received {$_FILES['userfile']['name']} - its size is {$_FILES['userfile']['size']}";
    } else {
        print "Upload failed!";
    }
?> 

if i want to insert in my script where should i put it ???
please help

Member Avatar for diafol

To wherever the action attribute of the form is pointing.

please help modify my script so i can upload picture to specified folder, been running around google and website but still blank (have no idea what supposed to do).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.