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 4232270
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:04:24+00:00 2026-05-21T02:04:24+00:00

i’m a bit of PHP noob, so sorry if this is a daft question,

  • 0

i’m a bit of PHP noob, so sorry if this is a daft question, but I just can’t figure this out by myself so any help would be greatly appreciated!

I am trying to create a modify page for an events web application. It seems to be working except when I try to validate the final if/else statement.
This statement returns the value of $row[0] and checks if its == NULL. If NULL, it should return an echo ‘this event does not exist’ to the user, if there is a value, it presents the user with a matrix of text boxes that they can change the data in.

Currently it works fine for the else statement when there is data found, but doesnt recognise the original if when there is no data. Coupled with that, the footer at the bottom of the page disappears!

Here is the main body of the code, i have highlighted the problem area. I understand that there is probably a more effective and efficient way of doing it all, but please keep it simple as I’m still learning. Thanks again. Dan

<div class="round">
<div id="main" class="round">

<span class="bold">MODIFY EVENT</span><br /><br />
On this page you can modify or delete the events that are stored on the database.<br />
Be aware that you cannot undo the DELETE function.<br />
<br />
Find Event:<br />
<table>
<form name="form1" id="form1" method="post" action="
<?php echo $_SERVER["PHP_SELF"]; ?>" >
<tr><th>By Date:</td><td><input type="text" name="modifyDate" 
id="modifyDate" value="dd/mm/yy" /></td></tr>
<tr><th>By Name:</td><td><input type="text" name="modifyName" id="modifyName" 
value="" /></td></tr>
<tr><th>Find All:</th><td><input type="checkbox" name="modifyAll" 
id="modifyAll" /><td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Search" /></td></tr>
</form>
</table>

<?PHP


if(!isset($_POST['modify'])){

    if(isset($_POST['submit'])){

    $moddate = $_POST['modifyDate'];

            If($moddate == "dd/mm/yy"){
        $date = "";
    }
    else{
        $newDate = str_replace("/",".",$moddate);
        $wholeDate = $newDate;
        $dateArray = explode('.', $wholeDate);
        $date = mktime(0,0,0,$dateArray[1],$dateArray[0],$dateArray[2]);
    }

    $name = $_POST['modifyName'];
    $all  = $_POST['modifyAll'];

    $host = "localhost";
    $user = "user";
    $password = "password";
    $db = "database";

    $con = mysql_connect($host,$user,$password) or die('Could not connect to Server');
    $dbc = mysql_select_db($db, $con) or die('Could not connect to Database');

    if($all != 'on'){
        $q = "SELECT * FROM events WHERE date = '$date' || title = '$name' ";
    }
    else{
        $q = "SELECT * FROM events";
    }

    $result = mysql_query($q);
    $row = mysql_fetch_array($result) or die(mysql_error());    

//THIS IS THE PROBLEM HERE!!!!

    if($row[0]==NULL){ 
        echo 'This event does not exist';
    }
    else{
        ?>

        <form name="form1" id="form1" method="post" action="
                    <?phpecho $_SERVER['PHP_SELF']; ?>" >
    <?PHP               

        $result = mysql_query($q) or die(mysql_error());

        while ($row = mysql_fetch_array($result)){

            $initialDate = date('d/m/y', $row['date']);
            $ID = $row['ID'];

            echo '<input type="text" name="inputEmail" id="inputEmail"  value="'.$initialDate.'" />';

            echo '<input type="checkbox" value=$ID name="toModify[]" style = "visibility: hidden;" /><br /><br />';

        }
        echo '<input type="submit" name="modify" value="Modify" />
                            <br /><br />';
    }
}
}
else{
    //modify database and return echo to user
}
?>


</div>
<div id="clear"></div>
</div>


</div>
</div>
<div id="footer" class="round shadow"></div>

</body>
</html>
  • 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-21T02:04:25+00:00Added an answer on May 21, 2026 at 2:04 am

    mysql_fetch_array($result) returns false if there are no rows, so it’s possible that even if there is nothing in the result, it’s still returning a false and your if($row[0] == null) is evaluating to false, also.

    In other words, you should be doing a more robust test on the return results from your query to catch fringe cases.

    As others have mentioned or implied, here are some things you could / should be doing:

    • test for rows returned, not values in rows
    • test for existence of variable, not content of variable
    • check the database for errors returned
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have just tried to save a simple *.rtf file with some websites and
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6

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.