Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display custom information using PHP in Wordpress?
    text
    copied!<p>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.</p> <p>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.</p> <p>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.</p> <p>I have three files this far:</p> <p>The template file for the submissions:</p> <pre><code>$ &lt;form action="http://videsignerweb.no/postform.php" enctype="multipart/form-data" method="post" id="oppdragform"&gt; &lt;input type="text" id="oppdragtittel" name="tittel" /&gt; &lt;br&gt; &lt;select name="oppdragstype" id="oppdragdropdown"&gt; &lt;option value="idephoto"&gt;Idé til Photoshop&lt;/option&gt; &lt;option value="idehtml"&gt;Idé til HTML/CSS&lt;/option&gt; &lt;option value="ideword"&gt;Idé til Wordpress&lt;/option&gt; &lt;option value="photohtml"&gt;Photoshop til HTML/CSS&lt;/option&gt; &lt;option value="photoword"&gt;Photoshop til Wordpress&lt;/option&gt; &lt;option value="htmlword"&gt;HTML/CSS til Wordpress&lt;/option&gt; &lt;/select&gt; &lt;br&gt; &lt;input type="radio" name="seo" value="Ja"/&gt;Ja + kr 4000,- &lt;br&gt; &lt;input type="radio" name="seo" value="Nei"/&gt;Nei &lt;br&gt;&lt;br&gt; &lt;input type="radio" name="java" value="Ja"/&gt;Ja + kr 1500,- &lt;br&gt; &lt;input type="radio" name="java" value="Nei"/&gt;Nei &lt;br&gt; &lt;input type="file" name="psdfil" /&gt; &lt;br&gt; &lt;input type="textarea" name="prosjektinfo" value="" /&gt; &lt;br&gt; &lt;input type="date" name="dato" value="" /&gt; &lt;br&gt; &lt;input type="submit" name="submit" value="Last opp ditt oppdrag" /&gt; &lt;/form&gt; </code></pre> <p>The postform.php:</p> <pre><code> $ &lt;html&gt; &lt;body&gt; &lt;?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"] &gt; 0) { echo "Error: " . $_FILES["psdfil"]["error"] . "&lt;br /&gt;"; } else { echo "Upload: " . $_FILES["psdfil"]["name"] . "&lt;br /&gt;"; echo "Type: " . $_FILES["psdfil"]["type"] . "&lt;br /&gt;"; echo "Size: " . ($_FILES["psdfil"]["size"] / 1024) . " Kb&lt;br /&gt;"; echo "Stored in: " . $_FILES["psdfil"]["tmp_name"]; } ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and the Template for displaying the post types:</p> <pre><code> $ &lt;?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 (" &lt;header&gt; {$row['tittel']}&lt;/header&gt; &lt;article&gt; &lt;br/&gt; {$row['info']} &lt;br/&gt; {$row['type']}Ü &lt;/article&gt; &lt;footer&gt;{$row['dato']}&lt;/footer&gt; "); } ?&gt; </code></pre> <p>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.</p> <p>Cheers, Michael</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload