Jump to content

PLEASE HELP!! Can't get ID from URL...whats the problem???


Bl4ckMaj1k

Recommended Posts

Good evening my PHP experts!!!

 

OK so heres the problem...I have been at this for about 2 DAYS now and for the life of me I just don't understand what I could possibly be doing wrong.

 

I have 3 of 4 variables outputting correctly but without my id being pulled from the URL NOTHING will get written to my database. I have ran some tests and I came to learn that my $_POST['id']; function is not working properly for some strange reason. As always, any help would be greatly appreciated. Please see below PHP code. I also have posted the HTML code for your reference purposes...thanks in advance. Please helpppp!!!!

 

<?php

session_start();

$id = '';

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

include_once "scripts/connect_to_mysql.php";

$id = $_POST['id'];
$id  = mysql_real_escape_string($id );
$id = eregi_replace("`", "", $id);


    $cust_password = $_POST['password'];
    $hashedPass = md5($cust_password); 

$sql = mysql_query("UPDATE customers SET password='$hashedPass' WHERE id='$id'");

$update_success = 'You have successfully updated your Password. Please click <a href="customer_login.php">HERE</a> to log into your account.';

//Output to test whether or not my variables have anything in them.
//$update_success, $hashedPass, $cust_password all Output just fine. $id displays nothing at all.	
echo $update_success;
echo $hashedPass;
echo $cust_password;
echo $id;

exit();

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="style.css"/>

<script type="text/javascript">
<!-- Form Validation -->
function validate_form ( ) { 
valid = true; 
if ( document.form.password.value == "" ) { 
alert ( "Password field must not be blank." ); 
valid = false;
}
return valid;
}
<!-- Form Validation -->
</script>

</head>

<body>

<div id="pg_container">

<!--HEADER SECTION-->
<div id="header">
<div id="header_logo"></div>
    <div id="header_right">Welcome to Built 2 Manage.</div>
</div>
<!--HEADER SECTION-->

<!--PAGE CONTAINER-->
<div id="pgbdy_container">
<form action="cust_acc_conf.php" method="post" id="form" name="form" enctype="multipart/form-data" onsubmit="return validate_form ( );">
<div id="login_header">
    	<p>
        	Please log into your account below.
        </p>
    </div>
    
    <div id="cust_choose_pass_form">
    	<div id="cust_choose_pass_text">
        	<p>
            	Password:
            </p>
        </div>
        <div id="cust_choose_pass_field">   	
            <p>
            	<input name="password" type="text" id="password" /><br /><br />
                <input name="submit_password" type="submit" id="submit_password" value="Submit Password" /><br />
               </p>
        </div>
    </div>
    </form>
</div>

<!--PAGE CONTAINER-->

<div id="footer"></div>

</div>
</body>
</html>

Link to comment
Share on other sites

I have tried $_GET, $_POST, and $_REQUEST....still nothing. My $id variable will not echo anything neither will any data get written to the table.

 

P.S. if I am using method="POST"; in my HTML form, will PHP still allow me to gather data using $_GET? Someone told me yesterday that its not possible.

 

P.S.S. I am literally smiling ear to ear seeing the speedy reply.....WOW!!! YAY!!!  :-)

Link to comment
Share on other sites

Yeah, even if the form method is post, you can still send a 4_GET var by tacking it onto the form's action= attribute. To see what you're actually getting, put this at the top of the script and look at its output after the form has been submitted.

 

echo '$_POST array:<pre>';
print_r($_POST);
echo '</pre>$_GET array:<pre>';
print_r($_GET);
echo '</pre>';

 

Edit: fixed bbcode tags.

Link to comment
Share on other sites

Interesting. Here is the PHP with the function you advised I add to top of code:

 

<?php

session_start();

echo '$_POST array:<pre>';
print_r($_POST);
echo '</pre>$_GET array:<pre>';
print_r($_GET);
echo '</pre>';

$id = '';

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

include_once "scripts/connect_to_mysql.php";

$id = $_GET['id'];
    $id  = mysql_real_escape_string($id );
    $id = eregi_replace("`", "", $id);

$cust_password = $_POST['password'];
    $hashedPass = md5($cust_password); 

//$sql = mysql_query("UPDATE customers SET password='$hashedPass' WHERE id='$id'");

$update_success = 'You have successfully updated your Password. Please click <a href="customer_login.php">HERE</a> to log into your account.';
echo $update_success;
echo $hashedPass;
echo $cust_password;
echo $id;

exit();

}

?>

 

And here is what was output to page:

 

$_POST array:

Array

(

    [password] => christopher

    [submit_password] => Submit Password

)

$_GET array:

Array

(

)

You have successfully updated your Password. Please click HERE to log into your account.0a909ffe7be1ffe2ec130aa243a64c26christopher

 

 

Link to comment
Share on other sites

EDIT

 

I DID IT!!!!!! I FIXED IT!!!!! Finally WOWWWW!!! I am SOOOOO proud of me right now!!

 

Here is what I did.

 

First, I changed the following:

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

include_once "scripts/connect_to_mysql.php";

$id = $_GET['id'];
    $id  = mysql_real_escape_string($id );
    $id = eregi_replace("`", "", $id);

 

to:

include_once "scripts/connect_to_mysql.php";

$id = $_GET['id'];
    $id  = mysql_real_escape_string($id );
    $id = eregi_replace("`", "", $id);
    if (isset($_POST['password'])) {

 

 

Then I went into the HTML of the code and changed the following:

<form action="cust_acc_conf.php" method="post" id="form" name="form" enctype="multipart/form-data" onsubmit="return validate_form ( );">
<div id="login_header">

 

to:

<form action="cust_acc_conf.php?id=<?php echo $id ?>" method="post" id="form" name="form" enctype="multipart/form-data" onsubmit="return validate_form ( );">

 

This wouldn't work for me before because the $id variable wasn't being returned UNLESS I hit the submit button. Now that its outside of the if condition, it stores it in the $id variable without any necessary action required. This makes it accessible whenever I need it, not just when a button is pressed. Wow sometimes all you need is a push in the right direction. Thank youuuuuuuuuu!!!!!!!

 

 

 

Link to comment
Share on other sites

And at that point, is there still a key=value pair appended to the URL string in the address bar of your browser?

 

P.S. The answer to this was NOOOO!!!! And I totally get it!! My form wasn't returning the variable to the URL.....so how would it POSSIBLY have anything to capture....wow PHP makes SOOOO much sense!!!!  :-)

 

I <3 this place already!!!!!!

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.