mysql - PHP Redirecting based on this error -
(please bear me.) want redirect page if error produced. if there duplicate entry in database (i.e. if goes wrong after submission db user resubmits page.)
error: insert di_ssenisub (timestamp, business_name, business_type, username, main_email, password) values (now(), '123', 'hotel', '123', 'jkljllk@mrmd.com', '$2y$10$gyxxbmhknmqrehhb2qow8uvvs7hnomdn4otpv8m98.ln/3r6mwseg') duplicate entry '123' key ‘primary’
my code set on else:
else { echo "error: " . $insertsql . "<br>" . mysqli_error($link); }
what want redirect them log in/error page, can log in , finish registration admin panel.
any thoughts? thanks.
$insertsql = sprintf("insert di_ssenisub (timestamp, business_name, business_type, username, main_email, password) values (now(), %s, %s, %s, %s, %s)", getsqlvaluestring($business_name, "text"), getsqlvaluestring($business_type, "text"), getsqlvaluestring($_post['username_entry'], "text"), getsqlvaluestring($main_email, "text"), getsqlvaluestring($hashpass, "text")); if (mysqli_query($link, $insertsql)) { session_start(); $_session['username'] = $username_check; $_session['business_name'] = $business_name; $_session['business_type'] = $business_type; header('location: ../../register/' .$business_type_link); } "update $table_name set business_name='$business_name', business_type='$business_type', username=$username_entry, main_email='$main_email', password = '$hashpass' id='$user_id' limit 1"); mysqli_close($link);
update
$insertsql = sprintf("insert di_ssenisub (timestamp, business_name, business_type, username, main_email, password) values (now(), %s, %s, %s, %s, %s)", getsqlvaluestring($business_name, "text"), getsqlvaluestring($business_type, "text"), getsqlvaluestring($_post['username_entry'], "text"), getsqlvaluestring($main_email, "text"), getsqlvaluestring($hashpass, "text")); $affected += mysqli_rows_affected($link); $insert_error = mysqli_errorno($link); "update $table_name set business_name='$business_name', business_type='$business_type', username=$username_entry, main_email='$main_email', password = '$hashpass' id='$user_id' limit 1"); $affected += mysqli_rows_affected($link); $insert_error = mysqli_errorno($link); session_start(); $_session['username'] = $username_check; $_session['business_name'] = $business_name; $_session['business_type'] = $business_type; } mysqli_close($link);
after insert , update, check data if problem.
and users favor, not reject user name. allow duplicate user names.
if want use unique user names , force user come unique name, add analytics see how many abandon site rather continue sign up.
if unique user name must used here on stackoverflow, have user name log in , on screen name. stackoverflow uses email log in.
if ($affected == 0){ // error detection / correction here // create warnings include('form.php'); exit } else{ include('next_page.php'); }
end of update
you not want redirect
use include, , repopulate inputs.
to eliminate duplicate first insert , follow insert update.
insert di_ssenisub (timestamp, business_name, business_type, username, main_email, password)
no need check error faster update. quick when record exists.
update `di_ssenisub` set `business_name` = '123', `business_type`,... `username` = '123';
the term uses columns in primary index. rest go in set.
if want validate values if find problem not redirect (`header("location: ')
you want pass problems found on user.
let's find problem invalid email:
$warn_email = '*";
include('form.php'); exit;
in form.php
$warn_email<inpupt name="email"
repopulate inputs
you have submitted data:
$timestamp = $_post['timestamp']; $business_name = $_post['business_name']; $business_type = $_post['business_type']; $username = $_post['username']; $main_email = $_post['main_email'];
with include these values automatically passed form.
<input type="text" name="business_name" value="$business_name" /> <input type="text" name="business_type" value="$business_type" /> <input type="text" name="username" value="$username" /> <input type="text" name="main_email" value="$main_email" />
if going in fresh, variables empty, , value=""
in html.
if want check insert , or update error this:
$affected = 0; insert ... $affected += mysqli_rows_affected($link); update ... $affected += mysqli_rows_affected($link); if ($affected == 0){echo 'houston have problem';}
Comments
Post a Comment