Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6060177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:47:45+00:00 2026-05-23T08:47:45+00:00

i need again your help… I have this php code: <? if(isset($_POST[‘addnews’])){ $type =

  • 0

i need again your help…

I have this php code:

<? 

if(isset($_POST['addnews'])){
$type = $_POST['type'];
$news = $_POST['news'];
$date = date("d-m-Y");
$memip = $_SERVER['REMOTE_ADDR'];

if($news == NULL){
$final_report.= "ALERT - Please enter something in the field with the news!";
}else{
if($type = '' AND NULL){
$final_report.= "ALERT - Please choose something from the checklist or you will die in pain!"; 
}else{ 
$create_news = mysql_query("INSERT INTO `lisnews` (`id`,`type`,`news`,`date`,`ip`) VALUES('','$type','$news','$date','$memip')"); 
$final_report.="<meta http-equiv='Refresh' content='0; URL=../admin/add-news.php'/>"; 
}}}

?>

And this form:

<div style="width:100%; text-align:left; overflow:visible; margin-top:11px; margin-bottom:7px;" id="regpage">        
<form action="" method="post">
<fieldset style="border:none;">

<label for="news" style="font-weight:normal;width:30%;float:left;display:block;"><p>this is the news field, you can write here:</p></label> 
<textarea rows="3" cols="104" name="news"></textarea></br></br>

Choose news type: <select name="type" style="margin-top:5px;">
<option>1</option>
<option>2</option>
<option>2</option>
</select>

<input type="submit" name="addnews" value="add new news!" id="addnews" style="float:right; border:1px solid #999; background:#E4E4E4;
margin-top:5px; padding-bottom:2px;"/>

</fieldset>
</form>
</div>

I want to add news in DB, and after to show them on a page. (if you can help with this too will be very very nice from you.

Regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:47:45+00:00Added an answer on May 23, 2026 at 8:47 am

    First of all, you forgot to tell the form where to send all the data:

    <form action="" method="post">
    

    You have to put the location of the PHP file you posted in between those empty quote marks after ‘action=’.

    Now let’s look at your PHP.

    First of all, this if statement here.

    if($type = '' AND NULL)
    

    Remember that = is the assignment operator, not the equality operator. It should be $type == ”. Secondly, I don’t think AND is valid PHP syntax. It should be &&. And thirdly… that if statement will never return true. Why?

    Let’s say you have this corrected version:

    if($type == '' && NULL)
    

    In that case, this will return true if $type is an empty string, and if NULL is true. However to PHP, NULL is never true. So this statement will always be false. Perhaps what you wanted to do was check if $type was either empty OR NULL, in which case the syntax is:

    if($type == '' || $type == NULL)
    

    Next, what’s with all the else statements? It’s entirely possible that more than one of those if statements could be true. What I think it should be is:

    if($news == NULL){
      $final_report.= "ALERT - Please enter something in the field with the news!";
      if($type = '' AND NULL){
        $final_report.= "ALERT - Please choose something from the checklist or you will die in    pain!"; 
      }
    }else{ 
    

    Furthermore, I’m not sure you can use the .= operator on a variable that hasn’t been initialized. I’d add in $final_report = ” to the beginning of the code just to be safe.

    Finally, you have a small error in your SQL:

    "INSERT INTO `lisnews` (`id`,`type`,`news`,`date`,`ip`) VALUES('','$type','$news','$date','$memip')"
    

    Column names don’t take quotes in SQL. It should be:

    "INSERT INTO lisnews (id,type,news,date,ip) VALUES('','$type','$news','$date','$memip')"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need your help again. This should be a function for php. I've got
I need your expertise once again. I have a java class that searches a
I need your help, i'm stacked on this project. When i run my applicaion
I really need your help for this. I am relatively new to programming and
I need some help with jQuery script again :-) Just trying to play with
need ask you about some help. I have web app running in Net 2.0.
i really really need your help. I'm successfully setting up a connection to my
I'm completely stuck and need your help... I've created a webservice stub with jaxb
I have my HTML like this: <table> <caption class=my_caption>Table 1.1: TABLE CAPTION</caption> <tr>...</tr> <tr>...</tr>
i have a input tag which is non editable, but some times i need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.