php - MySQL database insertion error -
I am uploading the images to a directory on a project and storing the image path in the database table. Image upload work is fine but my text input for name is not working I need your help.
if (isset ($ _ POST ['upload'])) {$ path = $ path $ _ Files ['file_upload'] ['name']; Br / & gt; Uploaded, if (move_uploaded_file ($ _ FILES ['file_upload'] ['tmp_name'], $ path) {echo ".basename ($ _ files ['file_upload'] ['name']),"; Echo '& lt; img src = "gallery /'. $ _ FILES ['file_upload'] ['name']. '' Width =" 48 "height =" 48 "/> $; img = $ _ Files ['file_upload'] ['name']; $ Query = "imgtables (name, imgurl, date) value ('$ name', STR_TO_DATE ('$ dateofbirth', '% d-% m-% y'), Insert "$ img", now ()); if ($ sp-> query ($ query)) {resonant "br / & gt; insert db";} Else {echo "error
"$ sp-> Error;}} Else {echo" is an error, please try again or ckeck path ";}} ??
form As follows:
form action = "gallery.php" method = "post" enctype = "multipart / form-data"> gt; width of the table = "384" "Border =" 1 "align =" center "> gt; & gt; TR & gt; & lt; td width =" 108 "& gt; name & lt; / td & gt; & lt; td & gt; Lt; input type = "text" name = "name" & gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td width = "108" & gt; Choose file & lt; / Td> & Lt; Td width = "260" & gt; & Lt; Label & gt; & Lt; Input type = "file" name = "file_upload" & gt; & Lt; / Labels & gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; & Lt; / TD & gt; & Lt; Td> & Lt; Label & gt; & Lt; Input type = "submit" name = "upload" value = "upload file" & gt; & Lt; / Labels & gt; & Lt; / Td> & Lt; / TR & gt; & Lt; / Table & gt; & Lt; / Form & gt;
Clearly the variable $ name
is blank or undefined And that is why all the other columns are populated and this is not one. Since the query is valid, you do not get any errors.
You can confirm it with a simple one:
resonance ($ name);
Not related to your issue:
- Your code is weak for: use it to stop.
- Is
globals turned on? If so, then you should actually consider closing it. To know, take a look.
Comments
Post a Comment