I've gotten it work for email or name, but not for both. This was using the if(empty) or using strlen.
But I'm sure there a cleaner way and for getting both name and email to do this.
Search page:
<?php
// Get value from HTML form
$name = $_POST['name'];
$connection = mysql_connect('xxxxxxx');
if (! $connection) {
die('Error connecting to database ' .
mysql_error());
}
$name = mysql_real_escape_string($name);
// select the proper database (your username)
mysql_select_db('User');
// run the query with the properly escaped string
$result = mysql_query(
"SELECT * FROM User WHERE name like '%$name%'"
);
// Check that there were results
if(!$result){
die('No results ' . mysql_error());
}
echo "<form method='post' action='update.php'>";
while ($row = mysql_fetch_array($result)) {
echo "User Info<br />\n";
echo "<input type='hidden' name='userid' value='$row[USERID]' />\n";
echo "User Name: <input type='text' name='name' value='$row[name]' /><br />\n";
echo "User Email: <input type='text' name='email' value='$row[email]' /><br />\n";
echo "<input type='submit' value='Save' />\n</form>";
// Print number of matching donors
echo 'There were ', mysql_num_rows($result), 'Matching Users';
// process results
while ($row = mysql_fetch_array($result)) {
echo "User Info<br />";
echo "User Name: $row[name]<br />";
echo "User Email: $row[email]<br />";
echo "User ID: $row[USERID]<br /><br />";
}
?>
Update page:
<?php
// Get value from HTML form
$name = $_POST['name'];
$email = $_POST['email'];
$userid = $_POST['userid'];
// Connect using your username and password.
$connection = mysql_connect(xxxxxxxxx);
if (!$connection) {
die("Error connecting to database " . mysql_error());
}
// Secure the data before it is used
$name = mysql_real_escape_string($name);
$email = mysql_real_escape_string($email);
// select the proper database
mysql_select_db("User");
// Create the query
$result =
mysql_query("UPDATE User set name= '$name',
email = '$email' WHERE USERID = '$userid'");
// Find number of affected rows
echo mysql_affected_rows()," row was updated";
?>