yeakyau Posted April 4, 2010 Share Posted April 4, 2010 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/197527-mysql-row-num-invalid-mysql-results-help/ Share on other sites More sharing options...
mmarif4u Posted April 4, 2010 Share Posted April 4, 2010 Maybe you should read more about mysql_num_rows, that how it works. I never see it with update command. http://php.net/manual/en/function.mysql-num-rows.php Quote Link to comment https://forums.phpfreaks.com/topic/197527-mysql-row-num-invalid-mysql-results-help/#findComment-1036684 Share on other sites More sharing options...
greatstar00 Posted April 4, 2010 Share Posted April 4, 2010 if you want to see how many rows are updated, u should use http://php.net/manual/en/function.mysql-affected-rows.php Quote Link to comment https://forums.phpfreaks.com/topic/197527-mysql-row-num-invalid-mysql-results-help/#findComment-1036698 Share on other sites More sharing options...
PFMaBiSmAd Posted April 4, 2010 Share Posted April 4, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/197527-mysql-row-num-invalid-mysql-results-help/#findComment-1036712 Share on other sites More sharing options...
TeddyKiller Posted April 4, 2010 Share Posted April 4, 2010 // 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 Quote Link to comment https://forums.phpfreaks.com/topic/197527-mysql-row-num-invalid-mysql-results-help/#findComment-1036719 Share on other sites More sharing options...
yeakyau Posted April 4, 2010 Author Share Posted April 4, 2010 i just wan if the users ID detected in database only able to make update to the details, if don't have in the database, will echo out invalid, users id. Quote Link to comment https://forums.phpfreaks.com/topic/197527-mysql-row-num-invalid-mysql-results-help/#findComment-1036736 Share on other sites More sharing options...
TeddyKiller Posted April 4, 2010 Share Posted April 4, 2010 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/197527-mysql-row-num-invalid-mysql-results-help/#findComment-1036737 Share on other sites More sharing options...
yeakyau Posted April 4, 2010 Author Share Posted April 4, 2010 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 -.-" Quote Link to comment https://forums.phpfreaks.com/topic/197527-mysql-row-num-invalid-mysql-results-help/#findComment-1036740 Share on other sites More sharing options...
TeddyKiller Posted April 4, 2010 Share Posted April 4, 2010 <?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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/197527-mysql-row-num-invalid-mysql-results-help/#findComment-1036745 Share on other sites More sharing options...
yeakyau Posted April 4, 2010 Author Share Posted April 4, 2010 TQ. solved Quote Link to comment https://forums.phpfreaks.com/topic/197527-mysql-row-num-invalid-mysql-results-help/#findComment-1036751 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.