Skip to content

Instantly share code, notes, and snippets.

@nilsmunch
Created November 12, 2013 12:53
Show Gist options
  • Save nilsmunch/7430320 to your computer and use it in GitHub Desktop.
Save nilsmunch/7430320 to your computer and use it in GitHub Desktop.
if($_POST["Forfatter"] && $_POST["Title"] && $_POST["Content"]) {
mysql_connect('localhost','root','');
mysql_select_db('phpopgave_PBG') or die(mysql_error());
$newsarticle = array('title' => $_POST["Title"], 'author' => $_POST["Forfatter"],'content'=>$_POST["Content"]);
if($_POST["opret_nyhed"]) {
if (array_search('', $newsarticle) !== false) {
die("Fyld venglist alle felter ud.");
}
if(filter_var($newsarticle['author'], FILTER_SANITIZE_NUMBER_INT)) {
die("Ingen tal i forfatter navn!");
}
$newsQ = 'INSERT INTO nyheder ('.impode(',',array_keys($newsarticle)).',date) VALUES ("'.impode('","',$newsarticle).'",NOW())';
mysql_query($newsQ) or die(mysql_error());
echo "Nyheden er tilføjet";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment