ANFAL
ANFAL

Reputation: 9

How can I add images to SQL Server in PHP

I am designing a form that enables the user to add more than one image.

I don't know exactly where the error is.

The code works and adds the images to my "images-design" folder.

But the name of the pictures is not added to the database and I do not see any errors?

I use SQL Server

This is the table

this is the table

This is the form (DesignSend.php)

<form action="imagesAdded.php" method="post" enctype="multipart/form-data" >
<input type="hidden" name="size5" value="10000000">

<label> image(1) </label>
<br>
<input type="file" name="image1"/>
    <br><br>
<label> image(2)</label>
<br>
<input type="file" name="image2"/>
<br><br>
<label> image(3)</label>
<br>
<input type="file" name="image3"/>
<br><br>
<label> image(4)</label>
<br>
<input type="file" name="image4"/>
<br><br>
<label> image(5)</label>
<br>
<input type="file" name="image5"/>
<br> <br>
<label> note :</label>
<br>
<textarea name="noteTo" cols="40" row="4" placeholder="add note here ..."></textarea>
<br>
<input type="submit" name="upload" value="upload images" >
</form>

and this the action codes in (imagesAdded.php):

<?php
  require_once "connect.php";
  session_start();
  $us=$_SESSION['usern'];
  if(isset($_SESSION['usern'])) {
    $cust_phone = $_POST['phoneid'];
if(isset($_POST['upload'])){
    $cust_phone = $_POST['phoneid'];
  $path1="./design-images/".basename($_FILES['image1']['name']);
  $path2="./design-images/".basename($_FILES['image2']['name']);
  $path3="./design-images/".basename($_FILES['image3']['name']);
  $path4="./design-images/".basename($_FILES['image4']['name']);
  $path5="./design-images/".basename($_FILES['image5']['name']);

  $imgA=$_FILES['image1']['name'];  
  $imgB=$_FILES['image2']['name'];
  $imgC=$_FILES['image3']['name'];
  $imgD=$_FILES['image4']['name'];
  $imgE=$_FILES['image5']['name'];
  $noteTc=$_POST['noteTo'];
  //$phoneNumber=$_POST['phoneid'];
  $query2 = "INSERT INTO dbo.design_cust (design_a, design_b, design_c,design_d,design_e,textn)
  VALUES(?, ? , ? , ? , ? )";
$params2 = array($imgA, $imgB,$imgC,$imgD,$imgE,$noteTc);                       
$result3 = sqlsrv_query($conn,$query2,$params2);
if(move_uploaded_file($_FILES['image1']['tmp_name'],$path1)
&& move_uploaded_file($_FILES['image2']['tmp_name'],$path2)
&& move_uploaded_file($_FILES['image3']['tmp_name'],$path3)
&& move_uploaded_file($_FILES['image4']['tmp_name'],$path4)
&& move_uploaded_file($_FILES['image5']['tmp_name'],$path5)
){
    $msg="<p>images uploaded</p>";
    echo $msg;
   
    
    }else {
 $msg="<p>there was a problem upload image </p>";
    echo $msg;
    }
    }
    }
    ?>
     

Can someone help me please?

Upvotes: 0

Views: 110

Answers (1)

Arun Vishwakarama
Arun Vishwakarama

Reputation: 166

Just replace this

VALUES(?, ? , ? , ? , ? )

With

VALUES(?, ? , ? , ? , ? ,?)

Because parameters count passed are 6 and question marks are 5

Should solve that

Upvotes: 1

Related Questions