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

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.