-
Posts
110 -
Joined
-
Last visited
Everything posted by bullbreed
-
Yes, t said You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES 'shorts')' at line 1
-
Hi. php newbie here. Could someone please tell me the error in this syntax if ($existcat != ""){ $queryreg = mysql_query("INSERT INTO articles (`article_section` VALUES '$existcat')");echo mysql_error(); }else{ if ($existcat = 'None'){ $queryreg = mysql_query("INSERT INTO articles (`article_section` VALUES '$newcat')");echo mysql_error(); } }
-
I think this bit isn't correct if ($existcat !== 'None'){ $queryreg = mysql_query("INSERT INTO articles (`article_cat` VALUES '$existcat')"); }else{ if ($existcat == 'None'){ $queryreg = mysql_query("INSERT INTO articles (`article_cat` VALUES '$newcat')"); } }
-
Wow. Thanks for that it worked a dream. I really appreciate your help. Thank you. Also when the user creates a news article they have an option to either create the article category or select it from the menu that was just sorted, (Thanks again) I had a go at the code but I cant get the article section to go in the database What if I made 2 form elements exist_cat - This would be a drop down menu form field with a value of 'None' new_cat - This would be an input text field which would have no value Then I could say If exist_cat doesn't = 'None' Insert exist_cat in to the database If exits_cat does = 'None' Insert into new_cat in to the database Then check the rest of the form and insert that in to the database I had a go at writing the script. Could someone point out if it will work and what's wrong with the code Heres the php <?php $submit = $_POST['submit']; //Form data $existcat = mysql_real_escape_string($_POST['exist_cat']); $newcat = mysql_real_escape_string($_POST['new_cat']); $articletitle = mysql_real_escape_string($_POST['article_title']); $articleptitle = mysql_real_escape_string($_POST['article_ptitle']); $articlepdescription = mysql_real_escape_string($_POST['article_pdescription']); $articlepkeywords = mysql_real_escape_string($_POST['article_pkeywords']); $articlecontent = mysql_real_escape_string($_POST['article_content']); $date = date('d/m/Y \a\t g:i.s a'); if ($submit){ //Open the database mysql_connect("localhost","root",""); mysql_select_db("********"); //Select the database if ($existcat !== 'None'){ $queryreg = mysql_query("INSERT INTO articles (`article_cat` VALUES '$existcat')"); }else{ if ($existcat == 'None'){ $queryreg = mysql_query("INSERT INTO articles (`article_cat` VALUES '$newcat')"); } } //Check for existing fields if ($articletitle && $articleptitle && $articlepdescription && articlepkeywords && $articlecontent && $date){ $pagecheck = mysql_query("SELECT `article_title` FROM articles WHERE `article_title` = '$articletitle'");echo mysql_error(); $count = mysql_num_rows($pagecheck);echo mysql_error(); if ($count != 0){ echo("<font size=\"2\" color=\"#ff0000\">Article already exists. Please edit the existing article!</font>");echo mysql_error(); }else{ //Enter into Database $queryreg = mysql_query("INSERT INTO articles (`article_title`, `article_ptitle`, `article_pdescription`, `article_pkeywords`, `article_content`, `date`) VALUES ('$articletitle', '$articleptitle', '$articlepdescription', '$articlepkeywords', '$articlecontent', '$date')"); echo("<font size=\"2\" color=\"#00cc00\">Your article has been created! </font>"); } }else{ echo ("<font size=\"2\" color=\"#ff0000\">Please complete <b>ALL</b> fields</font>"); } } //end Check for existing fields //end if submit $sql = "SELECT * FROM `articles` ORDER BY `id` ASC"; $query = mysql_query($sql); ?> and the form <form action="addarticle.php" method="post" enctype="multipart/form-data" name="addarticle" target="_self" id="addarticle"> <!-- Form Starts --> <div class="titlearea">Add News Article</div> <div class="dataarea"> <div class="infowrap">Article title</div> <div class="infowrap">Create Article Section</div> <div class="infowrap">Select Article Section</div> <div class="infowrap"> <input name="article_title" type="text" id="article_title" size="25" maxlength="20" /> </div> <div class="infowrap"> <input name="new_cat" type="text" id="new_cat" size="25" maxlength="100" /> </div> <div class="infowrap"> <label></label> <?php //Open the database mysql_connect("localhost","root",""); mysql_select_db("********"); //Select the database $sql = "SELECT DISTINCT(article_section) FROM articles"; $query = mysql_query($sql)or die(mysql_error()); if(mysql_num_rows($query) > 0){ ?> <label> <select name="exist_cat" id="exist_cat"> <option>None</option> <?php while($r = mysql_fetch_array($query)){ echo '<option value=" ' .$r['article_section'] . '">' . $r['article_section'] . '</option>'; } ?> </select> <?php } ?> </label> </div> </div> <div class="titlearea">Meta Data</div> <div class="dataarea"> <div class="metawrap">Title - Please use approx 65 characters</div> <div class="metawrap"> <input name="article_ptitle" type="text" id="article_ptitle" size="80" maxlength="20" /> </div> <div class="metawrap">Description - Please use approx 155 characters inc spaces</div> <div class="metawrap"> <input name="article_pdescription" type="text" id="article_pdescription" size="80" maxlength="200" /> </div> <div class="metawrap">Keywords - Please use approx 5 keyword per page</div> <div class="metawrap"> <input name="article_pkeywords" type="text" id="article_pkeywords" size="80" maxlength="200" /> </div> </div> <div class="titlearea">Article Content</div> <div class="dataarea"> <textarea name="article_content" cols="80" rows="20" id="article_content"></textarea> </div> <div class="dataarea"> <input type="submit" value="Save" name="submit" /> </div> </form> Thanks
-
Anyone
-
Hi In my mySQL table I have a column called article_section How do I echo every category in that column in to a form drop down menu element so the user can select one of the values?
-
Hi Guys. I got a little help about this yesterday but still a bit lost. I have a news article system on my website that i want to sort by article_section The user has an option to either create a section for an article or select a section from a list if one already exists. I put 2 form elements on the page. One is an input text field called article_section so the user can add a section. Another is a menu field called existingarticle_section so the user can select one from the list. What I want to do is something like Check if article_section has a value. If it does then create a section with this value if it doesn't the check existingarticle_section If existingarticle_section has a value, put the article in this section. However I have a default value in the existingarticle_section of "None" I dont know how to check the values and add the right one n to the database. I'm new to php and having difficulty writing this coz i just don't know any help would be great. Here is the PHP <?php $submit = $_POST['submit']; //Form data $articlesection = mysql_real_escape_string($_POST['article_section']); $articletitle = mysql_real_escape_string($_POST['article_title']); $articleptitle = mysql_real_escape_string($_POST['article_ptitle']); $articlepdescription = mysql_real_escape_string($_POST['article_pdescription']); $articlepkeywords = mysql_real_escape_string($_POST['article_pkeywords']); $articlecontent = mysql_real_escape_string($_POST['article_content']); $date = date('d/m/Y \a\t g:i.s a'); if ($submit){ //Open the database mysql_connect("localhost","root",""); mysql_select_db("+++++++++++"); //Select the database $pagecheck = mysql_query("SELECT `article_title` FROM articles WHERE `article_title` = '$articletitle'");echo mysql_error(); $count = mysql_num_rows($pagecheck);echo mysql_error(); if ($count != 0){ echo("<font size=\"2\" color=\"#ff0000\">Article already exists. Please edit the existing article!</font>");echo mysql_error(); }else{ //Check for existing fields if ($articlesection && $articletitle && $articleptitle && $articlepdescription && articlepkeywords && $articlecontent && $date){ //Enter into Database $queryreg = mysql_query("INSERT INTO articles (`article_section`, `article_title`, `article_ptitle`, `article_pdescription`, `article_pkeywords`, `article_content`, `date`) VALUES ('$articlesection', '$articletitle', '$articleptitle', '$articlepdescription', '$articlepkeywords', '$articlecontent', '$date')"); echo("<font size=\"2\" color=\"#00cc00\">Your article has been created! </font>"); }else{ echo ("<font size=\"2\" color=\"#ff0000\">Please complete <b>ALL</b> fields</font>"); } } } ?> and the form <form action="addarticle.php" method="post" enctype="multipart/form-data" name="addarticle" target="_self" id="addarticle"> <!-- Form Starts --> <div class="titlearea">Add News Article</div> <div class="dataarea"> <div class="infowrap">Article title</div> <div class="infowrap">Create Article Section</div> <div class="infowrap">Select Article Section</div> <div class="infowrap"> <input name="article_title" type="text" id="article_title" size="25" maxlength="20" /> </div> <div class="infowrap"> <input name="article_section" type="text" id="article_section" size="25" maxlength="100" /> </div> <div class="infowrap"> <label></label> <label> <select name="existingarticle_section" id="existingarticle_section"> <option><?php echo $row["article_section"]; ?></option> </select> </label> </div> </div> <div class="titlearea">Meta Data</div> <div class="dataarea"> <div class="metawrap">Title - Please use approx 65 characters</div> <div class="metawrap"> <input name="article_ptitle" type="text" id="article_ptitle" size="80" maxlength="20" /> </div> <div class="metawrap">Description - Please use approx 155 characters inc spaces</div> <div class="metawrap"> <input name="article_pdescription" type="text" id="article_pdescription" size="80" maxlength="200" /> </div> <div class="metawrap">Keywords - Please use approx 5 keyword per page</div> <div class="metawrap"> <input name="article_pkeywords" type="text" id="article_pkeywords" size="80" maxlength="200" /> </div> </div> <div class="titlearea">Article Content</div> <div class="dataarea"> <textarea name="article_content" cols="80" rows="20" id="article_content"></textarea> </div> <div class="dataarea"> <input type="submit" value="Save" name="submit" /> </div> </form> Thanks guys in advance Bullbreed
-
I was wondering if I could type in a keyword in to a form field on my site Click submit That keyword is then queried against google and yahoo Then the title, description and URL of the first 5 results are echoed on to my page?
-
Can I have 2 form fields that subit data to same column in Db
bullbreed replied to bullbreed's topic in PHP Coding Help
Anyone? -
Hi. Newbie PHP here. I am trying to learn PHP by developing a CMS I am part way through it but came accross this problem. I am creating a News Article system in the CMS and I want the articles to be associated with a category. This is so when a user clicks on the NEWS button, all the articles will be sorted by category; I'm not sure how to do this so I did the following. 1. Created a column in the database called article_category 2. Created a form Input text box so the user can create a category if it doesnt exist. 3. Created a Input menu field that needs to be populated with existing categories. I know i cant use the same name for these 3 form elements but I dont know how to set this up. How do I check if the Text Box is filled in to create a category or if a value from the Menu field has been selected and how to put the selected value in to the database. Heres the code I have so far <?php $submit = $_POST['submit']; //Form data $articlesection = mysql_real_escape_string($_POST['article_section']); $articletitle = mysql_real_escape_string($_POST['article_title']); $articleptitle = mysql_real_escape_string($_POST['article_ptitle']); $articlepdescription = mysql_real_escape_string($_POST['article_pdescription']); $articlepkeywords = mysql_real_escape_string($_POST['article_pkeywords']); $articlecontent = mysql_real_escape_string($_POST['article_content']); $date = date('d/m/Y \a\t g:i.s a'); if ($submit){ //Open the database mysql_connect("localhost","root",""); mysql_select_db("*************"); //Select the database $pagecheck = mysql_query("SELECT `article_title` FROM articles WHERE `article_title` = '$articletitle'");echo mysql_error(); $count = mysql_num_rows($pagecheck);echo mysql_error(); if ($count != 0){ echo("<font size=\"2\" color=\"#ff0000\">Article already exists. Please edit the existing article!</font>");echo mysql_error(); }else{ //Check for existing fields if ($articlesection && $articletitle && $articleptitle && $articlepdescription && articlepkeywords && $articlecontent && $date){ //Enter into Database $queryreg = mysql_query("INSERT INTO articles (`article_section`, `article_title`, `article_ptitle`, `article_pdescription`, `article_pkeywords`, `article_content`, `date`) VALUES ('$articlesection', '$articletitle', '$articleptitle', '$articlepdescription', '$articlepkeywords', '$articlecontent', '$date')"); echo("<font size=\"2\" color=\"#00cc00\">Your article has been created! </font>"); }else{ echo ("<font size=\"2\" color=\"#ff0000\">Please complete <b>ALL</b> fields</font>"); } } } ?> Here is the form <form action="addarticle.php" method="post" enctype="multipart/form-data" name="addarticle" target="_self" id="addarticle"> <!-- Form Starts --> <div class="titlearea">Add News Article</div> <div class="dataarea"> <div class="infowrap">Article title</div> <div class="infowrap">Create Article Section</div> <div class="infowrap">Select Article Section</div> <div class="infowrap"><input name="article_title" type="text" id="article_title" size="25" maxlength="20" /> </div> <div class="infowrap"><input name="article_section" type="text" id="article_section" size="25" maxlength="100" /> </div> <div class="infowrap"> <label></label> <label> <select name="article_section" id="article_section"> <option><?php echo $row["article_section"]; ?></option> </select> </label> </div> </div> <div class="titlearea">Meta Data</div> <div class="dataarea"> <div class="metawrap">Title - Please use approx 65 characters</div> <div class="metawrap"><input name="article_ptitle" type="text" id="article_ptitle" size="80" maxlength="20" /> </div> <div class="metawrap">Description - Please use approx 155 characters inc spaces</div> <div class="metawrap"><input name="article_pdescription" type="text" id="article_pdescription" size="80" maxlength="200" /> </div> <div class="metawrap">Keywords - Please use approx 5 keyword per page</div> <div class="metawrap"><input name="article_pkeywords" type="text" id="article_pkeywords" size="80" maxlength="200" /> </div> </div> <div class="titlearea">Article Content</div> <div class="dataarea"> <textarea name="article_content" cols="80" rows="20" id="article_content"></textarea> </div> <div class="dataarea"> <input type="submit" value="Save" name="submit" /></div> </form> Any ideas would be a great help
-
Thank you very much
-
HOw does the update statement work? I have some data that is echoed into form fields on the page from the database. I then want the user to be able to edit the data and submit it to the database. I can't get my head around the UPDATE statement. I tried this //Enter into Database $queryreg = mysql_query("UPDATE webpages SET page_name = $pagename, page_order = $pageorder, page_parent = $pageparent, page_title = $pagetitle, page_description = $pagedescription, page_keywords = $pagekeywords, page_content = $pagecontent"); echo("<font size=\"2\" color=\"#00cc00\">Your page has been updated! </font>"); }else{ echo ("<font size=\"2\" color=\"#ff0000\">Please complete <b>ALL</b> fields</font>"); } } It didnt work. Any ideas everyone. Thanks
-
Im trying to learn php my developing a CMS (I know, what a mad man I hear you say) I have a page where you can add the data for your webpage but now I want to edit the info. So I created a page that calls all the pages up in to a table on x-screen with an edit link at the end. I want to edit the Home page. Here is the table on screen; Page Name-----------------Action Home--------------------------Edit (Link) About US-----------------------Edit (Link) When you click on the Edit (Link) for the Home page you go to this Url - editpage.php?p=Home I want the form fields on this page to be populated with the info from the database related to the Home page. What value do I put in to the form fields to call the info related to the Url ?p=Home. So lets say its the page name form field I want to edit. I want it to do something like Echo the value from the page_name column in the database relative to the Home page in the URL. I hope I make sense Regards
-
Hi. Newbie here. Love the site. I have created a page where a user can create his own webpage (CMS) I would like the user to be able to edit the page by selecting the required page from a drop down menu form field. How do I populate the menu form field with the page names so when selected the user can edit the content on that page. Thanks Bullbreed
-
Sorted it. I wrote another one like this if(!$session->logged_in){ header("Status: 200"); header("Location: index.php?denied=true");
-
Yes I think so. I have 3 users. Admin User Guest When I have a page that is Admin only I write if(!$session->isAdmin()){ header("Status: 200"); header("Location: index.php?denied=true"); But I have one that is admin and user and havent done this before so was wondering if I had written in correctly and in the right order
-
Have I wrote this the right way? if(!$session->isAdmin() || (!$session->isUser())){ header("Status: 200"); header("Location: index.php?denied=true");
-
This is somethiing I took from a tutorial and cant get it to work. I see what you mean about the variable. Thanks for that. $sec1 was the original variable I created for data from the initial form submission Any more reasons how I messed it up.
-
I want to put the unserialized data into a table and came up with this; $sql = "SELECT `sec1`, `sec1other`, `sentdate` FROM `trainingdata` WHERE `username`='".$_GET['username']."'"; $sql_query = mysql_query($sql) or trigger_error(mysql_error()); if (mysql_num_rows($sql_query) > 0) { while ($data = mysql_fetch_assoc($sql_query)) { $sec1 = unserialize ($sec1['sec1']); ?> <tr> <td width="50%"><?php echo $data['sec1']; ?></td> <td><?php echo $data['sec1other']; ?></td> <td width="20%"><?php echo $data['sentdate']; ?></td> </tr> Doesn't work. Anyone any ideas.
-
Do I simply do an Insert in to database at this point or do I need to check the data first?
-
Thanks for your reply. I am trying to get the data from quite a long form in to my database. I sectioned off each section of the form, hence sec1, sec2 etc. NOW I want to check what has been selected and store it in the database. So later I can selects this information from the database and echo it to the screen
-
Would this be correct. The 'sec1other etc are text fields in the form. if(isset($_POST["sec1"])) {$sec1 = $_POST["sec1"];} else {$sec1 = array();} if(isset($_POST["sec1other"])) {$sec1other = $_POST["sec1other"];} if(isset($_POST["sec2"])) {$sec2 = $_POST["sec2"];} else {$sec2 = array();} if(isset($_POST["sec2other"])) {$sec2other = $_POST["sec2other"];} if(isset($_POST["sec3"])) {$sec3 = $_POST["sec3"];} else {$sec3 = array();} if(isset($_POST["sec3other"])) {$sec3other = $_POST["sec3other"];} if(isset($_POST["sec4"])) {$sec4 = $_POST["sec4"];} else {$sec4 = array();} if(isset($_POST["sec4other"])) {$sec4other = $_POST["sec4other"];} if(isset($_POST["cantsee"])) {$cantsee = $_POST["cantsee"];} if(isset($_POST["sec5"])) {$sec5 = $_POST["sec5"];} else {$sec5 = array();} if(isset($_POST["sec5other"])) {$sec5other = $_POST["sec5other"];} if(isset($_POST["sec6"])) {$sec6 = $_POST["sec6"];} else {$sec6 = array();} if(isset($_POST["sec6other"])) {$sec6other = $_POST["sec6other"];} if(isset($_POST["sec7"])) {$sec7 = $_POST["sec7"];} else {$sec7 = array();} if(isset($_POST["sec7other"])) {$sec7other = $_POST["sec7other"];} if(isset($_POST["sec8"])) {$sec8 = $_POST["sec8"];} else {$sec8 = array();} if(isset($_POST["sec8other"])) {$sec8other = $_POST["sec8other"];} if(isset($_POST["whendate"])) {$whendate = $_POST["whendate"];} if(isset($_POST["username"])) {$username = $_POST["username"];} $date = date('d/m/Y \a\t g:i.s a');
-
Ok, getting a bit closer. I sectioned off each option like this FRUIT <input type="checkbox" name="sec1[]" id="sec1[]" value="apples" /> <label>Apples.</label><br /> <input type="checkbox" name="sec1[]" id="sec1[]" value="oranges" /><label>Oranges.</label><br /> <input type="checkbox" name="sec1[]" id="sec1[]" value="banana" /><label>Banana.</label><br /> Vegetables <input type="checkbox" name="sec2[]" id="sec2[]" value="tomato" /><label>Tomato.</label><br /> <input type="checkbox" name="sec2[]" id="sec2[]" value="beans" /><label>Beans.</label><br /> <input type="checkbox" name="sec2[]" id="sec2[]" value="carrots" /><label>Carrots.</label><br /> How do I get this info in to the database? Do I use an IF statement or do I check the items selected. I'm completely lost here Thanks
-
Hi. PHP Newbie here but old guy learning new tricks. lol I'm having a hard time figuring out how to get information from check boxes in to a database and show them on screen. I have 2 sections as below in bold with the checkboxes below each; (the sections will probably increase) Singles Pop Rap Swing Jazz Albums Pop Rap Swing Jazz 1. How do I set up the database to accept this data? 2. Do I create a different name"" for every input checkbox so above there would be 8 different names? This can't be right. Databases are much cleverer than this. Hope you can help