Im having some trouble uploading an image with php to phpmyadmin.
Here is my markup so far.
<form method="post">
<p>Event Date<span> - eg "23" for the 23rd</span><br /> <input type="text" name="eventDate" maxlength="2" required /> </p>
<p>Event Month<span> - eg "Mar" for March</span> <br /><input type="text" name="eventMonth" maxlength="3" required /> </p>
<p>Artist Image <br /><input type="file" name="artistImage" required /> </p>
<p>Artist Name <br /><input type="text" name="artistName" maxlength="30" required /> </p>
<p>Location <br /><input type="text" name="location" maxlength="30" required /> </p>
<p>Price <br /><input type="text" name="price" maxlength="10" required /> </p>
<p>Time <br /><input type="text" name="time" maxlength="10" required /> </p>
<input id="eventSubmit" type="submit" name="submitEvent" />
</form>
and here is my php code
`
if(isset($_POST['submitEvent'])){
$addEventDate = $_POST['eventDate'];
$addEventMonth = $_POST['eventMonth'];
$addEventName = $_POST['artistName'];
$addEventLocation = $_POST['location'];
$addEventPrice = $_POST['price'];
$addEventTime = $_POST['time'];
$addEventImg = $_FILES['artistImage']['name'];
$temp_name1 = $_FILES['artistImage']['tmp_name'];
move_uploaded_file($temp_name1, "img/$addEventImg");
$ticket= 1;
$insert_product = "INSERT INTO events (eventDate,eventMonth,artistImg,artistName,location,price,time,buyTicket) VALUES ('$addEventDate','$addEventMonth','$addEventImg','$addEventName','$addEventLocation','$addEventPrice','$addEventTime','$ticket')";
$run_product = mysqli_query($con,$insert_product);
echo mysqli_error($con);
if($run_product){
echo "<script>alert('Product has been inserted.');</script>";
echo "<script>window.open('admin.php','_self');</script>";
}
}
?>`
I have set the database up to take the image as a blob here is a picture of my database
and this is the code that is rendering the products onto the events page.
<?php
$get_events = "select * from events";
$run_events = mysqli_query($con,$get_events);
while($row_events = mysqli_fetch_array($run_events)){
$eventDate = $row_events['eventDate'];
$eventMonth = $row_events['eventMonth'];
$artistImg = $row_events['artistImg'];
$artistName = $row_events['artistName'];
$location = $row_events['location'];
$price = $row_events['price'];
$time = $row_events['time'];
$buyTicket = $row_events['buyTicket'];
echo "
<div class='eventBox'>
<div class='dateBanner'>
<p><span>$eventDate</span><br />$eventMonth</p>
</div>
<img src='img/$artistImg' alt='event image' />
<div class='eventDetails'>
<h2>$artistName</h2>
<p><span>Location</span> <br /> $location<br /><br /><span>Ticket Price</span> <br /> £$price<br /><br /><span>Time</span> <br />$time<br /><br /></p>
</div>
<div class='PurchaseTicket'>
<h3>Buy Ticket</h3>
</div>
</div>
";
}
?>
This works for everything apart from the image. The image just displays the alt tag not the actual image. It also doesn't save the image in the folder either.
If anyone could help I'd really appreciate it!!
Thanks
Related
So I have a form that users fill out and it adds to a database. Everything works except for the date. The date shows up as 0000-00-00. Currently, I'm using a datepicker, but the date wasn't showing up even when the user had to type it in...so that shouldn't be the issue.
<form name="Add" id="Add" method="post" action="programadd.php">
<p>Program Name:
<input name="program" type="text" id="program" />
</p>
<p>Air Date
<input name="airdate" type="text" id="airdate" />
</p>
<p>Description
<input name="description" type="text" id="description" s />
</p>
<p>Production
<input name="production" type="text" id="production" />
</p>
<p>Promotions
<input name="promotion" type="text" id="promotion" />
</p>
<p>Community
<input name="community" type="text" id="community" />
</p>
<p>Web
<input name="web" type="text" id="web" />
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
And here's the code that adds it to the database:
<?php require_once('connect-db.php');
$program = $_POST['program'];
$airdate = $_POST['airdate'];
$description = $_POST['description'];
$production = $_POST['production'];
$promotion = $_POST['promotion'];
$community = $_POST['community'];
$web = $_POST['web'];
if (mysql_query ("INSERT INTO calendar(program, airdate, description, production, community, promotion, web) VALUES
('$program', '$airdate', '$description','$production', '$promotion', '$community', '$web')"))
{ echo "Program successfully added to the database <br />";
}
else {
die(mysql_error());
}
require_once("db_connx_close.php");
?>
One other question, how do I get the date to display as Month/Date/Year, instead of the reverse?
$date = date('Y-m-d', strtotime($_POST['airdate']));
can anyone help me find the code thats causing my code not to work? my code wont update... ive been debuging this code for 3hours already stil cant fix it :(...i need your help guys.
php code:
<?php
if(isset($_GET['gogo'])){
include('include/connect.php');
$batchcode = $_GET['code'];
$sql = mysql_query("SELECT * FROM score WHERE batchcode = '".$batchcode."' ");
if($sql) {
while($rows = mysql_fetch_array($sql)){
$id[] = $rows['id'];
$name[] = $rows['name'];
$score1[] = $rows['score1'];
$score2[] = $rows['score2'];
$other_qual[] = $rows['score3'];
$interview[] = $rows['score4'];
$total[] = $rows['total'];
}
}
}
?>
<?php
if(isset($_POST['update'])){
include('include/connect.php');
//1
$u1id = $_POST['id1'];
$u1name = $_POST['name1'];
$u1score1 = $_POST['optA1'];
$u1score2 = $_POST['optB1'];
$u1other_qual = $_POST['other_qual1'];
$u1interview = $_POST['interview1'];
$u1total = $_POST['total1'];
//2
$u2id = $_POST['id2'];
$u2name = $_POST['name2'];
$u2score1 = $_POST['optA2'];
$u2score2 = $_POST['optB2'];
$u2other_qual = $_POST['other_qual2'];
$u2interview = $_POST['interview2'];
$u2total = $_POST['total2'];
//1
mysql_query("UPDATE score SET score1='$u1score1', score2='$u1score2', total='$u1total' WHERE id='$u1id'");
//2
mysql_query("UPDATE score SET score1='$u2score1', score2='$u2score2', total='$u2total' WHERE id='$u2id'");
header("Location: index.php");
}
?>
html code:
<form method="get">
<form method="post">
Search batchcode: <input type="text" name="code" id="query" /><input type="submit" value="Go" name="gogo" /><br />
<table>
<tr>
<td>
ID: <br />
<input type="text" name="id1" value="<?php if(empty($id[0])){$id[0] = array(NULL);}else{echo $id[0];} ?>" readonly /> <br />
<input type="text" name="id2" value="<?php if(empty($id[1])){$id[1] = array(NULL);}else{echo $id[1];} ?>" readonly /> <br />
</td>
<td>
Name: <br />
<input type="text" name="name1" value="<?php if(empty($name[0])){$name[0] = array(NULL);}else{echo $name[0];} ?>" readonly /> <br />
<input type="text" name="name2" value="<?php if(empty($name[1])){$name[1] = array(NULL);}else{echo $name[1];} ?>" readonly /> <br />
</td>
<td>
Score 1: <br />
<input type="text" name="optA1" value="<?php if(empty($score1[0])){$score1[0] = array(NULL);}else{echo $score1[0];} ?>" onchange="optTotal1()" /> <br />
<input type="text" name="optA2" value="<?php if(empty($score1[1])){$score1[1] = array(NULL);}else{echo $score1[1];} ?>" onchange="optTotal2()" /> <br />
</td>
<td>
Score 2: <br />
<input type="text" name="optB1" value="<?php if(empty($score2[0])){$score2[0] = array(NULL);}else{echo $score2[0];} ?>" onchange="optTotal1()" /> <br />
<input type="text" name="optB2" value="<?php if(empty($score2[1])){$score2[1] = array(NULL);}else{echo $score2[1];} ?>" onchange="optTotal2()" /> <br />
</td>
<td>
Other Qualification: <br />
<input type="text" name="other_qual1" value="<?php if(empty($other_qual[0])){$other_qual[0] = array(NULL);}else{echo $other_qual[0];} ?>" readonly /> <br />
<input type="text" name="other_qual2" value="<?php if(empty($other_qual[1])){$other_qual[1] = array(NULL);}else{echo $other_qual[1];} ?>" readonly /> <br />
</td>
<td>
Interview: <br />
<input type="text" name="interview1" value="<?php if(empty($interview[0])){$interview[0] = array(NULL);}else{echo $interview[0];} ?>" readonly /> <br />
<input type="text" name="interview2" value="<?php if(empty($interview[1])){$interview[1] = array(NULL);}else{echo $interview[1];} ?>" readonly /> <br />
</td>
<td>
Total: <br />
<input type="text" name="total1" value="<?php if(empty($total[0])){$total[0] = array(NULL);}else{echo $total[0];} ?>" readonly onKeyUp="optTotal1()" /> <br />
<input type="text" name="total2" value="<?php if(empty($total[1])){$total[1] = array(NULL);}else{echo $total[1];} ?>" readonly onKeyUp="optTotal2()" /> <br />
</td>
</tr>
</table>
<input type="submit" value="update" name="update" />
</form>
</form>
You cannot do a GET and POST at the same time. Use one or the other..
In your HTML remove the <form method="get"> and the corresponding </form> and just use POST. (<form method="post">)
See this: Post and get at the same time in php
So then in your PHP, change GET to POST like so:
if(isset($_POST['gogo'])){
include('include/connect.php');
$batchcode = $_POST['code'];
$sql = mysql_query("SELECT * FROM score WHERE batchcode = '".$batchcode."' ");
...
EDIT:
Or alternatively, you could keep your php code the same the way you have it and just make it 2 seperate forms in your HTML,.. The search form using GET and the other form using POST
So HTML would be this:
<form method="get">
Search batchcode: <input type="text" name="code" id="query" /><input type="submit" value="Go" name="gogo" /><br />
</form>
<form method="post">
<table>
<tr>
<td>
ID: <br />
<input type="text" name="id1" value="<?php if(empty($id[0])){$id[0] = array(NULL);}else{echo $id[0];} ?>" readonly /> <br />
<input type="text" name="id2" value="<?php if(empty($id[1])){$id[1] = array(NULL);}else{echo $id[1];} ?>" readonly /> <br />
</td>...
...
</form>
If your code won't update then it is very likely you are updating the wrong files. Make sure that you are updating the files on the server or even better updating the files on your local drive and then uploading them to the server.
Check that you have permissions to upload to the correct place too. Might be that your uploads are failing because of bad permissions.
I am trying to execute this html form code, the php script is not executing properly. Can you point out the problems?
<form action="form.php" method="post">
<p>
<input type="text" name="titles[]" /><br />
<textarea name="languages[]" ></textarea><br />
</p>
<p>
<input type="text" name="titles[]" /><br />
<textarea name="languages[]" ></textarea><br />
</p>
php script
<?php
if (isset($_POST['submit']))
{
$k=0;
foreach($_POST['languages'] as $language) {
echo $language = htmlentities($language);
echo $title = $_POST['titles'][$k];
$k++;
}
}
?>
HTML
<form action="form.php" method="post">
<p>
<input type="text" name="titles[]" /><br />
<textarea name="languages[]" ></textarea><br />
</p>
<p>
<input type="text" name="titles[]" /><br />
<textarea name="languages[]" ></textarea><br />
</p>
<input type="submit" name="submit" id="submit" value="Submit">
</form>
PHP
<?php
if (isset($_POST['submit']))
{
foreach($_POST['languages'] as $key => $language) {
echo $language = htmlentities($language);
echo " -- ";
echo $title = $_POST['titles'][$key];
echo "<br/>";
}
}
?>
i want to store an image in database not by inserting but by updating (by using UPDATE query).
Everything else is updated successfully but its not storing image. I'm using medium blob data type to store image.
Here is my code:
update-profile.php:
<form id="form" method="post" action="update-profile-action.php" enctype="multipart/form-data">
<label for="Fname">First Name:</label> <input type="text" id="Fname" class="text" value="<?php echo $firstname; ?>" name="Fname" /> <br /><br />
<label for="Lname">Last Name:</label> <input type="text" id="Lname" class="text" value="<?php echo $lastname; ?>" name="Lname" /><br /> <br />
<?php
if ($_SESSION["type"]=="T")
{
?>
<label>Profile Image:</label> <input type="file" name="image" value="" /><br /> <br />
<label>Qualification:</label><textarea name="qualification" class="text" id="qualification"><?php echo $qualification;?></textarea><br /><br />
<label>Education & Teaching History:</label> <textarea name="briefintro" class="text" id="intro"><?php echo $briefintro; ?></textarea><br /><br />
<?php
}
?>
<input type="submit" class="mybutton" value="Update Profile" />
</form>
update-profile-action.php:
<?php include("../includes/config.php");?>
<?php
$Fname=$_POST["Fname"];
$Lname=$_POST["Lname"];
$image=$_POST["profileimg"];
$briefintro=$_POST["briefintro"];
$qualification=$_POST["qualification"];
$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db($dbname, $con);
$query=("UPDATE accounts SET firstname='".$Fname."' , lastname='".$Lname."' , profileimg='".$image."' , briefintro='".$briefintro."', qualification='".$qualification."' WHERE id=".$_SESSION['id']);
$result = mysql_query($query);
header("Location: update-profile.php?status=3");
mysql_close($con);
?>
i copied only the related data from update-profile.php to making it more easy to read :)
any kind of help will be appreciated :)
Two problems:
You do not have an id for the input tag for the file. You need to change <input type="file" name="image" value="" /> to <input type="file" name="image" value="" id = "profileimage" />
Secondly you access files not via $_POST but rather via $_FILES.
I can't seem to figure out how to make this script write data to the section of the file. Here is an excerpt of the code that applies:
$file = $url.'.php';
if (!$file_handle = fopen($file,"a+"))
{
echo $lang['cannot_open_file'];
}
if (!fwrite($file_handle,stripslashes(html_entity_decode($data))))
{
echo $lang['file_is_not_writable'];
}
fclose($file_handle);
echo ($lang['success']);
echo ('<meta http-equiv="Refresh" content="4;url='.$url.'.php" />');
}
}
?>
<form action="<?php echo $url;?>.php" method="post">
<?php echo $lang['name']?> <span style="font-weight:100;">(<?php echo $lang['required']?>)</span>:<br />
<input class="textfield" type="text" name="name" value="" /><br />
<?php echo $lang['website']?> <span style="font-weight:100;">(<?php echo $lang['without_http'];?>)</span>:<br />
<input class="textfield" type="text" name="site" value="" /><br />
<?php echo $lang['message']?>:<br />
<textarea class="textarea" rows="2" cols="25" name="message"></textarea><br />
<img src="captcha-image.php" alt="Image verification" /> <br />
<?php echo $lang['value_from_the_image'];?>:<br />
<input class="textfield" type="text" name="img_ver" value="" /><br />
<input type="reset" name="reset" value="<?php echo $lang['reset'];?>" />
<input type="submit" name="send" value="<?php echo $lang['send'];?>" />
</form>
<hr>
<h3>Comments:</h3>
<!--comments -->
<?php include('../templates/footer.php'); ?>
Would anyone mind helping me out on this one? It would be much appreciated.
Use file get contens to retrieve the contens first.
Then use preg_replace to find where or what you want to be replaced.
Then rewrite the file with the new content.