More than one preg_match queries? [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am a newbie to php and trying to write the code that validates my form.now the problem is I am having trouble in this line of code:
$fullname_pattern = "/[a-zA-Z]+/";
$fullname = $_POST['fullname'];
$email = $_POST['email'];
$email_pattern = "/^[a-zA-Z]+([a-zA-Z0-9]+)?#[a-zA-Z]{3,50}\.(com|net|org)/";
$password = $_POST['password'];
$password_pattern = "/(.){6,12}/";
if(preg_match($fullname_pattern,$fullname)) &&
(preg_match($email_pattern,$email)) &&
(preg_match($password_pattern,$password))
{
header("Location: home.php");
}
else
header("Location: registration.php");
Don't know what to do!

if(preg_match($fullname_pattern,$fullname))
Remove Last ")"
And add here (preg_match($password_pattern,$password)))
Like this:
if(preg_match($fullname_pattern,$fullname)
&& preg_match($email_pattern,$email)
&& preg_match($password_pattern,$password)
) {

Related

Correct verification of request [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I think I miss something about the verification of my PHP request. I'm actually doing $result = $req->fetch(); but result always return false for some reason.
$bdd = new PDO($conStr,$user,$pass);
$req = $bdd->prepare('INSERT INTO users(login, password, dateregister) VALUES(?, ?, NOW())');
$req->execute(array($loginR,$passwordR));
$result = $req->fetch();
Check the return value of execute function for success/failure message
$res = $req->execute(array($login_fieldR,$password_fieldR));
if (!$res )
{
echo '<p id="popup_text">Problem..</p>';
}
else
{
echo '<p id="popup_text">You are registered ! You can logged in now';
}

Update query is not working - need to look [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Can anyone tell where am I wrong in the query. The database in not updating irrespective of the value
<?php
// ================= UPDATE =========================
if ($_POST['SUBMIT']=='SUBMIT')
{
$fixture_id = "$_GET[id]";
$m_date = "$_POST[match_date]";
$m_time = "$_POST[match_time]";
$m_report = "$_POST[match_report]";
$m_a_result = "$_POST[team_a_result]";
$m_b_result = "$_POST[team_b_result]";
$updt = mysql_query("UPDATE `fixture` SET match_date='$m_date', match_time='$m_time', match_report='$m_report', match_a_result='$m_a_result', match_b_result='$m_b_result', status = 1 WHERE id = '$fixture_id'");
header("location:view_fixture.php?msg= You have inserted result successfully...");
}
else
{
header("location:result_update.php?msg= Something went wrong...");
}
// ================================================================================
?>
Before executing this make sure your submit button have a string value of "SUBMIT"
Try this ..
<?php
$fixture_id = $_GET[id];
if ($_POST['SUBMIT']=='SUBMIT')
{
$m_date = $_POST['match_date'];
$m_time = $_POST['match_time'];
$m_report = $_POST['match_report'];
$m_a_result = $_POST['team_a_result'];
$m_b_result = $_POST['team_b_result'];
$updt = mysql_query("UPDATE `fixture` SET match_date= '$m_date', match_time='$m_time', match_report='$m_report', match_a_result='$m_a_result', match_b_result='$m_b_result', status = 1 WHERE id = '$fixture_id'");
header("location:view_fixture.php?msg= You have inserted result successfully...");
}
else
{
header("location:result_update.php?msg= Something went wrong...");
}
?>
Please DO NOT USE mysql_* . It is now deprecated

Session to display current login User [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I have a problem with my code. I want to make a Seesion which display the current login user
Thank you !
$link = mysql_connect($DB_server, $DB_user, $DB_password,$DB_name);
mysql_select_db('linux', $link) or die(mysql_error());
$uid = 0;
if(isset($_GET["id"]))
{
$uid = $_GET["id"];
}
$profilname = mysql_query("SELECT U_Benutzername ,U_ID FROM u_user WHERE U_ID = '$uid'");
$emailadresse =mysql_query("SELECT U_login ,U_ID FROM u_user WHERE U_ID = '$uid'");
$_SESSION['profilname'] = $profilname;
$_SESSION['email'] =$emailadresse;
echo "Benutzername: $profilname";
echo "<br/>";
echo "Email: $profilname";
You have a typo...
$lid = $_GET["id"];
should probably be
$uid = $_GET["id"];
change your mysql query to:
if($uid!=0) {
$ref = mysql_query("SELECT * FROM u_user WHERE U_ID = '$uid'");
$row = mysql_fetch_array($ref);
$profilname = $row["U_Benutzername"];
$emailadresse= $row["U_login"];
$_SESSION['profilname'] = $profilname;
$_SESSION['email'] =$emailadresse;
}
to display it:
echo $_SESSION['profilname'];
BUT:
You wont get far with this, this is mysql_-code and its deprecated.
You have to use mysqli in newer PHP-Versions.
http://php.net/manual/de/book.mysqli.php
Change $lid = $_GET["id"]; to $uid = $_GET["id"];, and it also is a good idea to sanitize the data from $_GET,

I get error when i use mysqli select [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
<?php if($_POST) {
$username = htmlspecialchars($_POST['username']);
$password = htmlspecialchars($_POST['password']);
$mysqli = new mysqli('localhost','root','','movie_posters');
$query = $mysqli->query("SELECT password FROM users WHERE username = '"$username"'");
} ?>
When I try this code on WAMP, I get error like; this http://i.stack.imgur.com/qcifR.jpg
What can I do ?
Do not use single and double quotes in your query.
This is the right way:
$query = $mysqli->query("SELECT password FROM users WHERE username = '$username'");
Otherwise, you will not print $username's value.
You have to put periods before and after you variable.
In your example:
$query = $mysqli->query("SELECT password FROM users WHERE username = '".$username."'");

PHP if Statement [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Hello guys i don't know what is call if or switch statement.
i have database table field which is call price, so i want to make if the price if the price field empty its show "please Call us for the price " and if the price field is not its i will show what ever i put it..
here is my code but i don't know why its not working..
any body can help please
thanks you
<?php
$result = mysql_query("SELECT * FROM articles where articlefriendlyURL='%s'",mysql_real_escape_string($aid));
while($row = mysql_fetch_assoc($result)) {
if ($row['price']; = = '') {
echo ("Please Call Us for the price");
else {
echo $row_getArticle['price'];
}
}
}
?>
You can't separate the equals signs or its no longer a conditional statement to check the equal to. you also had a syntax error with your if/else from the brackets. Try this:
<?php
$result = mysql_query("SELECT * FROM articles where articlefriendlyURL='%s'",mysql_real_escape_string($aid));
while($row = mysql_fetch_assoc($result)) {
if (empty($row['price'])) {
echo ("Please Call Us for the price");
} else {
echo $row['price'];
}
}
?>
I think the problem is on
if ($row['price']; = = '0')
I think the correct syntax of that statement is
if ($row['price'] == '0')

Categories