I have a MySQL table with a number of columns, including one called ‘Name’.
I would like to design a form for a webpage which consists of two textboxes, A and B. In textbox A the user would be required to enter their name, and in textbox B some other information.
I would like the PHP script to check if the Name in Textbox A matches a value already in the Name column in the MySQL table, and if it does, add the value in Textbox B to another column in this table. If the name is not found, I would like the script to return an error, along the lines of “Your booking was not found on our database”.
Is it possible to do this using PHP/MySQL and if it is, how would I go about this?
CURRENT CODE
$row_count = count($_POST['name']);
mysql_select_db($database, $connection);
if ($row_count > 0) {
$values = array();
for($i = 0; $i < $row_count; $i++) {
// variable sanitation...
$name = mysql_real_escape_string(ucwords($_POST['name'][$i]));
$workshop = mysql_real_escape_string($_POST['workshop'][$i]);
$query = "SELECT * FROM conference WHERE Name = '$name' ";
$result = mysql_query($query);
if ($result) {
$rowcount = mysql_num_rows($result);
if ($rowcount == 0) {echo "no bookings found"; }
else {
$row = mysql_fetch_row($result);
$sql = "UPDATE conference SET Workshop = '$workshop' WHERE Name = '$name'";
mysql_query($sql);
}
}
}
}
This should get you started.
See here: http://php.net/manual/en/book.mysql.php
Comments on the code