<?php
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("corporate_personnel_order_for_2016") or die(mysql_error());
@$mode = $_POST['mode'];
@$OBS_NUMBER = $_POST['OBS_NUMBER'];
@$NAME = $_POST['NAME'];
@$PURPOSE = $_POST['PURPOSE'];
@$DATE_OF_OB = $_POST['DATE_OF_OB'];
@$DESTINATION = $_POST['DESTINATION'];
@$SELF = $_SERVER['PHP_SELF'];
if(isset($_POST["submit"])){
if(getimagesize($_FILES['fileToUpload']['tmp_name']) == FALSE)
{
echo "Please select an image.";
}
else
{
$image= addslashes($_FILES['fileToUpload']['tmp_name']);
//$name= addslashes($_FILES['image']['name']);
$image= file_get_contents($image);
$image= base64_encode($image);
saveimage($OBS_NUMBER, $NAME, $PURPOSE, $DATE_OF_OB,$DESTINATION,$image);
}
function saveimage($OBS_NUMBER, $NAME, $PURPOSE, $DATE_OF_OB,$DESTINATION,$image)
{
$con=mysql_connect("localhost","root","");
mysql_select_db("corporate_personnel_order_for_2016",$con);
mysql_query ("INSERT INTO obs (OBS_NUMBER, NAME, PURPOSE,DATE_OF_OB,DESTINATION,IMAGESOBS) VALUES ('$OBS_NUMBER', '$NAME', '$PURPOSE','$DATE_OF_OB','$DESTINATION', '$image' )");
}
}
print '<script type="text/javascript">';
print 'alert("Add Successful")';
print '</script>';
?>
答案 0 :(得分:1)
请试试这个:
<?php
$con=mysqli_connect('127.0.0.1','root','');
if(!$con)
{
echo "Could not connect to the server";
}
if(! mysqli_select_db($con,'database_name'))
{
echo "Cannot select the database";
}
答案 1 :(得分:0)
试试这个:
<?php
$con = mysqli_connect("127.0.0.1","root","654321","testV2") or die("Some error occurred during connection " . mysqli_error($con));
// Write query
$sql = "INSERT INTO MyGuests (firstname, lastname, email)VALUES ('John', 'Doe', 'john@example.com')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// Close the connection
mysqli_close($con);
?>
答案 2 :(得分:0)
尝试执行你在mysql中手动插入查询,看看你是否收到错误
也尝试只有一个mysql_connect和mysql_select_db