Jump to content

Struggling to get back on the horse...


phatgreenbuds

Recommended Posts

Its been a while since I have played with this stuff. Trying to get back into it and doing pretty well catching up but I am struggling with something that should be simple.

I am able to pull data from MySQL back into my form field respective to the user, but when I try to update that field I get a blank page. If this is something stupid I am doing wrong please nudge me in the right direction.

 

<?php 
require('Includes/initialize.php'); 
$page_title = 'Test';
include_once('Includes/header.php');

// Query Stuff

if(isset($_POST['update'])) {
        //
        //this is where I expect to see the updated name. Instead its just blank.
        //
        echo $_POST['first_name'];
        } else {
      
        if(is_post_request()){ //function to see if its a post from the previous page
        $uname = $_POST['username']; 
        $pword = $_POST['password'];
        
        $result = mysqli_query($db, "SELECT * FROM SubInfo WHERE email='$uname' AND password='$pword'");
        $row = mysqli_fetch_assoc($result);
        
			if(!$row) {
				echo "Not Found";
				echo "<br />";
				echo '<a href="index.php?p=5">Start Over</a>';
			} else {
				?>

          <P>First Name: 
          <input name="first_name" type="text" value="<?php echo $row["FirstName"] ?>" size="10" />  
      	  <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
		  <input name="update" type="submit" value="edit info" style="font-size:18px">
		  </form>
		  </p>

	  <?php 
	  }
		}
		  }
		?>

 

Link to comment
Share on other sites

Looking at this revised code of yours see anything wrong here?

<?php
require('Includes/initialize.php'); 
$page_title = 'Test';
include_once('Includes/header.php');
// Query Stuff
if(isset($_POST['update'])) 
{
	//
	//this is where I expect to see the updated name. Instead its just blank.
	//
	echo $_POST['first_name'];
} 
else 
{
	if(is_post_request())
	{ //function to see if its a post from the previous page
		$uname = $_POST['username']; 
		$pword = $_POST['password'];
		$result = mysqli_query($db, "SELECT * FROM SubInfo WHERE email='$uname' AND password='$pword'");
		$row = mysqli_fetch_assoc($result);
		if(!$row) 
		{
			echo "Not Found";
			echo "<br />";
			echo '<a href="index.php?p=5">Start Over</a>';
		} 
		else 
		{
			$code=<<<heredocs
			<P>First Name: 
			<input name="first_name" type="text" value="{$row['FirstName']}" size="10" />  
			<form action="{$_SERVER['PHP_SELF']}" method="post">
			<input name="update" type="submit" value="edit info" style="font-size:18px">
			</form>
			</p>
heredocs;
			echo $code;
		}
	}
}
?>

Your form here has only a submit button and no inputs.

Link to comment
Share on other sites

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.