Scip Posted June 10, 2009 Share Posted June 10, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/161689-what-am-i-doing-wrong/ Share on other sites More sharing options...
taquitosensei Posted June 10, 2009 Share Posted June 10, 2009 Usually a blank screen means there was a fatal error and displaying errors is turned off. Put this at the top of your processing page. ini_set("display_errors","2"); ERROR_REPORTING(E_ALL); or from the command line. php -l "yourprocessingfile.php" Quote Link to comment https://forums.phpfreaks.com/topic/161689-what-am-i-doing-wrong/#findComment-853169 Share on other sites More sharing options...
Maq Posted June 10, 2009 Share Posted June 10, 2009 In addition to what taquito suggested, you're not outputting anything on the processing page. Why would it display anything? Quote Link to comment https://forums.phpfreaks.com/topic/161689-what-am-i-doing-wrong/#findComment-853170 Share on other sites More sharing options...
Scip Posted June 10, 2009 Author Share Posted June 10, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/161689-what-am-i-doing-wrong/#findComment-853175 Share on other sites More sharing options...
Maq Posted June 10, 2009 Share Posted June 10, 2009 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()); Quote Link to comment https://forums.phpfreaks.com/topic/161689-what-am-i-doing-wrong/#findComment-853177 Share on other sites More sharing options...
Scip Posted June 10, 2009 Author Share Posted June 10, 2009 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) ?> Quote Link to comment https://forums.phpfreaks.com/topic/161689-what-am-i-doing-wrong/#findComment-853179 Share on other sites More sharing options...
Scip Posted June 10, 2009 Author Share Posted June 10, 2009 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} )"; Quote Link to comment https://forums.phpfreaks.com/topic/161689-what-am-i-doing-wrong/#findComment-853196 Share on other sites More sharing options...
Maq Posted June 10, 2009 Share Posted June 10, 2009 Nice, but you should really properly indent and space your query for readability, you can look in the MySQL manual to see the conventional formatting. Please mark as solved. Quote Link to comment https://forums.phpfreaks.com/topic/161689-what-am-i-doing-wrong/#findComment-853198 Share on other sites More sharing options...
Scip Posted June 10, 2009 Author Share Posted June 10, 2009 How do i mark as solved? Quote Link to comment https://forums.phpfreaks.com/topic/161689-what-am-i-doing-wrong/#findComment-853212 Share on other sites More sharing options...
Maq Posted June 10, 2009 Share Posted June 10, 2009 How do i mark as solved? Bottom left, right above "Quick Reply". Quote Link to comment https://forums.phpfreaks.com/topic/161689-what-am-i-doing-wrong/#findComment-853233 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.