Jump to content

What am i doing wrong


Scip

Recommended Posts

when i hit the submit button nothing it goes to the processing page but nothing happens, i get a white screen and when i check the database nothing has been entered.

 

 

Here is the code for the form:

 

  <div id="content"><!-- START CONTENT-->
           <?php
	         $query="SELECT *";
		 $query.="FROM category";

		 $category_set=mysql_query($query,$connection);
		 confirm_query($category_set);

	   ?>
                   <div id="resourcebox"><!-- START RESOURCE BOX-->
                            <form action="new-resource.php" method="post">
                               <table>
                                 <thead><h3>Add a resource</h3></thead>
                                 <tr></tr>
                                 <tr>
                                   <td><p>Name:</p></td>
                                   <td><p>Category:</p></td>
                                   <td><p>Quantity:</p></td>
                                   <td><p>Image:</p></td>
                                 </tr>
                                 <tr>
                                   <td><input type="text" name="name" class="field" value=""/></td>
                                   <!--<td><input type="text" name="category" class="field" value="" /></td>-->
                                   <td><select name="category">
			         <?php
				    while($categories=mysql_fetch_array($category_set)){
                                             echo "<option value=\"{$categories['type']}\" >{$categories['type']}</option>";
				    }
			         ?>
                                        </select>
                                   </td>
                                   <td><input type="text" name="quantity" class="field" value="" /></td>
                                   <td><input type="text" name="image" class="filefield" value=""/></td>  
                                 </tr>
                                 <tr>
                                   <td ></td>
                                   <td ></td>
                                   <td ></td>
                                   <td ><p class="align"><input type="submit" name="submit" class="addbutton" value="Add"/></p></td>  
                                 </tr>

                               </table>
                             </form>
                            </div><!-- END RESOURCE BOX-->

 

For the processing page:

 

  <?php
      $name= mysql_prep($_POST['name']);
            $quantity= mysql_prep($_POST['quantity']);
            $image= mysql_prep($_POST['image']);
            $category= mysql_prep($_POST['category']);
            
            $query="SELECT id FROM category WHERE type = '{$category}'";
            
            $result= mysql_query($query,$connection);
            confirm_query($result);
            
            $type_id=mysql_fetch_array($result);
            
            
             $query="INSERT INTO resource (
                          resource_name, type_id, image, quantity
             )VALUES(
                          '{$name}', {$type_id}, '{$image}', {$quantity}
             )";
                 
             $insert_result = mysql_query($query,$connection);
             
             if($insert_result){
                $message="Addition was successful.";
                redicret_to("Resource.php?m=".urlencode($message));
             }else{
                    $message = "The addition was not sucessfull.";
                    $message .= "<br/>" .mysql_error();
                }
?>

 

This thing is driving me mad.

Link to comment
https://forums.phpfreaks.com/topic/161689-what-am-i-doing-wrong/
Share on other sites

yeh i am not outputing anything but normally when something is wrong an error is displayed.

 

I have been doing some testing and it seems that this bit of code might be the cause of the problem.

 

$query = "SELECT id FROM category WHERE type = {$category}";
   $result = mysql_query($query,$connection);

On the processing page, add this after the first opening <?php tag:

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

Try adding singe quotes around $category:

 

$query = "SELECT id FROM category WHERE type = '{$category}'";

 

If that doesn't work, temporarily add an or die clause after your query to diagnose it:

 

   $result = mysql_query($query,$connection) or die(mysql_error());

I did you you guys suggested but still the same problem.

 

Here is the code from my test page.

 

<?php require_once("includes/cms/connection.php"); ?>
<?php require_once("includes/cms/functions.php"); ?>
<?php
    ini_set ("display_errors", "1");
    error_reporting(E_ALL);
    
   $name = "Ebonite";
   $image = "image.gif";
   $quantity = 14;
   $category = "Alloy";
   
   $query = "SELECT id FROM category WHERE type = '{$category}' LIMIT 1";
   $result = mysql_query($query,$connection) or die(mysql_error());;
   
   $type_id= $result;
   
   
   $query ="INSERT INTO resource (
                 resource_name, type_id, image,quantity
   )VALUES(      '{$name}', {$type_id}, '{$image}', {$quantity}
   )";
   
   $result = mysql_query($query,$connection);
   
   if($result){
     $message="Resource was succesfully added.";
     echo $message ."<br/>";
     echo $type_id;
     
   }
   
   
?>
<?php mysql_close($connection) ?>

Thanks guys managed to figure it out.

 

The problem was

 

$query="INSERT INTO resource (
                          resource_name, type_id, image, quantity
             )VALUES(
                          '{$name}', {$type_id}, '{$image}', {$quantity}
             )";

 

should have been

$query="INSERT INTO resource (
                          resource_name, type_id, image, quantity
             )VALUES(
                          '{$name}', {$type_id['id']}, '{$image}', {$quantity}
             )";

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.