I’m currently embarked in my first web project, and I think I may have taken on too much without the proper experience in PHP + WordPress.
What I’m trying to achieve with this project is to have a website where we have two different users, and 1 user can post custom post types through a form, while the other user can view them in a custom feed for that post type. I’m using WordPress as the CMS, and I’ve tried to solve this problem using WordPress and Custom Post Types. What I realized though, is that it still required a fair amount of PHP experience to put the Post Type in the WordPress loop and display it with the right information.
Someone told me that I should be able to go around WordPress, work in the backend and create everything there, so I connected to the MySQL Database and made some variables for the information that I wanted in my post type.
I have three files this far:
The template file for the submissions:
$
<form action="http://videsignerweb.no/postform.php" enctype="multipart/form-data" method="post" id="oppdragform">
<input type="text" id="oppdragtittel" name="tittel" />
<br>
<select name="oppdragstype" id="oppdragdropdown">
<option value="idephoto">Idé til Photoshop</option>
<option value="idehtml">Idé til HTML/CSS</option>
<option value="ideword">Idé til WordPress</option>
<option value="photohtml">Photoshop til HTML/CSS</option>
<option value="photoword">Photoshop til WordPress</option>
<option value="htmlword">HTML/CSS til WordPress</option>
</select>
<br>
<input type="radio" name="seo" value="Ja"/>Ja + kr 4000,-
<br>
<input type="radio" name="seo" value="Nei"/>Nei
<br><br>
<input type="radio" name="java" value="Ja"/>Ja + kr 1500,-
<br>
<input type="radio" name="java" value="Nei"/>Nei
<br>
<input type="file" name="psdfil" />
<br>
<input type="textarea" name="prosjektinfo" value="" />
<br>
<input type="date" name="dato" value="" />
<br>
<input type="submit" name="submit" value="Last opp ditt oppdrag" />
</form>
The postform.php:
$
<html>
<body>
<?php
$connect = mysql_connect('videsignerweb.mysql.domeneshop.no', 'videsignerweb', '25zscHxj') or die ("Connection Faliure");
mysql_select_db("videsignerweb") or die ("Database failure");
$tittel = $_POST['tittel'];
$oppdragstype = $_POST['oppdragstype'];
$seo = $_POST['seo'];
$java = $_POST['java'];
$prosjektinfo = $_POST['prosjektinfo'];
$dato = $_POST['dato'];
echo $tittel;
echo $oppdragstype;
echo $seo;
echo $java;
echo $prosjektinfo;
echo $dato;
move_uploaded_file($_FILES["psdfil"]["tmp_name"],
"uploads/" . $_FILES["psdfil"]["name"]);
$filelocation="uploads/" . $_FILES["psdfil"]["name"];
$queryreg = mysql_query("INSERT INTO oppdrag VALUES ('', '$tittel', '$oppdragstype', '$seo', '$java', '$prosjektinfo', '$dato', '$filelocation')");
if ($_FILES["psdfil"]["error"] > 0)
{
echo "Error: " . $_FILES["psdfil"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["psdfil"]["name"] . "<br />";
echo "Type: " . $_FILES["psdfil"]["type"] . "<br />";
echo "Size: " . ($_FILES["psdfil"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["psdfil"]["tmp_name"];
}
?>
</body>
</html>
and the Template for displaying the post types:
$
<?php
$connect = mysql_connect('videsignerweb.mysql.domeneshop.no', 'videsignerweb', '25zscHxj') or die ("Connection Faliure");
mysql_select_db("videsignerweb") or die ("Database failure");
$sSQL = "SELECT * FROM oppdrag";
$rsResult = mysql_query($sSQL);
while ($row = mysql_fetch_array($rsResult))
{
echo ("
<header> {$row['tittel']}</header>
<article> <br/>
{$row['info']}
<br/>
{$row['type']}Ü
</article>
<footer>{$row['dato']}</footer>
");
}
?>
If anyone could help me with this, I’d be eternally grateful, I’m really unsure where to go from here, and I’m having troubles finding the right information through search.
Cheers,
Michael
The key statement is this:
By “user” do you mean the people using the admin section of the site, or the user groups who will use the front-end of the site?
For most things WordPress related you shouldn’t need to be playing around with SQL statements at all and be using built in wrapper functions instead.