Hi,

I have started learning PHP, I did eventually manage to set up and configure everything fine.

I had tested all the settings individually and even tested php to access data from mysql and it worked fine. But then a couple of days ago i was working on something similar, where the php file had to take user input via a html form and insert the data into the database. My code looked fine( i was following a tutorial) but for some reason everytime the form was submitted it jus redisplayed the form again without adding anything to the database nor any errors on the screen.

In the process of fixing this i somehow made the problem even worse now the file wont even display the html form at all which is really strane, and my other test file which worked fine previously now just outputs nothing at all.

I have spent the last two days tryin to figure out what i had possibly done and its making me go nuts.

please help anyoneπŸ˜• πŸ™

btw im using php5, mysql server 4.1 and apache 2 on winXP

    Hi,

    Do you have your error reporting set to output errors to screen?

    You got any sample code to see whats going on ?

      Im not sure how to do that, I have tried to set the display_errors to On on the php.ini files but it didnt seem to make any difference.

      This is what im trying to fix: sorry i cant attach it.

      <html>
      <head>
      <title>Add an Article</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      </head>
      <?php
      // Get the PHP file containing the DbConnector class
      require_once('../includes/DbConnector.php');
      require_once('../includes/Validator.php');

      // Create an instance of DbConnector
      $connector = new DbConnector();

      // Check whether a form has been submitted. If so, carry on
      if ($HTTP_POST_VARS){

      // Validate the entries
      $validator = new Validator();

      $validator->validateTextOnly($HTTP_POST_VARS['title'],'Title');
      $validator->validateTextOnly($HTTP_POST_VARS['imgDescrip'],'ImageDes');
      $validator->validateNumber($HTTP_POST_VARS['Section'],'Section');
      $validator->validateGeneral($HTTP_POST_VARS['mainText'],'MainText');

      // Check whether the validator found any problems
      if ( $validator->foundErrors() ){
      echo 'There was a problem with: <br>'.$validator->listErrors('<br>'); // Show the errors, with a line between each
      }else{

      // Create an SQL query (MySQL version)
      // The 'addslashes' command is used 5 lines below for added security
      // Remember to use 'stripslashes' later to remove them (they are inserted in front of any
      // special characters

      $insertQuery = "INSERT INTO project_content (Title,MainText,Image,ImageDes,Section) VALUES (".
      "'".$HTTP_POST_VARS['title']."', ".
      "'".addslashes($HTTP_POST_VARS['mainText'])."', ".
      $HTTP_POST_VARS['image']."', ".
      $HTTP_POST_VARS['imgDescrip']."', ".
      "'".$HTTP_POST_VARS['section']."')";

      // Save the form data into the database 
      if ($result = $connector->query($insertQuery)){
      
      	// It worked, give confirmation
      	echo '<center><b>Content added to the project database</b></center><br>';
      
      }else{
      
      	// It hasn't worked so stop. Better error handling code would be good here!
      	exit('<center>Sorry, there was an error saving to the database</center>');
      
      }

      }
      }
      ?>

      <html>
      <head>
      <title> Add/Modify project content </title>
      </head>

      <body>
      <h2> Form to Add / Modify Content </h2>
      <form name="input1" method ="post" action="AddContent.php">
      <table>
      <tr>
      <td> Title: </td>
      <td><input type="text" name="title" size="50"></td></tr>
      <tr><td> Section: </td>
      <td><input type="int" name="Section" size="4"></td></tr>
      <tr>
      <td> Main Text: </td>
      <td><textarea rows="5" cols="37"" name="mainText">
      </textarea></td></tr>
      <tr>
      <td>Load Image: </td>
      <td><input type="file" name="image"></td></tr>
      <td>Image Position
      <table>
      <tbody>
      <tr>
      <td align=center><input type=radio name=position value=topleft ></td>
      <td align=center><input type=radio name=position value=top ></td>
      <td align=center><input type=radio name=position value=topright ></td>
      </tr>
      <tr>
      <td><input type=radio name=position value=left ></td>
      <td>text</td>
      <td><input type=radio name=position value=right ></td>
      </tr>
      <tr>
      <td align=center><input type=radio name=position value=botleft ></td>
      <td align=center><input type=radio name=position value=bot checked></td>
      <td align=center><input type=radio name=position value=botright ></td>
      </tr>
      </tbody>
      </table></td>

      <tr>
      <td>Image Description: </td>
      <td><input type="text" name="imgDescrip" size="50"></td>
      </tr>
      <tr>
      <td>More Images: </td></tr>
      <br>
      <tr>
      <td> Place Links: <small>(Upload a file)</small></td>
      <td> <input type="file" name="file"></td>
      </tr><table>

      <p align="center">
      <input type="submit" value="Submit">
      </p>
      </form>

      </body>
      </html>

      Previously the following test worked:

      <?php

      // Get the PHP file containing the DbConnector class
      require_once('DbConnector.php');

      // Create an instance of DbConnector
      $connector = new DbConnector();

      // Use the query function of DbConnector to run a database query
      // (The arrow -> is used to access a function of an object)
      $result = $connector->query('SELECT firstname FROM customers');

      // Get the result
      $row = $connector->fetchArray($result);

      // Show it to the user
      echo $row['firstname'];

      ?>

      but it doesnt display anything at all now.

      Cheers mate.

        What does this output?

        <?php
        
        // Get the PHP file containing the DbConnector class
        require_once('DbConnector.php');
        
        // Create an instance of DbConnector
        $connector = new DbConnector();
        
        if (empty($connector)){
            echo ('database connection problem');
        die();
        }
        
        // Use the query function of DbConnector to run a database query
        // (The arrow -> is used to access a function of an object)
        $result = $connector->query('SELECT firstname FROM customers');
        
        if(empty($result)){
        echo('Query Problem <br> Have you connected to a database?');
        die();
        }
        
        // Get the result
        $row = $connector->fetchArray($result);
        
        if (empty( $row['firstname'])){
        echo('Row problem  - dumping recordset<br>');
        print_r($row);
        die();
        }
        
        // Show it to the user
        echo $row['firstname'];
        ?> 

          Hi mate,

          Just tried that but It doesnt output anything at all, just like everything else.

          I get the feeling it might be possible that I have accidentally changed something on my php.ini file, though i cant be sure at all.
          Do you think i should just wipe out PHP completely and set it up again, even tho i had spent many hours setting it up on the firstplace?

          I have tried this really basic test, but no output again:

          <html>
          <head>
          <title> Reading the test database </title>
          </head>
          <body>
          <?php
          $db = mysql_connect("localhost", "root","");
          mysql_select_db("test", $db);
          $result = mysql_query("SELECT * FROM customers",$db);

          echo("First Name: " . mysql_result($result,0,"firstname"). "<br>\n";
          echo("Surname: " .mysql_result($result,0,"surname"). "<br>\n";
          ?>

          </body>
          </html>

            Just another note, I have just tried out something similar using the SQLite database instead and it worked fine, and output things as expected.
            So does that mean I dont have to worry about my php setup?

              check your phpinfo() and see what it says...

              I'm on hols now - so wont be able to help anymore - off to get married!

                Hi roni,

                Do yourself a favour and learn how to indent your code by hand πŸ˜‰

                Don't use a gui (like dreamweaver) ... they make a mess of a script and make it impossible to debug.

                I found 4 errors in the 3 minutes it took me to indent your code :queasy:... 2 errors in the SQL and 2 in the HTML (there could be more!) ...

                <html> 
                <head> 
                <title>Add an Article</title> 
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
                </head> 
                <?php 
                // Get the PHP file containing the DbConnector class 
                require_once('../includes/DbConnector.php'); 
                require_once('../includes/Validator.php'); 
                
                // Create an instance of DbConnector 
                $connector = new DbConnector(); 
                
                // Check whether a form has been submitted. If so, carry on 
                if ($HTTP_POST_VARS){ 
                
                // Validate the entries 
                $validator = new Validator(); 
                $validator->validateTextOnly($HTTP_POST_VARS['title'],'Title'); 
                $validator->validateTextOnly($HTTP_POST_VARS['imgDescrip'],'ImageDes'); 
                $validator->validateNumber($HTTP_POST_VARS['Section'],'Section'); 
                $validator->validateGeneral($HTTP_POST_VARS['mainText'],'MainText'); 
                
                // Check whether the validator found any problems 
                if ( $validator->foundErrors() ){ 
                	echo 'There was a problem with: <br>'.$validator->listErrors('<br>'); // Show the errors, with a line between each 
                } else { 
                	// Create an SQL query (MySQL version) 
                	// The 'addslashes' command is used 5 lines below for added security 
                	// Remember to use 'stripslashes' later to remove them (they are inserted in front of any 
                	// special characters 
                
                
                	/* ERROR
                		** You missed the opening single-quote 
                		** before $HTTP_POST_VARS['image'] and 
                		** $HTTP_POST_VARS['imgDescrip']
                	*/
                
                	$insertQuery = "
                INSERT INTO project_content (Title, MainText, Image, ImageDes, Section) 
                VALUES (
                	'".$HTTP_POST_VARS['title']."'
                , 	'".addslashes($HTTP_POST_VARS['mainText'])."'
                , 	'".$HTTP_POST_VARS['image']."' 	
                , 	'".$HTTP_POST_VARS['imgDescrip']."' // You missed the opening single-quote here
                , 	'".$HTTP_POST_VARS['section']."'
                )"; 
                
                	// Save the form data into the database 
                	if ($result = $connector->query($insertQuery)){ 
                		// It worked, give confirmation 
                		echo '<center><b>Content added to the project database</b></center><br>'; 
                	} else { 
                		// It hasn't worked so stop. Better error handling code would be good here! 
                		exit('<center>Sorry, there was an error saving to the database</center>'); 
                	} 
                } 
                } 
                ?> 
                
                <html> 
                <head> 
                <title> Add/Modify project content </title> 
                </head> 
                
                <body> 
                <h2> Form to Add / Modify Content </h2> 
                <form name="input1" method ="post" action="AddContent.php"> 
                <table> 
                	<tr> 
                		<td> Title: </td> 
                		<td><input type="text" name="title" size="50"></td>
                	</tr> 
                	<tr>
                		<td> Section: </td> 
                		<td><input type="int" name="Section" size="4"></td>
                	</tr> 
                	<tr> 
                		<td> Main Text: </td> 
                		<td><textarea rows="5" cols="37"" name="mainText"></textarea></td>
                	</tr> 
                	<tr> 
                		<td>Load Image: </td> 
                		<td><input type="file" name="image"></td>
                	</tr> 
                
                <!-- ERROR: Missed out <tr> -->
                	<td>Image Position 
                		<table> 
                			<tbody> 
                			<tr> 
                				<td align=center><input type=radio name=position value=topleft ></td> 
                				<td align=center><input type=radio name=position value=top ></td> 
                				<td align=center><input type=radio name=position value=topright ></td> 
                			</tr> 
                			<tr> 
                				<td><input type=radio name=position value=left ></td> 
                				<td>text</td> 
                				<td><input type=radio name=position value=right ></td> 
                			</tr> 
                			<tr> 
                				<td align=center><input type=radio name=position value=botleft ></td> 
                				<td align=center><input type=radio name=position value=bot checked></td> 
                				<td align=center><input type=radio name=position value=botright ></td> 
                			</tr> 
                			</tbody> 
                		</table>
                	</td> 
                <!-- ERROR: Missed out </tr>  here -->
                
                <tr> 
                	<td>Image Description: </td> 
                	<td><input type="text" name="imgDescrip" size="50"></td> 
                </tr> 
                <tr> 
                	<td>More Images: </td>
                </tr> 
                
                	<br> <!--ERROR: what's this? -->
                
                <tr> 
                	<td> Place Links: <small>(Upload a file)</small></td> 
                	<td> <input type="file" name="file"></td> 
                </tr>
                <table> 
                <p align="center"><input type="submit" value="Submit"></p> 
                </form> 
                
                </body> 
                </html> 
                

                You don't have to use my formatting, but do use one that you can read clearly yourself.

                Hope that helps!

                Paul πŸ™‚

                  I have checked phpinfo() and it looks fine though im not really sure what I should be looking for.

                  Anyway enjoy your big day you lucky man!! Thanks.

                  Also cheers for the tips Paul!! I didnt find a couple other similar errors but it hasnt really made any difference to my problem. Im still getting no output display at all.

                  Im not sure if im generalising the problem too much but so far this problem only just concerns any code that involves connection to mysql database.

                    Write a Reply...