MySQL Forums
Forum List  »  PHP

Image in not inserting into mysql database but all other is do
Posted by: software ss
Date: February 13, 2016 03:12AM

I am trying to learn form and inserting data into mysql database. here I have got some code, trying to understand by modifying. I have successfully added all the data to msql table but image is not so far, not able to find the mistake, please help.

database table name is 'student' and field name is 'std_img'

I have form file name addstud.php contains following code:

<!-- end of image upload test code -->
<form enctype="multipart/form-data" action=
"<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<input name="userfile" type="file" />
<!--<input type="submit" value="Submit" />
</form> -->


</td>
</tr>
<tr>
<td>Id Number</td>
<td><input name="id" type="text" class="ed" id="brnu" size="50" /></td>
</tr>
<tr>
<td>Student's Name</td>
<td><input name="std_name" type="text" class="ed" id="brnu" size="50" /></td>
</tr>
<tr>
<td>Father's Name</td>
<td><input name="std_fname" type="text" class="ed" id="brnu" size="50" /></td>
</tr>
<tr>
<td>Mother's Name</td>
<td><input name="std_mname" type="text" class="ed" id="brnu" size="50" /></td>
</tr>
<tr>
<td>Address</td>
<td><input name="std_address" type="text" class="ed" id="brnu" size="70" /></td>
</tr>
<tr>
<td>Date Of Birth</td>
<td><input name="std_dob" type="text" class="ed" id="brnu" size="50" /></td>
</tr>
<tr>
<td>Gender</td>
<td>
<table width="200" border="0">
<tr>
<td width="100"><select name="std_gender" class="ed">
<option>Male</option>
<option>Female</option>
<option>Other</option>
</select></td>
<td width="84">Religion</td>
<td width="84"><select name="std_religion" class="ed">
<option>Islam</option>
<option>Hinduism</option>
<option>Christianity</option>
<option>Buddhism</option>
<option>Other</option>
</select></td>
<td>Nationality</td>
<td> <select name="std_nationality" class="ed">
<option>Bangladeshi</option>
<option>Other</option>
</select></td>
</tr>
</table></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>


</tr>
<tr>
<td>&nbsp;</td>
<td> Official Informations</td>
</tr>
<tr>
<td>Technology</td>
<td><table width="423" border="0">
<tr>
<td width="180"><select name="std_department" class="ed">
<option>Electrical Technology</option>
<option>Civil Technology</option>
<option>Mechanical Technology</option>
</select></td>
<td width="102">Admission Date:</td>
<td width="57"><input name="do_admission" type="text" class="ed" id="brnu" size="15" /></td>
</tr>
</table></td>
</tr>
<tr>
<td>Student's Cell No.</td>
<td><table width="455" border="0">
<tr>
<td width="188"><input name="std_cellno" type="text" class="ed" id="brnu" size="20"/></td>
<td width="107">Father's Cell No.</td>
<td width="146"><input name="std_fcellno" type="text" class="ed" id="brnu" size="20" /></td>
</tr>
</table>
</td>

</tr>
<tr>
<td>Student's Login Info:</td>
<td><table width="449" border="0">
<tr>
<td width="74">Username:</td>
<td width="94"><input name="std_username" type="text" class="ed" id="brnu" size="15" /> </td>
<td width="69">Password</td>
<td width="176"><input name="std_password" type="text" class="ed" id="brnu" size="15" /></td>
</tr>
</table></td>
</tr>
<tr>

</tr>
</table>

<br>
<input type="submit" name="Submit" value="save" id="button1" />
</form>




other file using to insert data is addstudexec.php

contains code here:

<?php
include('../connect.php');

//Function to sanitize values received from the form. Prevents SQL injection
function clean($str)
{
$str = @trim($str);
if(get_magic_quotes_gpc())
{
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$id = clean($_POST['id']);
$std_name = clean($_POST['std_name']);
$std_fname = clean($_POST['std_fname']);
$std_mname = clean($_POST['std_mname']);
$std_address = clean($_POST['std_address']);
$std_dob = clean($_POST['std_dob']);
$std_gender = clean($_POST['std_gender']);
$std_religion = clean($_POST['std_religion']);
$std_nationality = clean($_POST['std_nationality']);
$std_department = clean($_POST['std_department']);
$do_admission = clean($_POST['do_admission']);

$std_cellno = clean($_POST['std_cellno']);
$std_fcellno = clean($_POST['std_fcellno']);
$std_username = clean($_POST['std_username']);
$std_password = clean($_POST['std_password']);

mysql_query("INSERT INTO student (id,std_name,std_fname,std_mname,std_address,std_dob,std_gender,std_religion,std_nationality,std_department,do_admission,std_cellno,std_fcellno,std_username,std_password)
VALUES ('$id','$std_name','$std_fname','$std_mname','$std_address','$std_dob','$std_gender','$std_religion','$std_nationality','$std_department','$do_admission','$std_cellno','$std_fcellno','$std_username','$std_password')");
mysql_query("INSERT INTO user (id, std_username, std_password)
VALUES ('$id','$std_username','std_password')");
header("location: student.php");
?>

Options: ReplyQuote


Subject
Written By
Posted
Image in not inserting into mysql database but all other is do
February 13, 2016 03:12AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.