0

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

2
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by sigit_p
0

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>
0

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.

0

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

0

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).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.