Jump to content

webdeveloper123

Members
  • Posts

    437
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by webdeveloper123

  1. Oh i'm using SELECT again to populate the update form
  2. I'm using GET because I have something like this from the Edit link from the view page: https://name.domain.com/updateForm/edit1.php?user_id=155 and the echoed update statement shows that the FormId(P.K) is passing to it correctly
  3. @Barand - So it 2 files, view.php & edit.php, View.php is fine, its just a basic select statement from the Form db table, that shows all the data and then has "Edit" and "Delete" links next to each record. When user clicks "Edit", it takes them to the edit.php, from which the above code is from.
  4. Hey I did that, but the echo shows up on the submit page and not on the page after being posted. it looks like this: UPDATE Form SET FirstName = '', LastName = '', email = '', age = '', Birthdate= '', FavLanguage = '' WHERE FormId = '184' Could it be POST? Not picking up the HTML fields? Then it updates to a blank record because the HTML inputs are blank? Here is my HTML: <h2>Update the entry</h2> <form name="funform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <label for="fname">First name:</label><br> <input type="text" id="fname" name="fname" value="<?php echo($first_name); ?>"><span id="errorfname"></span><br> <label for="lname">Last name:</label><br> <input type="text" id="lname" name="lname" value="<?php echo($last_name); ?>"><span id="errorlname"></span><br> <label for="email">Email:</label><br> <input type="text" id="email" name="email" value="<?php echo($email); ?>"><span id="erroremail"></span>&nbsp; &nbsp; <span id="errorpattern"></span><br> <label for="age">Age:</label><br> <input type="number" id="age" name="age" value="<?php echo($age); ?>"><span id="errorage"></span><br> <label for="birthday">Birthday:</label><br> <input type="date" id="birthday" name="birthday" value="<?php echo($birthday); ?>"><span id="errorbday"></span><br> <p>Choose your favorite Web language:</p> <input type="radio" id="html" name="fav_language" value="<?php echo($favlanguage); ?>"> <label for="html" class="radiostyle">HTML</label><br> <input type="radio" id="css" name="fav_language" value="<?php echo($favlanguage); ?>"> <label for="css" class="radiostyle">CSS</label><br> <input type="radio" id="javascript" name="fav_language" value="<?php echo($favlanguage); ?>"> <label for="javascript" class="radiostyle">JavaScript</label><br><br><br> <span id="errorlang"></span><br>
  5. Hey, I echoed the update query and this is what it looks like (before posting). It looks ok to me. UPDATE Form SET FirstName = '', LastName = '', email = '', age = '', Birthdate= '', FavLanguage = '' WHERE FormId = '175' Sorry i've only been doing php for 3 months
  6. Hi Guys, Thanks for the help. I have another problem. The UPDATE statement isn't running correctly. I have a hunch the FormId is not being passed properly to the UPDATE statement. If you could have a look please. Sorry for the long code: <?php include ("db/connect.php"); include ('includes/error.php'); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $FormId = isset($_GET['user_id']) ? $_GET['user_id'] : ""; $queryselect = "SELECT FormId, FirstName, LastName, Email, Age, Birthdate, FavLanguage FROM Form WHERE FormId = '$FormId'"; $result = mysqli_query($link, $queryselect); if (!$result) { printf("Error in connection: %s\n", mysqli_error($link)); exit(); } $table = []; while ( $row = mysqli_fetch_assoc( $result ) ) { $table[] = $row; } if ( count($table) != 1) { exit; } else { print_r($table); $first_name = $table[0]["FirstName"]; $last_name = $table[0]["LastName"]; $email = $table[0]["Email"]; $age = $table[0]["Age"]; $birthday = $table[0]["Birthdate"]; $favlanguage = $table[0]["FavLanguage"]; } $fname=""; $lname=""; $email1=""; $age1=""; $birthday1=""; $fav_language1=""; if(isset($_POST['fname'])){ $fname=$_POST['fname']; } if(isset($_POST['lname'])){ $lname=$_POST['lname']; } if(isset($_POST['email'])){ $email1=$_POST['email']; } if(isset($_POST['age'])){ $age1=$_POST['age']; } if(isset($_POST['birthday'])){ $birthday1=$_POST['birthday']; } if(isset($_POST['fav_language'])){ $fav_language1=$_POST['fav_language']; } $updatequery = "UPDATE Form SET FirstName = '$fname', LastName = '$lname', email = '$email1', age = '$age1', Birthdate= '$birthday1', FavLanguage = '$fav_language1' WHERE FormId = '$FormId'"; $result1 = mysqli_query( $link, $updatequery ); echo ("id is: $FormId"); ?>
  7. Then how would you do it? Build a record set using SELECT and then use foreach?
  8. Hi Thanks, @gizmola - that got rid of the error message but my update form is still not updating. Every time I submit a "modification" and look at the database after, that record is now blank, even though it had data in it before. So something is happening in the UPDATE statement but not the desired result. Sorry the snippet of code I showed did not make it clear I was making an UPDATE form. @ginerjm the storing in the "set of distinct vars" was because I was populating HTML form from SELECT statement (passing variables to value attribute) I was not getting an empty record set because I printed $table using print_r and It showed me the relevant data from the record I was on.
  9. you see the code at the bottom: table[0], i'm using that data, and I know there is data in that because it is populating my form
  10. it does return results, there is a while record set of about 200 records
  11. Hi Guys, I'm getting: Undefined variable: table and count(): Parameter must be an array or an object that implements Countable on the same line of code. I know I have defined $table as an array but it is still giving me an error. Here is the relevant code: The line of code where I have declared $table is inside the while loop Thank you $queryselect = "SELECT FormId, FirstName, LastName, Email, Age, Birthdate, FavLanguage FROM Form WHERE FormId = '$FormId'"; $result = mysqli_query($link, $queryselect); if (!$result) { printf("Error in connection: %s\n", mysqli_error($link)); exit(); } //Fetch the result into an associative array while ( $row = mysqli_fetch_assoc( $result ) ) { $table[] = $row; //add each row into the table array } if ( count($table) != 1 ) { exit; } else { //Collect the values from the database $first_name = $table[0]["FirstName"]; $last_name = $table[0]["LastName"]; $email = $table[0]["Email"]; $age = $table[0]["Age"]; $birthday = $table[0]["Birthdate"]; $favlanguage = $table[0]["FavLanguage"]; }
×
×
  • 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.