Jump to content

oh headaches!


quint

Recommended Posts

i ave this problem with lines 89 and 90 returning the following errors

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\chris1\My Documents\xampp\htdocs\elp\modify_information.php on line 88

 

Warning: Cannot modify header information - headers already sent by (output started at C:\Documents and Settings\chris1\My Documents\xampp\htdocs\elp\modify_information.php:88) in C:\Documents and Settings\chris1\My Documents\xampp\htdocs\elp\modify_information.php on line 89

 

heres the code

$RSStudent=$RSStudent_query=@mysql_query(("update OCStudents set StudentName = '"

    .$_POST["Name"]."', StudentEmailAddress = '"

    .$_POST["EmailAddress"]."', StudentPassword = '"

    .$_POST["Password"]."' where StudentID = "

    .$_SESSION['StudentID']),$conn);

  $RSStudent=mysql_fetch_array($RSStudent_query);

;header("Location: "."student_menu.php");}

?>

 

 

89 and 90 are in bold....

 

 

complete newbie to php using mysql xammp apache

 

any thoughts appreciated

 

thanks in advance quint

Link to comment
Share on other sites

heres full code

<?

  session_start();

  session_register("StudentID_session");

  session_register("blnIsUserGood_session");

  session_register("studentid_session");

?>

<? // asp2php (vbscript) converted on Tue Sep 11 21:05:05 2007

?>

<?

if (empty($_SESSION['StudentID']))

{

 

  header("Location: "."index.php");

}

 

if (empty($_POST["Submit"]))

{

 

//first time entering page

  // $conn is of type "adodb.connection"

$conn=mysql_connect("localhost","root","");

mysql_select_db("elp",$conn);

 

  $RSStudent=$RSStudent_query=mysql_query(("SELECT StudentName, StudentEmailAddress, StudentPassword FROM OCStudents where StudentID = ".$_SESSION['StudentID']),$conn); 

$RSStudent=mysql_fetch_array($RSStudent_query);

;  $TheMessage="Modify your student information and press OK.";

  $StudentName=$RSStudent["StudentName"];

  $StudentEmailAddress=$RSStudent["StudentEmailAddress"];

  $StudentPassword=$RSStudent["StudentPassword"];

}

  else

if (empty($_POST["Name"]) || $_POST["Name"]=="")

{

 

  $TheMessage="Name is required.";

  $StudentName=$_POST["Name"];

  $StudentEmailAddress=$_POST["EmailAddress"];

  $StudentPassword=$_POST["Password"];

}

  else

if (empty($_POST["EmailAddress"]) || $_POST["EmailAddress"]=="")

{

 

  $TheMessage="Email is required.";

  $StudentName=$_POST["Name"];

  $StudentEmailAddress=$_POST["EmailAddress"];

  $StudentPassword=$_POST["Password"];

}

  else

if (empty($_POST["Password"]) || $_POST["Password"]=="")

{

 

  $TheMessage="Password is required.";

  $StudentName=$_POST["Name"];

  $StudentEmailAddress=$_POST["EmailAddress"];

  $StudentPassword=$_POST["Password"];

}

  else

if (empty($_POST["RepeatPassword"]) || $_POST["RepeatPassword"]=="")

{

 

  $TheMessage="Repeat Password is required.";

  $StudentName=$_POST["Name"];

  $StudentEmailAddress=$_POST["EmailAddress"];

  $StudentPassword=$_POST["Password"];

}

  else

if ($_POST["Password"]!=$_POST["RepeatPassword"])

{

 

  $TheMessage="Both passwords do not match!";

  $StudentName=$_POST["Name"];

  $StudentEmailAddress=$_POST["EmailAddress"];

  $StudentPassword=$_POST["Password"];

}

  else

{

 

  // $conn is of type "adodb.connection"

$conn=mysql_connect("localhost","root","");

mysql_select_db("elp",$conn);

 

$RSStudent=$RSStudent_query=@mysql_query(("update OCStudents set StudentName = '"

    .$_POST["Name"]."', StudentEmailAddress = '"

    .$_POST["EmailAddress"]."', StudentPassword = '"

    .$_POST["Password"]."' where StudentID = "

    .$_SESSION['StudentID']),$conn);

$RSStudent=mysql_fetch_array($RSStudent_query);

header("Location: "."student_menu.php");}

?>

 

line 89 an 90 in bold

Link to comment
Share on other sites

Your header error is caused by the first error, which is:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\chris1\My Documents\xampp\htdocs\elp\modify_information.php on line 88

 

When you get the above type of error it basically means that you have error in your query. Id change these lines:

$RSStudent=$RSStudent_query=@mysql_query(("update OCStudents set StudentName = '"
    .$_POST["Name"]."', StudentEmailAddress = '"
    .$_POST["EmailAddress"]."', StudentPassword = '"
    .$_POST["Password"]."' where StudentID = "
    .$_SESSION['StudentID']),$conn);
  $RSStudent=mysql_fetch_array($RSStudent_query);
header("Location: "."student_menu.php");}

 

Into:

$RSStudent_query = "UPDATE OCStudents SET StudentName = '" . $_POST['Name'] . "',
                                          StudentEmailAddress = '" . $_POST["EmailAddress"] . "',
                                          StudentPassword = '" . $_POST["Password"] . "'
                    WHERE StudentID = " . $_SESSION['StudentID'];

$RSStudent_result = mysql_query($RSStudent_query, $conn) or die('SQL Error:<br />' . $RSStudent_query . '<br />' . mysql_error($conn));


$RSStudent = mysql_fetch_array($RSStudent_result);

header("Location: student_menu.php");
}

Re run you code. If there is an error with your query an error message will appear showing the query being ran and the reason for the error.

 

Also I notice you are using POST data in your query. I strongly advise you to validate any user input (GET, POST, COOKIE) etc before using it within a query. Look into SQL Injection.

 

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.