I need help on this

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mphatso
Forum Newbie
Posts: 1
Joined: Sun Dec 20, 2020 4:46 am

I need help on this

Post by Mphatso »

Am new to php,
i have a problem am trying to check if data already exist in my database but when i run the code it keeps on giving me errors.

error1-Warning: mysql_query() expects parameter 1 to be string, resource given in C:\wamp\www\New folder\trial\code.php on line 47
error2-Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\wamp\www\New folder\trial\code.php on line 48

here is the code..

Code: Select all

if(isset($_POST['submit_login']))
{
$username= $_POST['email'];
$password = $_POST['pass'];


$query2="SELECT * FROM customer_details WHERE email=\"$username\" AND password=\"$password\"";

$result2 = mysql_query($con,$query2);
$row=mysql_num_rows($result2);
if(!$row)
{
echo"Please try again";
}
else
{
header("Location:landing.html");
}
}
:( :( :( :(
User avatar
Benjamin
Site Administrator
Posts: 6888
Joined: Sun May 19, 2002 10:24 pm

Re: I need help on this

Post by Benjamin »

Hi.

Checkout the manual for the mysql_query method here: https://www.php.net/manual/en/function.mysql-query

You'll notice that the first parameter should be the query, while the second parameter should be the connection.

You should also notice this method is depreciated, so instead you should be using the MySQLi extensions.

Code: Select all

<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

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

/* Create table doesn't return a resultset */
if ($mysqli->query("CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) {
    printf("Table myCity successfully created.\n");
}

/* Select queries return a resultset */
if ($result = $mysqli->query("SELECT Name FROM City LIMIT 10")) {
    printf("Select returned %d rows.\n", $result->num_rows);

    /* free result set */
    $result->close();
}

/* If we have to retrieve large amount of data we use MYSQLI_USE_RESULT */
if ($result = $mysqli->query("SELECT * FROM City", MYSQLI_USE_RESULT)) {

    /* Note, that we can't execute any functions which interact with the
       server until result set was closed. All calls will return an
       'out of sync' error */
    if (!$mysqli->query("SET @a:='this will not work'")) {
        printf("Error: %s\n", $mysqli->error);
    }
    $result->close();
}

$mysqli->close();
Post Reply