Jump to content

Insert query results in just a blank page


drayarms

Recommended Posts

The form below is meant to retrieve the named attribute of a form input called "limitedtextfield" , along side the current date and store those values in a database.  The form contains some javascript which can be disregarded for this particular problem.
[code]
<form name="mymind" style= "position:relative;left:40px;" action="insert_status.php" method="post">

				<input  name="limitedtextfield" type="text" onKeyDown="limitText(this.form.limitedtextfield,this.form.countdown,55);" 

				onKeyUp="limitText(this.form.limitedtextfield,this.form.countdown,55);" maxlength="55"><br>

				<font size="1">(Maximum characters: 55)<br>

				You have <input readonly type="text" name="countdown" size="3" value="55"> characters left.</font>

				<input type="hidden" name="submitted" value="TRUE"/>

				<input style="position:relative;left:0px;bottom:0px;" type="submit" name="submit" value="Submit!" />

				</form>


 

 

Here is the php script that processes the form. What it is meant to do is search the database and if no record is found for the authenticated member,  input the relevant values into the database.  If a record is found, it should update the record.  Well every time I hit the submit button, all I get is a blank page.  Any clue as to what is going wrong?

 

PS:  I checked the database and no values got inserted.

<?php

//address error handling

ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);


//authenticate user
require('auth.php');

//Connect to database
require ('config.php');




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

$query = "SELECT* FROM publications WHERE member_id ='".$_SESSION['id']."' AND cartegory='status'";
        $result = @mysql_query($query);
        $num = @mysql_num_rows($result);
       
        if ($num> 0) {

	$update = mysql_query("UPDATE publications SET publication = '{$_POST['limitedtextfield']}' WHERE member_id = '".$_SESSION['id']."' AND cartegory = 'status'"); 

	header("Location: member.php");
            
        } else {



        	$query = "INSERT INTO publications ( member_id, publication, cartegory, pub_date)

	 	VALUES ( '{$_SESSION['id']}','{$_POST['limitedtextfield']}', 'status', NOW() )";


	header("Location: member.php");
            

}

}



?>


Link to comment
Share on other sites

Hi

 

Could there be a typo in these 2 lines?

$query = "SELECT * FROM publications WHERE member_id ='".$_SESSION['id']."' AND cartegory='status'";

 

$query = "INSERT INTO publications ( member_id, publication, cartegory, pub_date) VALUES ( '{$_SESSION['id']}','{$_POST['limitedtextfield']}', 'status', NOW() )";

 

Should it not be category?  Obviously I'm not sure about your tables, but this would seem logical?

 

Also you're missing concatenating full stops in the 2nd line.  I'd guess at

 

$query = "SELECT * FROM publications WHERE member_id ='".$_SESSION['id']."' AND category='status'";

 

And

 

$query = "INSERT INTO publications ( member_id, publication, cartegory, pub_date) VALUES ( ' . {$_SESSION['id']} . ',' . {$_POST['limitedtextfield']} . ', 'status', NOW() )";

 

 

 

Link to comment
Share on other sites

your update is not working because you dont have a mysql_query line for $update, try changing this

 

$query = "INSERT INTO publications ( member_id, publication, cartegory, pub_date)

	 	VALUES ( '{$_SESSION['id']}','{$_POST['limitedtextfield']}', 'status', NOW() )";

 

ti this

 

mysql_query( "INSERT INTO publications ( member_id, publication, cartegory, pub_date)
 	VALUES ( '{$_SESSION['id']}','{$_POST['limitedtextfield']}', 'status', NOW() )");

 

or you can do it like this

 

$query = "INSERT INTO publications ( member_id, publication, cartegory, pub_date)
 	VALUES ( '{$_SESSION['id']}','{$_POST['limitedtextfield']}', 'status', NOW() )";
$res=mysql_query($query);

Link to comment
Share on other sites

Remove the error suppression @ operators, and forget that they exist. There's probably an error being generated that you aren't seeing. (While developing, make sure error reporting is enabled also)

 

Unrelated to the current problem, but whenever you use header(), you need to immediately follow it with exit() to prevent further execution of the code in the script.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.