Reputation: 437
Im just new and still learning PHP.
Im trying to make a simple PHP for connecting and doing basic syntax insert, delete,select and update but I encountered an error Undefined Variable: Get in C:/wamp/www/sql
. Is there something I missed?
Here is what i got:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$port = "3306";
$dbname = "student";
$conn = mysqli_connect($servername, $username, $password, $dbname, $port);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM info";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "ID: " . $row["studentid"]. " Name: " . $row["fname"]. " " . $row["lname"]." <a href = delete.php? uid=".$row["studentid"]."> Delete</a> |
<a href = test.php? euid=".$row['studentid']."&elname".$row['lname']."&efname".$row['fname']."> Edit </a> <br/>" ;
}
} else {
echo "0 results";
}
?>
<form action ="insert.php" method="POST">
<input type ="text" name="fname">
<input type ="text" name="lname">
<input type ="submit"value="Submit">
</form>
<form action ="update.php" method="POST">
<input type ="hidden" name="ID"<?php echo"value=".$GET["studentid"];?>> //I get the error from here
<input type ="text" name="fname"<?php echo"value=".$GET['fname'];?>>
<input type ="text"name="lname"<?php echo"value=".$GET['lname'];?>>. // until here
<input type ="submit"value="Update">
</form>
<?php
mysqli_close($conn);
?>
Edit: Here is the other one im having trouble with.I get there error Parse error: syntax error, unexpected '<' in
How to fix it?. In this part of code:
<?php
if(isset($_GET['xID']))
{
<form action ="update.php" method="POST">
<input type ="hidden" name="ID"<?php echo"value=".$_GET['xID'];?>>
<input type ="text" name="fname"<?php echo"value=".$_GET['xfname'];?>>
<input type ="text"name="lname"<?php echo"value=".$_GET['xlname'];?>>.
<input type ="submit"value="Update">
}
else
{
}
</form>
?>
Upvotes: 0
Views: 48
Reputation: 44
In addition to the syntax error (it's $_GET
and not $GET
), you are also using POST as method to send the data, be sure to learn the difference between GET
and POST
methods.
You should also know that you can use use $_REQUEST
to retrieve the data sent via both GET
and POST
.
The following should be correct:
<form action ="update.php" method="GET">
<input type ="hidden" name="ID"<?php echo"value=".$_REQUEST["studentid"];?>>
<input type ="text" name="fname"<?php echo"value=".$_REQUEST['fname'];?>>
<input type ="text"name="lname"<?php echo"value=".$_REQUEST['lname'];?>>.
<input type ="submit"value="Update">
</form>
Upvotes: 0
Reputation: 11987
you using get as wrong, its not $GET
, its $_GET
, chenge your code like this.
<form action ="update.php" method="GET">
<input type ="hidden" name="ID"<?php echo"value=".$_GET["studentid"];?>> //I get the error from here
<input type ="text" name="fname"<?php echo"value=".$_GET['fname'];?>>
<input type ="text"name="lname"<?php echo"value=".$_GET['lname'];?>>. // until here
<input type ="submit"value="Update">
</form>
Upvotes: 3