Please I'm a newbie in php and mysql I want you to help me on how to check if value to be inserted into a database is greater than or lesser than, if greater than it should insert pass, thanks.
this the code
$query="select * from ats_question";
$rs=mysql_query("select * from ats_question where test_id=$tid",$cn) or die(mysql_error());
if(!isset($_SESSION[qn]))
{
$_SESSION[qn]=0;
mysql_query("delete from ats_useranswer where sess_id='" . session_id() ."'") or die(mysql_error());
$_SESSION[trueans]=0;
}
else
{
if($submit1=='Next Question' && isset($ans))
{
mysql_data_seek($rs,$_SESSION[qn]);
$row= mysql_fetch_row($rs);
mysql_query("insert into ats_useranswer(sess_id, test_id, que_des, ans1,ans2,ans3,ans4,
true_ans,your_ans)values('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$ans')") or die(mysql_error());
if($ans==$row[7])
{
$_SESSION[trueans]=$_SESSION[trueans]+1;
}
$_SESSION[qn]=$_SESSION[qn]+1;
}
else if($submit=='Get Result' && isset($ans))
{
mysql_data_seek($rs,$_SESSION[qn]);
$row= mysql_fetch_row($rs);
mysql_query("insert into ats_useranswer(sess_id, test_id, que_des, ans1,ans2,ans3,ans4,true_ans,
your_ans) values
('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$ans')") or die(mysql_error());
if($ans==$row[7])
{
$_SESSION[trueans]=$_SESSION[trueans]+1;
}
echo "<h1 class=head1> Result</h1>";
$_SESSION[qn]=$_SESSION[qn]+1;
echo "<Table align=center><tr class=tot><td>Total Question<td> $_SESSION[qn]";
echo "<tr class=tans><td>True Answer<td>".$_SESSION[trueans];
$w=$_SESSION[qn]-$_SESSION[trueans];
echo "<tr class=fans><td>Wrong Answer<td> ". $w;
echo "</table>";
mysql_query("insert into ats_result(login,test_id,grade,score) values
('$login',$tid,grade,$_SESSION[trueans])")
or die(mysql_error());
echo "<h1 align=center><a href=ats_review.php> Review Question</a> </h1>";
unset($_SESSION[qn]);
unset($_SESSION[sid]);
unset($_SESSION[tid]);
unset($_SESSION[trueans]);
exit;
}
}
$rs=mysql_query("select * from ats_question where test_id=$tid",$cn) or die(mysql_error());
if($_SESSION[qn]>mysql_num_rows($rs)-1)
{
unset($_SESSION[qn]);
echo "<h1 class=head1>Some Error Occured</h1>";
session_destroy();
echo "Please <a href=index.php> Start Again</a>";
exit;
}
mysql_data_seek($rs,$_SESSION[qn]);
$row= mysql_fetch_row($rs);
echo "<div align=\"center\" class=\"style2\"><strong> Ats Examination </strong></div>";
echo "<div id=\"\"></div>";
echo"<p id=\"note\"></p>";
echo "<form name=myfm id=myfm1 method=post action=ats_exam.php>";
echo "<table width=100%> <tr> <td width=30> <td> <table border=0>";
$n=$_SESSION[qn]+1;
echo "<tR><td><span class=style2>Que ". $n .": $row[2]</style>";
echo "<tr><td class=style6><input type=radio name=ans value=1>$row[3]";
echo "<tr><td class=style6> <input type=radio name=ans value=2>$row[4]";
echo "<tr><td class=style6><input type=radio name=ans value=3>$row[5]";
echo "<tr><td class=style6><input type=radio name=ans value=4>$row[6]";
if($_SESSION[qn]<mysql_num_rows($rs)-1)
echo "<tr><td><input type=submit name=submit1 value='Next Question'> </form>";
echo "<tr><td><input type=submit name=submit value='Get Result'></form>";
echo "</table></table>";
?>
i want to check if the trueans is greater than 15 it should insert pass if not fail in the grade value
mysql_query("insert into ats_result(login,test_id,grade,score) values
('$login',$tid,grade,$_SESSION[trueans])")
Thanks I have finally get solution to my question this what my code now look like mysql_query("insert into ats_result(login,test_id,score,grade)values('$login','$tid',$_SESSION[trueans],IF($_SESSION[trueans]>=10,'Pass','Fail')"); thanks all for the response and challenges throw to me.
Related
guyz, i want to select radio button for each question.please help me to do that.now i can select only one radio button in a page...... check this link: http://i.stack.imgur.com/UI2vp.png
while($row= mysql_fetch_row($rs)){
echo "<form name=myfm method=post action=Quiz.php>";
echo "<table width=100%> <tr> <td width=30> <td> <table border=0>";
$n=$n+1;
echo "<tr><td><span class=style2>Question ". $n .": $row[2]</style>";
echo "<tr><td class=style8><input type=radio name='ques[$n][]' value=1>$row[3]";
echo "<tr><td class=style8> <input type=radio name='ques[$n][]' value=2>$row[4]";
echo "<tr><td class=style8><input type=radio name='ques[$n][]' value=3>$row[5]";
echo "<tr><td class=style8><input type=radio name='ques[$n][]' value=4>$row[6]";
}
How to fetch the data and store it to mydb...
$query="select * from question";
$rs=mysql_query("select * from question where testid=$tid",$cn) or die(mysql_error());
if($submit=='Get Result')
{
$n=0;
while($row= mysql_fetch_row($rs)){
for($i=0;$i<count($_POST['ques']);$i++)
{
$ans=$_POST['ques'][$n][$i];
echo $ans;
$n=$n+1;
mysql_query("insert into useranswer(sessid, testid, ques, ans1,ans2,ans3,ans4,correctans,yourans) values ('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$ans')") or die(mysql_error());}
}
}
is this works???....
Just replace ques[] with ques[". $n ."][] like this..
while($row= mysql_fetch_row($rs)){
echo "<form name=myfm method=post action=Quiz.php>";
echo "<table width=100%> <tr> <td width=30> <td> <table border=0>";
$n=$n+1;
echo "<tr><td><span class=style2>Question ". $n .": $row[2]</style>";
echo "<tr><td class=style8><input type=radio name='ques[".$n."][]' value=1>$row[3]";
echo "<tr><td class=style8> <input type=radio name='ques[". $n ."][]' value=2>$row[4]";
echo "<tr><td class=style8><input type=radio name='ques[". $n ."][]' value=3>$row[5]";
echo "<tr><td class=style8><input type=radio name='ques[". $n ."][]' value=4>$row[6]";
}
You have to name your radiobuttons for each set.
while($row=mysql_fetch_row($rs)) {
echo "<form name=myfm method=post action=Quiz.php>";
echo "<table width=100%> <tr> <td width=30> <td> <table border=0>";
$n=$n+1;
echo "<tr><td><span class=style2>Question ". $n .": $row[2]</style>";
echo "<tr><td class=style8><input type=radio name='ques".$n."' value=1>$row[3]";
echo "<tr><td class=style8> <input type=radio name='ques".$n."' value=2>$row[4]";
echo "<tr><td class=style8><input type=radio name='ques".$n."' value=3>$row[5]";
echo "<tr><td class=style8><input type=radio name='ques".$n."' value=4>$row[6]";
echo "</table></table></form>"; //AND you should close your tags
}
Also, you should refrain from using mysql_functions, which are deprecated and removed in PHP7.
The mistake is that you are naming all your radio buttons with the same name. That makes all of them in one group. Name each group with three different names. Your problem is solved
It is MCQ exam code. Everything in the code is working because of $p3[8] i am not getting the required output. It is unable to print $p3[8] value also.
<?php
session_start();
error_reporting(1);
include("connect.php");
extract($_POST);
extract($_GET);
extract($_SESSION);
$username = $_SESSION['student'];
if(isset($testid))
{
//$_SESSION[sid]=$subid;
//echo 'sads';
$_SESSION['tid']=$testid;
header("location:test.php");
}
if(!isset($_SESSION['tid']))
{//echo 'qwerwq';
header("location:home.php");
}
?>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Online Exam</title>
<link href="quiz.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
include("head.php");
$rs=mysqli_query($con, "select * from addmcq where test_id=$tid",$cn);
$r = mysqli_num_rows($rs);
if($r==0)
{
//header("location:test2.php");
}
if(!isset($_SESSION['qn']))
{
$_SESSION['qn']=0;
mysqli_query($con, "delete from mcq_user where sess_id='$username' and test_id=$tid") or die(mysql_error());
$_SESSION['trueans']=0;
}
else
{
if($submit=='Next MCQ' && isset($ans))
{
mysqli_data_seek($rs,$_SESSION['qn']);
$row= mysqli_fetch_row($rs);
mysqli_query($con, "delete from mcq_user where sess_id='$username', test_id=$tid and ques=$row[3]");
echo "ww";
mysqli_query($con, "insert into mcq_user(sess_id, test_id, que, ans1,ans2,ans3,ans4,true_ans,your_ans) values ('$username', $tid,'$row[3]','$row[4]','$row[5]','$row[6]', '$row[7]','$row[8]','$ans')") or die(mysql_error());
if($ans==$row[8])
{
$_SESSION['trueans']=$_SESSION['trueans']+1;
}
$_SESSION['qn']=$_SESSION['qn']+1;
}
else if($submit=='Next EA' && isset($ans))
{
mysqli_data_seek($rs,$_SESSION['qn']);
$row= mysqli_fetch_row($rs);
mysqli_query($con, "delete from mcq_user where sess_id='$username', test_id=$tid and ques=$row[3]");
mysqli_query($con, "insert into mcq_user(sess_id, test_id, que, ans1,ans2,ans3,ans4,true_ans,your_ans) values ('$username', $tid,'$row[3]','$row[4]','$row[5]','$row[6]', '$row[7]','$row[8]','$ans')") or die(mysql_error());
if($ans==$row[8])
{
$_SESSION['trueans']=$_SESSION['trueans']+1;
// echo $_SESSION['trueans'];
}
//echo "<h1 class=head1> Result</h1>";
$_SESSION['qn']=$_SESSION['qn']+1;
//$_SESSION['trueans'];
header("location:test2.php");
//echo '<br />Start short answer type questionsclick here';
}
else if($submit=='Previous MCQ' && isset($ans))
{
mysqli_data_seek($rs,$_SESSION['qn']);
$row= mysqli_fetch_row($rs);
mysqli_query($con, "insert into mcq_user(sess_id, test_id, que, ans1,ans2,ans3,ans4,true_ans,your_ans) values ('$username', $tid,'$row[3]','$row[4]','$row[5]','$row[6]', '$row[7]','$row[8]','$ans')") or die(mysql_error());
if($ans==$row[8])
{
$_SESSION['trueans']=$_SESSION['trueans']+1;
}
$_SESSION['qn']=$_SESSION['qn']-1;
}
}
Main problem starts from here $p2 also not printing the value
$rs=mysqli_query($con, "select * from addmcq where test_id=$tid",$cn) or die(mysql_error());
$r = mysqli_num_rows($rs);
$p1= mysqli_query($con, "select * from mcq_user where test_id=$tid and sess_id=$username");
$p2 = mysqli_num_rows($p1);
//echo "qqqqq";
echo $p2;
if($r==0)
{
header("location:test2.php");
}
if($_SESSION['qn']>mysqli_num_rows($rs)-1)
{
//unset($_SESSION[qn]);
//echo "<h1 class=head1>Some Error Occured</h1>";
//session_destroy();
//echo "Please <a href=head.php> Start Again</a>";
exit;
}
mysqli_data_seek($rs,$_SESSION['qn']);
mysqli_data_seek($p1,$_SESSION['qn']);
echo $_SESSION['qn'];
$row= mysqli_fetch_row($rs);
$p3 initialization and displaying it to check.
$p3= mysqli_fetch_row($p1);
echo $p3[8];
//include("tt.html");
echo "<form name=myfm method=post action=test.php>";
echo "<table width=100%> <tr> <td width=30> <td> <table border=0>";
$n=$_SESSION['qn']+1;
echo "<tr><td><span class=style2>Que ". $n .": $row[3]</style>";
echo "<tr><td class=style8><input ";
if($p3[8]==1) echo "checked='checked'";
echo " type=radio name=ans value=1>$row[4]";
echo "<tr><td class=style8> <input ";
if($p3[8]==2) echo "checked='checked'";
echo" type=radio name=ans value=2>$row[5]";
echo "<tr><td class=style8><input ";
if($p3[8]==3) echo "checked='checked'";
echo" type=radio name=ans value=3>$row[6]";
echo "<tr><td class=style8><input ";
if($p3[8]==4) echo "checked='checked'";
echo" type=radio name=ans value=4>$row[7]";
if($n == 1)
echo "<tr><td><input type=submit name=submit value='Next MCQ'><td><tr></form>";
if($_SESSION['qn']<mysqli_num_rows($rs)-1 && $n > 1)
echo "<tr><td><input type=submit name=submit value='Previous MCQ'><input type=submit name=submit value='Next MCQ'><td><tr></form>";
if($_SESSION['qn']== mysqli_num_rows($rs)-1)
echo "<tr><td><input type=submit name=submit value='Previous MCQ'><input type=submit name=submit value='Next EA'><td><tr></form>";
echo "</table></table>";
?>
</body>
</html>
make sure that this query
$p1= mysqli_query($con, "select * from mcq_user where test_id=$tid and sess_id=$username");
will return a record which consists of atleast 8 column...
one more thing
if $username is a string than you should use single quote around it
$p1= mysqli_query($con, "select * from mcq_user where test_id=$tid and sess_id='$username'");
<?php
$status=&$_POST['status'];
$from=&$_POST['date_from'];
$to=&$_POST['date_to'];
$conn=mysqli_connect('localhost','root','','punbus') or die("Database not connected".mysqli_error());
if(isset($_POST['sub'])){
$ins="insert into driver_status(driver_name,status,date_from,date_to)
select Driver_name,'$status','$from','$to' from driver_master";
if(mysqli_query($conn,$ins)){
echo "added";
}
else{
echo "NOT".mysqli_error($conn);
}
}
$sel='select Driver_name from driver_master';
$query=mysqli_query($conn,$sel);
echo "<form action='driver_status.php' method='post'>";
echo "<table cellpadding=5>";
echo "<tr>";
echo "<th>Driver Name</th>";
echo "<th>Status</th>";
echo "<th>From</th>";
echo "<th>To</th>";
echo "</tr>";
while($row=mysqli_fetch_assoc($query)){
echo "<tr>";
echo "<td>".$row['Driver_name']."</td>";
$sel1='select d_status from status';
$query1=mysqli_query($conn,$sel1);
?>
<td>
<select name="status">
<?php
while($row1=mysqli_fetch_assoc($query1)){
$st=$row1['d_status'];
echo "<option value='$st'>$st</option>";
}
?>
</select>
</td>
<?php
echo "</tr>";
}
echo "</table>";
echo '<input type="submit" name="sub" value="Update"/>';
echo "</form>";
?>
That is my code. I want to save option selected from 4 drop down list to mysql. When I submit the form, the value selected from last box are getting saved in all rows of mysql table. Now, please tell me what should I do?
I am getting drop down box values from database table properly so what is the problem?
this is your code.
<?php
$status = $_POST['status'];
$driver_name= $_POST['driver_name'];
$from = $_POST['date_from'];
$to = $_POST['date_to'];
$conn = mysqli_connect('localhost', 'root', '', 'punbus') or
die("Database not connected" . mysqli_error());
if(isset($_POST['sub'])) {
foreach($status as $k=>$s){
$ins = "insert into driver_status(driver_name,status,date_from,date_to) VALUES
('".$driver_name[$k]."','$s','$from','$to')";
if (mysqli_query($conn, $ins)) {
echo "added";
} else {
echo "NOT" . mysqli_error($conn);
}
}
}
$sel = 'select Driver_name from driver_master';
$query = mysqli_query($conn, $sel);
echo "<form action='driver_status.php' method='post'>";
echo "<table cellpadding=5>";
echo "<tr>";
echo "<th>Driver Name</th>";
echo "<th>Status</th>";
echo "<th>From</th>";
echo "<th>To</th>";
echo "</tr>";
while($row=mysqli_fetch_assoc($query)){
echo "<tr><td>".$row['Driver_name']
."<input type=\"hidden\" name=\"driver_name[]\" value=\"".$row['Driver_name']."\"/></td>";
$sel1='select d_status from status';
$query1=mysqli_query($conn,$sel1);
echo "<td><select name=\"status[]\">";
while($row1=mysqli_fetch_assoc($query1)){
echo "<option value=\"".$row1['d_status']."\">".$row1['d_status']."</option>";
}
echo "</select></td></tr>";
}
echo "</table>";
echo '<input type="submit" name="sub" value="Update"/>';
echo "</form>";
?>
this is similar to other textbox
$op="select * from client where active=0";
$op1=mysql_query($op);
echo '<select name="c" id="c" style="width:160px;" required>';
while ($row = mysql_fetch_array($op1))
{
echo $s=$row["c_name"];
if($company!=$s)
{
echo '<option value="'.$row["c_name"].'">'.$row["c_name"].'</option>';
}
}
$c=$_REQUEST['c'];
$sql="insert into project c_name) values('$c')";
$sql1=mysql_query($sql);
I m trying to make a quiz.It's working but not giving the right result. On a correct answer for example answer 1 variable rans should be incremented by one but it is incrementing after submitting the 2nd question, that's why the value of the 10th current answer is not including in the total correct answer.
<?php
require_once("global.inc.php");?>
<form name="test" method="post" action="test.php">
<?php
$qid=(!isset($_POST['q_id'])) ? 0 : $_POST['q_id'];
$rans=(!isset($_POST["rans"])) ? 0 : $_POST["rans"];
$totalquestion=(!isset($_POST["totalquestion"])) ?
0 : $_POST["totalquestion"];
echo $rans;
if(isset($_POST["submit"]))
{
echo "<table align='center' style='border:1px solid silver' width='80%'
bgcolor='green'>";
echo "<tr><td>Total Question Attempt</td><td>",$totalquestion,"</td><tr>";
echo "<tr><td>Correct Answer</td><td>",$rans,"</td></tr>";
echo "<tr><td>Wrong Answer</td><td>",$totalquestion-$rans,"</td></tr>";
echo "<tr><td>Correct Answer Percentage</td> <td>",$rans/$totalquestion*100,"%</td></tr>";
echo "<tr><td>Wrong Answer Percenntage</td><td>",($totalquestion-$rans)/$totalquestion*100,"%</td></tr>";
echo "</table><br><br>";
$query="select * from questions,answers
where questions.q_id=answers.q_id";
echo "<table cellpadding='5px' align='center' style='border:1px
solid silver'>";
echo "<tr><th colspan='4' id='heading'>Online Quiz Test
Question</td></tr>";
$result=mysql_query($query);
while ($row = mysql_fetch_array($result)) {
echo "<tr><td>",$row['q_id'],"</td><td colspan='2'>",$row['question'],"</td></tr><tr><td></td>";
echo "<td colspan='2'>A. ",$row['opt1'],"</td>";
echo "<td colspan='2'>B. ",$row['opt2'],"</td></tr>";
echo "<tr><td></td><td colspan='2'>C. ",$row['opt3'],"</td>";
echo "<td colspan='1'>D. ",$row['opt4'],"</td></tr>";
echo "<tr><td colspan='4' align='right'
style='color:orange'>Correct option is ",strtoupper($row['correct_ans']),"</td></tr>";
echo "<tr><td colspan='4' align='right'
style='color:orange'><hr></td></tr>";
}
echo "</table>";
echo "<p align='right'><a href='#' onclick='window.print()'>Print</a></p>";
echo "<div style='visibility:hidden;display:none'>";
}
?>
<form name="test" method="post" action="test.php">
<?php
if(!isset($a))
{
$a=0;
//unset($_SESSION['score']);
}
if(isset($_POST['next'])) {
$a=$_POST['a'];
$totalquestion=$_POST['totalquestion'];
if(isset($_POST['rans']))
$rans=$_POST['rans'];
}
$sql1="SELECT * FROM questions,answers
where questions.q_id=answers.q_id limit 1 offset $a";
$result=mysql_query($sql1);
$num = mysql_num_rows($result);
echo "<form method='post' action=''>";
if($result) {
while ($row = mysql_fetch_array($result))
{
$qid = $row["q_id"];
$questions = $row["question"];
$opt1 = $row["opt1"];
$opt2 = $row["opt2"];
$opt3 = $row["opt3"];
$opt4 = $row["opt4"];
$correct = $row["correct_ans"];
echo $rans;
?>
<p >Q.<?php echo $qid ?> <?php echo $questions;?></p>
<input type="radio" value="<?php echo $opt1;?>" name="choice"/><?php echo $opt1;?> <br/>
<input type="radio" value="<?php echo $opt2;?>" name="choice"/><?php echo $opt2;?><br/>
<input type="radio" value="<?php echo $opt3;?>" name="choice"/><?php echo $opt3;?><br/>
<input type="radio" value="<?php echo $opt4;?>" name="choice"/><?php echo $opt4;?><br/>
<input type="hidden" value="$answer" name="rightanswer[$qid]"/>
<?php
$b=$a+1;
$sql2="SELECT * FROM questions where q_id=$qid-1 ";
$result2=mysql_query($sql2);
while ($row2 = mysql_fetch_array($result2)) {
$ans=$row2['correct_ans'];
}
if(isset($_POST['choice'])) {
if($ans==$_POST['choice']){
//echo "<input type='hidden' name='rans' value='".($rans+1). "'>";
$rans=$rans+1;
}
else {
//echo "<input type='hidden' name='rans' value='" . $rans . "'>";
$rans=$rans;
}
}
//$query="select correct_ans from questions where q_id='$qid'";
//$result=mysql_query($query);
//while ($row = mysql_fetch_array($result)) {
//echo $row['correct_ans'];
echo "<input type='hidden' value='$b' name='a'>";
echo "<input type='hidden' value='count' name='count'>";
echo "<input type='hidden' name=qid value='$qid'>";
echo "<input type='hidden' name='totalquestion' value='".$totalquestion+1)."'>";
echo "<input type='hidden' name='rans' value='" . $rans . "'>";
echo "<input type='submit' name='next' value='next'> ";
echo "<input type='submit' name='submit' value='submit'><br><br>";
echo "</form>";
}
}
?>
Okay, your code is a bit of a mess.
You have random tautologies (like the $rans=$rans; which does absolutely nothing. If the answerer clicks "next" you're assigning $totalquestion twice. Definitely take a good, hard look and refactor this page.
But the answer to your question is probably because you're checking to see if they entered in the right answer at the bottom of the code -- after you've presented the results or the next question.
You've utilized the scripting capabilities of PHP without touching on any functions so it will evaluate top to bottom.
I'd move everything around: Move the handler for "next" to the top, underneath your default variable assignments, then put the check for right answer underneath that, then do the presentation of the next question, then the "submit"handler.
I'd break up the different units into functions for readability and reusability, also. For example, make a function to print out the specified question, make another one to validate the user entered in the right answer.
I'm having a problem to upload images using a form. This is my form code :
<?php
echo '<table width="70%">';
echo '<tr>';
echo '<td>Add Promotion</td>';
echo '</tr>';
echo "<form action='addpromotion_post.php' method='post' enctype='multipart/form-data' name='form1' id='form1'>";
echo '<tr>';
echo "<td> </td>";
echo '</tr>';
echo '<tr>';
echo "<td>Promotion :</td>";
echo "<td><textarea name='promotion1' rows='2'></textarea></td>";
echo '</tr>';
echo '<tr>';
echo "<td>Valid From :</td>";
echo "<td><input type='text' size='40' name='validfrom1' value='promotion' /></td>";
echo '</tr>';
echo '<tr>';
echo "<td>Add Picture :</td>";
echo "<td><input type='file' name='pic1' id='pic1' /></td>";
echo '</tr>';
echo '<tr>';
echo "<td>Add Picture :</td>";
echo "<td><input type='file' name='pic2' id='pic2' /></td>";
echo '</tr>';
echo '<tr>';
echo "<td>Add Picture :</td>";
echo "<td><input type='file' name='pic3' id='pic3' /></td>";
echo '</tr>';
echo '<tr>';
echo "<td> </td>";
echo '</tr>';
echo'<tr>
<td colspan="3" align="center"><input type="submit" name="button" id="button" value="Submit" /></td>
</tr>
</table>
</form>';
This is my post code :
<?php
//session_start();
include_once("connection.php");
$promotion= $_POST["promotion1"];
$validfrom= $_POST["validfrom1"];
$promotion= mysql_real_escape_string($promotion);
$validfrom= mysql_real_escape_string($validfrom);
$sql = "insert into promotion(proid, promotion, validfrom) values ('', '$promotion', '$validfrom')";
mysql_query($sql) or die ("Error in query: $sql");
$lastid=mysql_insert_id();
$file = "slider_imagesClient/".$lastid."/";
mkdir($file);
$pic1 = $_FILES['pic1']['name'];
$pic2 = $_FILES['pic2']['name'];
$pic3 = $_FILES['pic3']['name'];
print_r($pic1);
$ext1 = pathinfo($pic1,PATHINFO_EXTENSION);
$ext2 = pathinfo($pic2,PATHINFO_EXTENSION);
$ext3 = pathinfo($pic3,PATHINFO_EXTENSION);
//$fileEnote = $_FILES['eNote']['name'];
$path1 = $file.$pic1.'.'.$ext1;
$path2 = $file.$pic2.'.'.$ext2;
$path3 = $file.$pic3.'.'.$ext3;
print_r($path1);
$ory1 = $sfish.$pic1.'.'.$ext1;
$ory2 = $sfish.$pic2.'.'.$ext2;
$ory3 = $sfish.$pic3.'.'.$ext3;
if (!file_exists($path1))
{
move_uploaded_file ($_FILES['pic1']['tmp_name'], $path1) or die ("Error");
}
if (!file_exists($path2))
{
move_uploaded_file ($_FILES['pic2']['tmp_name'], $path2) or die ("Error");
}
if (!file_exists($path3))
{
move_uploaded_file ($_FILES['pic3']['tmp_name'], $path3) or die ("Error");
}
if(!empty($pic1)) {
$sql5= "INSERT INTO pimage (id, proid, image)
VALUES ('', $lastid, '$ory1')";
mysql_query($sql5) or die ("Error in query: $sql5");
}
else
{
$not = "not good";
print_r($not);
}
if(!empty($pic2)) {
$sql5= "INSERT INTO image (resID, image)
VALUES ($lastid, '$ory2')";
mysql_query($sql5) or die ("Error in query: $sql5");
}
else
{
$not = "not good";
print_r($not);
}
if(!empty($pic3)) {
$sql5= "INSERT INTO image (resID, image)
VALUES ($lastid, '$ory3')";
mysql_query($sql5) or die ("Error in query: $sql5");
}
else
{
$not = "not good";
print_r($not);
}
?>
print_r($pic1) are not outputting anything. print_r($path1) just outputting slider_imagesClient/50/.
How can I solve this? I'm suspecting error in the form but I couldn't find any. Thank you very much :D. Really appreciate your help.
echo '<table width="70%">';
echo '<tr>';
echo '<td>Add Promotion</td>';
echo '</tr>';
echo "<form action='addpromotion_post.php' method='post'
enctype='multipart/form-data' name='form1' id='form1'>";
change like this
echo "<form action='addpromotion_post.php' method='post' enctype='multipart/form-data' name='form1' id='form1'>";
echo '<table width="70%">';
echo '<tr>';
echo '<td>Add Promotion</td>';
echo '</tr>';