I need to convert to current PHP

Asked

Viewed 38 times

-1

I have an old form that would like to adjust a page with current PHP parameters. Follows code:

<?php include "login_senha.php";

$email = $_POST['email'];

$sql = mysql_query("SELECT * FROM usuarios WHERE email = '$email'");
while($linha = mysql_fetch_array($sql)) {
    $email_db = $linha['email'];
}
$cont = mysql_num_rows($sql);

if($cont == 0){
echo"
<meta http-equiv='refresh' content='0; url=cadastro02.php' />
<script type='text/javascript'>alert('Login nao existe')</script>
";
} else {
if($senha_db !=$senha){
echo"
<meta http-equiv='refresh' content='0; url=cadastro02.php' />
<script type='text/javascript'>alert('Senha nao corresponde')</script>
";
} else {
session_start();
$_SESSION['email_usuario'] = $email;

header("Location: segunda.php");
}
}
$sql = mysql_query("SELECT * FROM dropdown");
while($record = mysql_fetch_array($sql)) {
    echo '<option value="' . $record['item'] , '">' . $record['item'] .'"</option>';

}

mysql_close($db);

?>

If I’m not mistaken today is no more mysql and yes mysqli, correct?

2 answers

0

It works yes, there must be some other error in your code...

Take a look at the php manual for every function that doesn’t work.

https://www.php.net/manual/en/mysqli-result.fetch-array.php

I tested this code below using shaman and local base and it worked correctly.

<?php
$link = mysqli_connect("localhost", "root", "", "base_teste");

$mysqli = new mysqli("localhost", "root", "", "base_teste");
/* check connection */
if ($mysqli->connect_errno) {
    echo printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}

$query = "SELECT * FROM usuarios";
$result = mysqli_query($link, $query);

while ($linha = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    $email_db = $linha['email'];
    echo '<br> email: ' . $email_db;
}

  • Hi friend, it worked, listed all the emails from my database, but it turns out that it does not log in, says that user does not exist, and is there in the listing that it shows. But thank you very much for your attention.

-2

SO change from "mysql_" to "mysqli_", use CTRL + SPACE that will fill in correctly. It’s all about testing...

  • Good night, buddy, it didn’t work out. I can connect to the bank, I did the tests here, but he’s not able to read the data, I did what you told me, but he can’t recognize the user registered in the database. Gives the message of how he didn’t exist. :(

Browser other questions tagged

You are not signed in. Login or sign up in order to post.