Jump to content

Recommended Posts

<?php

$host=""; // Host name

$username=""; // Mysql username

$password=""; // Mysql password

$db_name=""; // Database name

$tbl_name="members"; // Table name

 

// Connect to server and select database.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

$userid=$_POST['userid'];

$password=$_POST['password'];

$name=$_POST['name'];

$lastname=$_POST['lastname'];

$email=$_POST['email'];

$gender=$_POST['gender'];

$address=$_POST['address'];

$country=$_POST['country'];

 

 

 

// update data in mysql database

$sql="UPDATE $tbl_name SET password='$password', name='$name', lastname='$lastname', email='$email', gender='$gender', address='$address', country='$country' WHERE userid='$userid'";

$result=mysql_query($sql);

 

// Mysql_num_row is counting table row

$count=mysql_num_rows($result);

// If result matched $ic and $password, table row must be 1 row

 

if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"

session_register("userid");

session_register("password");

header("location:home.php");

}

else {

echo '<script type="text/javascript">

alert("Provide Wrong Username Or Password , Please TrY Again!!!");

window.location.href = "index.php";         

</script>';

}

?>

anyone pls help why it's get eRror on line 28.

it said warning myswl_num_row (): supplied argument is not a valid mysql_ results resource inline 28

The code up to the mysql_query() statement is attempting to UPDATE an existing record in your members table. The code after that point is from a log in script. Updating a record and logging someone in are two different tasks and your code really does not make any sense. What are you trying to accomplish in that code?

// update data in mysql database
$sql="UPDATE $tbl_name SET password='$password', name='$name', lastname='$lastname', email='$email', gender='$gender', address='$address', country='$country' WHERE userid='$userid'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $ic and $password, table row must be 1 row

 

Sorry to say, you can't get mysql_num_rows if your doing an update query.

 

What you'd do.. is this.

// update data in mysql database
$sql="UPDATE $tbl_name SET password='$password', name='$name', lastname='$lastname', email='$email', gender='$gender', address='$address', country='$country' WHERE userid='$userid'";
$result=mysql_query($sql);

//Get some results from the database
$sql="SELECT * FROM $tbl_name WHERE userid='$userid'";
$result1=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result1);
// If result matched $ic and $password, table row must be 1 row

Try this..

<?php
//Get some results from the database
$sql = "SELECT * FROM $tbl_name WHERE userid='$userid'";
$result = mysql_query($sql);

// Mysql_num_row is counting table row
if(mysql_num_rows($result) == 1) {
// update data in mysql database
$sql = "UPDATE $tbl_name SET password='$password', name='$name', lastname='$lastname', email='$email', gender='$gender', address='$address', country='$country' WHERE userid='$userid'";
$result = mysql_query($sql);
}
?>

ok  work but how to put echo ur users id not in database  >.< once i put get an error .  unexpected end.

i'm trying to put this

if($result){

echo "Successful";

echo "<BR>";

echo "<a href='home.php'>go to home</a>";

}

 

else {

echo "users id not found in database";

}

 

?>

i get an error unexpected end -.-"

<?php
//Get some results from the database
$sql = "SELECT * FROM $tbl_name WHERE userid='$userid'";
$result = mysql_query($sql);

// Mysql_num_row is counting table row
if(mysql_num_rows($result) == 1) {
     // update data in mysql database
     $sql = "UPDATE $tbl_name SET password='$password', name='$name', lastname='$lastname', email='$email', gender='$gender', address='$address', country='$country' WHERE userid='$userid'";
     $result = mysql_query($sql);

     echo "Successful <br /> <a href='home.php'>go to home</a>";
} else { echo "users id not found in database"; }
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.