zgkhoo Posted August 20, 2007 Share Posted August 20, 2007 <?php include 'config.php'; include 'opendb.php'; function generatePassword ($length = 13) { // start with a blank password $password = ""; // define possible characters $possible = "0123456789bcdfghjkmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // set up a counter $i = 0; // add random characters to $password until $length is reached while ($i < $length) { // pick a random character from the possible ones $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); // we don't want this character if it's already in the password if (!strstr($password, $char)) { $password .= $char; $i++; } } // done! return $password; } //connect to database $con = mysql_connect("localhost","root",""); //if mysql doesnt exist if (!$con){ die('Could not connect: ' . mysql_error()); } //select database mysql_select_db("my_db", $con); // Create table in my_db database $sql = "CREATE TABLE gamecard ( Serialnum varchar(13), Activatecode varchar(13), Ownerid varchar(13), Status varchar(13), Downleft varchar(13), Downright varchar(13), Upline varchar(13), Expireddate varchar(13), Createdate varchar(13), Point varchar(13) )"; mysql_query($sql,$con); $result = mysql_query("SELECT * FROM gamecard") or die('Query failed: ' . mysql_error()); while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ $serial=$row["Serialnum"]; echo "serial=".$serial; }; $serial++; $cardnum=$_POST['cardnum']; $count=0; while ($count<$cardnum) { $randompass=generatePassword(); //insert into table $sql="INSERT INTO gamecard (Serialnum,Activatecode) VALUES ('$serial','$randompass')"; //insert into table (action) mysql_query($sql,$con); //if (!mysql_query($sql,$con)) // { // die('Error: ' . mysql_error()); // } //display successful message echo "card successful registered!, 1 record added"; $count++; $serial++; }//end of while loop //display database record //$result = mysql_query("SELECT * FROM gamecard"); //while($row = mysql_fetch_array($result)) // { // echo $row['serialnum'] ; // echo "<br />"; // } ?> <?php session_start(); if(isset($_POST["ic"])) { $_SESSION["ic"] = $_POST["ic"]; } if(isset($_POST["fullname"])) { $_SESSION["fullname"] = $_POST["fullname"]; } if(isset($_POST["gender"])) { $_SESSION["gender"] = $_POST["gender"]; } if(isset($_POST["dob"])) { $_SESSION["dob"] = $_POST["dob"]; } if(isset($_POST["address"])) { $_SESSION["address"] = $_POST["address"]; } if(isset($_POST["postcode"])) { $_SESSION["postcode"] = $_POST["postcode"]; } if(isset($_POST["city"])) { $_SESSION["city"] = $_POST["city"]; } if(isset($_POST["state"])) { $_SESSION["state"] = $_POST["state"]; } if(isset($_POST["phonenumber"])) { $_SESSION["phonenumber"] = $_POST["phonenumber"]; } if(isset($_POST["hpnumber"])) { $_SESSION["hpnumber"] = $_POST["hpnumber"]; } if(isset($_POST["banktype"])) { $_SESSION["banktype"] = $_POST["banktype"]; } if(isset($_POST["accname"])) { $_SESSION["accname"] = $_POST["accname"]; } if(isset($_POST["accnumber"])) { $_SESSION["accnumber"] = $_POST["accnumber"]; } //$_SESSION["gender"] = $_POST["gender"]; //$_SESSION["address"] = $_POST["address"]; //$_SESSION["postcode"] = $_POST["postcode"]; //$_SESSION["city"] = $_POST["city"]; //$_SESSION["state"] = $_POST["state"]; //$_SESSION["phonenumber"] = $_POST["phonenumber"]; //$_SESSION["hpnumber"] = $_POST["hpnumber"]; //$_SESSION["banktype"] = $_POST["banktype"]; //$_SESSION["accname"] = $_POST["accname"]; //$_SESSION["accnumber"] = $_POST["accnumber"]; //store data into variable echo "<br>"; echo "Username = "; echo $_SESSION["username"]; echo "<br>"; echo "Password = "; echo $_SESSION["password"]; echo "<br>"; echo "Country = "; echo $_SESSION["country"]; echo "<br>"; echo "IC = "; echo $_SESSION["ic"]; echo "<br>"; echo "Fullname = "; echo $_SESSION["fullname"]; echo "<br>"; echo "Gender = "; echo $_SESSION["gender"]; echo "<br>"; echo "DOB = "; echo $_SESSION["dob"]; echo "<br>"; echo "Address = "; echo $_SESSION["address"]; echo "<br>"; echo " Postcode= "; echo $_SESSION["postcode"]; echo "<br>"; echo "City = "; echo $_SESSION["city"]; echo "<br>"; echo "State = "; echo $_SESSION["state"]; echo "<br>"; echo "Phone Number = "; echo $_SESSION["phonenumber"]; echo "<br>"; echo "HP Number = "; echo $_SESSION["hpnumber"]; echo "<br>"; echo "BankYype = "; echo $_SESSION["banktype"]; echo "<br>"; echo "Account Name = "; echo $_SESSION["accname"]; echo "<br>"; echo "Account Number = "; echo $_SESSION["accnumber"]; echo "<br>"; echo "Card ID= "; echo $_SESSION["cardID"]; echo "<br>"; echo "Upline ID= "; echo $_SESSION["uplineID"]; if(isset($_REQUEST['button'])) { echo "<BR/>"."Thank you for your registration"; $con = mysql_connect("localhost","root",""); mysql_select_db("my_db", $con); $sql = "CREATE TABLE person ( Username varchar(13), Password varchar(13), Country varchar(10), IC varchar(13), FullName varchar(40), Gender varchar(15), DOB varchar(15), Address varchar(80), Postcode varchar(10), City varchar(20), State varchar(20), PhoneNumber varchar(15), HpNumber varchar(15), BankType varchar(30), AccName varchar(40), AccNumber varchar(15) )"; mysql_query($sql,$con); //insert into table $sql="INSERT INTO person (Username,Password,Country,IC,FullName,Gender,DOB,Address,Postcode,City,State,PhoneNumber,HpNumber,BankType,AccName,AccNumber) VALUES ('$_SESSION[username]','$_SESSION[password]','$_SESSION[country]', '$_SESSION[ic]','$_SESSION[fullname]','$_SESSION[gender]','$_SESSION[dob]', '$_SESSION[address]','$_SESSION[postcode]','$_SESSION[city]','$_SESSION[state]', '$_SESSION[phonenumber]','$_SESSION[hpnumber]','$_SESSION[banktype]', '$_SESSION[accname]','$_SESSION[accnumber]')"; mysql_query($sql,$con); echo "</br>"; echo "<a href=\"main.php\">back to main </a>"; //begin checking card id $result = mysql_query("SELECT * FROM gamecard where Serialnum=$_SESSION[cardID]") or die('Query failed: ' . mysql_error()); $numrows=mysql_num_rows($results); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; } }//end of isset ?> <html> <body> <form name='noname' action='register3.php' method=post> <input type="submit" name='button' value='comfirm'> </form> </body> </html> when i typed in wrong cardID in the form...error = back to main Query failed: Unknown column 'testing999' in 'where clause' when i typed the correct(which is '2') cardID in the form error= Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\register3.php on line 195 Sorry, your search: "" returned zero results Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/ Share on other sites More sharing options...
trq Posted August 20, 2007 Share Posted August 20, 2007 Can you please narrow your code down to the problematic query. Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-328822 Share on other sites More sharing options...
zgkhoo Posted August 20, 2007 Author Share Posted August 20, 2007 first php file // Create table in my_db database $sql = "CREATE TABLE gamecard ( Serialnum varchar(13), Activatecode varchar(13), Ownerid varchar(13), Status varchar(13), Downleft varchar(13), Downright varchar(13), Upline varchar(13), Expireddate varchar(13), Createdate varchar(13), Point varchar(13) )"; mysql_query($sql,$con); $result = mysql_query("SELECT * FROM gamecard") or die('Query failed: ' . mysql_error()); while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ $serial=$row["Serialnum"]; echo "serial=".$serial; }; $serial++; $cardnum=$_POST['cardnum']; $count=0; while ($count<$cardnum) { $randompass=generatePassword(); //insert into table $sql="INSERT INTO gamecard (Serialnum,Activatecode) VALUES ('$serial','$randompass')"; //insert into table (action) mysql_query($sql,$con); //if (!mysql_query($sql,$con)) // { // die('Error: ' . mysql_error()); // } //display successful message echo "card successful registered!, 1 record added"; $count++; $serial++; }//end of while loop another file file //begin checking card id $result = mysql_query("SELECT * FROM gamecard where Serialnum=$_SESSION[cardID]") or die('Query failed: ' . mysql_error()); $numrows=mysql_num_rows($results); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; } }//end of isset thanks.. Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-328927 Share on other sites More sharing options...
itsmeArry Posted August 20, 2007 Share Posted August 20, 2007 at line 195 you have $numrows=mysql_num_rows($results); but you are getting the result in "$result" change line 195 to $numrows=mysql_num_rows($result); Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-328929 Share on other sites More sharing options...
zgkhoo Posted August 21, 2007 Author Share Posted August 21, 2007 i added bellowing code but it cant update Ownerid, the $cardID,$_SESSION[ic] all correct. if ($numrows == 0) { echo "testing3"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; } else{ echo "testing4"; echo "cardID=".$cardID; while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ $serial=$row["Serialnum"]; echo "serial=".$serial; echo "ic=".$_SESSION[ic]; } echo "testing5"; mysql_query("UPDATE gamecard SET Ownerid = $_SESSION[ic] where Serialnum =$cardID"); echo "testing6"; } Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329490 Share on other sites More sharing options...
teng84 Posted August 21, 2007 Share Posted August 21, 2007 try something like $result = mysql_query("SELECT * FROM gamecard where Serialnum=".$_SESSION['cardID']."") or die('Query failed: ' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329505 Share on other sites More sharing options...
zgkhoo Posted August 21, 2007 Author Share Posted August 21, 2007 the query is correct which successful display the following code's message while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ $serial=$row["Serialnum"]; echo "serial=".$serial; }; nevermind i try it then let u know.. thanks 1st. Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329551 Share on other sites More sharing options...
sandy1028 Posted August 21, 2007 Share Posted August 21, 2007 Try the query like this $result = "SELECT * FROM gamecard where Serialnum=".$_SESSION['cardID']."; $res= mysql_query($result); Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329553 Share on other sites More sharing options...
bache Posted August 21, 2007 Share Posted August 21, 2007 You should have quotation marks around $_SESSION['cardID'] because Serialnum is varchar and that's way you get "Query failed: Unknown column" for example: select * from gamecard where Serialnum = 'asdf' Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329559 Share on other sites More sharing options...
zgkhoo Posted August 21, 2007 Author Share Posted August 21, 2007 like this? $cardID=$_SESSION['cardID']; <---here? selection A $result = mysql_query("SELECT * FROM gamecard where Serialnum='$cardID'") <--or here? selection B or die('Query failed: ' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329564 Share on other sites More sharing options...
bache Posted August 21, 2007 Share Posted August 21, 2007 yeah, both Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329565 Share on other sites More sharing options...
zgkhoo Posted August 21, 2007 Author Share Posted August 21, 2007 <?php session_start(); if(isset($_POST["ic"])) { $_SESSION["ic"] = $_POST["ic"]; } if(isset($_POST["fullname"])) { $_SESSION["fullname"] = $_POST["fullname"]; } if(isset($_POST["gender"])) { $_SESSION["gender"] = $_POST["gender"]; } if(isset($_POST["dob"])) { $_SESSION["dob"] = $_POST["dob"]; } if(isset($_POST["address"])) { $_SESSION["address"] = $_POST["address"]; } if(isset($_POST["postcode"])) { $_SESSION["postcode"] = $_POST["postcode"]; } if(isset($_POST["city"])) { $_SESSION["city"] = $_POST["city"]; } if(isset($_POST["state"])) { $_SESSION["state"] = $_POST["state"]; } if(isset($_POST["phonenumber"])) { $_SESSION["phonenumber"] = $_POST["phonenumber"]; } if(isset($_POST["hpnumber"])) { $_SESSION["hpnumber"] = $_POST["hpnumber"]; } if(isset($_POST["banktype"])) { $_SESSION["banktype"] = $_POST["banktype"]; } if(isset($_POST["accname"])) { $_SESSION["accname"] = $_POST["accname"]; } if(isset($_POST["accnumber"])) { $_SESSION["accnumber"] = $_POST["accnumber"]; } //$_SESSION["gender"] = $_POST["gender"]; //$_SESSION["address"] = $_POST["address"]; //$_SESSION["postcode"] = $_POST["postcode"]; //$_SESSION["city"] = $_POST["city"]; //$_SESSION["state"] = $_POST["state"]; //$_SESSION["phonenumber"] = $_POST["phonenumber"]; //$_SESSION["hpnumber"] = $_POST["hpnumber"]; //$_SESSION["banktype"] = $_POST["banktype"]; //$_SESSION["accname"] = $_POST["accname"]; //$_SESSION["accnumber"] = $_POST["accnumber"]; //store data into variable echo "<br>"; echo "Username = "; echo $_SESSION["username"]; echo "<br>"; echo "Password = "; echo $_SESSION["password"]; echo "<br>"; echo "Country = "; echo $_SESSION["country"]; echo "<br>"; echo "IC = "; echo $_SESSION["ic"]; echo "<br>"; echo "Fullname = "; echo $_SESSION["fullname"]; echo "<br>"; echo "Gender = "; echo $_SESSION["gender"]; echo "<br>"; echo "DOB = "; echo $_SESSION["dob"]; echo "<br>"; echo "Address = "; echo $_SESSION["address"]; echo "<br>"; echo " Postcode= "; echo $_SESSION["postcode"]; echo "<br>"; echo "City = "; echo $_SESSION["city"]; echo "<br>"; echo "State = "; echo $_SESSION["state"]; echo "<br>"; echo "Phone Number = "; echo $_SESSION["phonenumber"]; echo "<br>"; echo "HP Number = "; echo $_SESSION["hpnumber"]; echo "<br>"; echo "BankYype = "; echo $_SESSION["banktype"]; echo "<br>"; echo "Account Name = "; echo $_SESSION["accname"]; echo "<br>"; echo "Account Number = "; echo $_SESSION["accnumber"]; echo "<br>"; echo "Card ID= "; echo $_SESSION["cardID"]; echo "<br>"; echo "Upline ID= "; echo $_SESSION["uplineID"]; if(isset($_REQUEST['button'])) { echo "<BR/>"."Thank you for your registration"; $con = mysql_connect("localhost","root",""); mysql_select_db("my_db", $con); $sql = "CREATE TABLE person ( Username varchar(13), Password varchar(13), Country varchar(10), IC varchar(13), FullName varchar(40), Gender varchar(15), DOB varchar(15), Address varchar(80), Postcode varchar(10), City varchar(20), State varchar(20), PhoneNumber varchar(15), HpNumber varchar(15), BankType varchar(30), AccName varchar(40), AccNumber varchar(15) )"; mysql_query($sql,$con); //insert into table $sql="INSERT INTO person (Username,Password,Country,IC,FullName,Gender,DOB,Address,Postcode,City,State,PhoneNumber,HpNumber,BankType,AccName,AccNumber) VALUES ('$_SESSION[username]','$_SESSION[password]','$_SESSION[country]', '$_SESSION[ic]','$_SESSION[fullname]','$_SESSION[gender]','$_SESSION[dob]', '$_SESSION[address]','$_SESSION[postcode]','$_SESSION[city]','$_SESSION[state]', '$_SESSION[phonenumber]','$_SESSION[hpnumber]','$_SESSION[banktype]', '$_SESSION[accname]','$_SESSION[accnumber]')"; mysql_query($sql,$con); echo "</br>"; echo "<a href=\"main.php\">back to main </a>"; //begin checking card id $cardID=$_SESSION['cardID']; $result = mysql_query("SELECT * FROM gamecard where Serialnum='$cardID'") or die('Query failed: ' . mysql_error()); $numrows=mysql_num_rows($result); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "testing3"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; } else{ echo "testing4"; echo "cardID=".$cardID; while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ $serial=$row["Serialnum"]; echo "serial=".$serial; echo "ic=".$_SESSION[ic]; } echo "testing5"; mysql_query("UPDATE gamecard SET Ownerid = $_SESSION[ic] where Serialnum ='$cardID'"); echo "testing6"; } }//end of isset ?> <html> <body> <form name='noname' action='register3.php' method=post> <input type="submit" name='button' value='comfirm'> </form> </body> </html> the lastest code, i modify already, still the same..weird ??? Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329567 Share on other sites More sharing options...
bache Posted August 21, 2007 Share Posted August 21, 2007 what is the error now? Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329578 Share on other sites More sharing options...
zgkhoo Posted August 21, 2007 Author Share Posted August 21, 2007 still no update into Ownerid, ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329594 Share on other sites More sharing options...
itsmeArry Posted August 21, 2007 Share Posted August 21, 2007 try this out and remember to check the field, table names if they are correct mysql_query("UPDATE gamecard SET Ownerid = '".$_SESSION['ic']."' where Serialnum ='$cardID'"); Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329632 Share on other sites More sharing options...
zgkhoo Posted August 21, 2007 Author Share Posted August 21, 2007 i changed still the same..aihz. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329683 Share on other sites More sharing options...
MadTechie Posted August 21, 2007 Share Posted August 21, 2007 you don't have OwnerID field your using IC mysql_query("UPDATE gamecard SET IC= '".$_SESSION['ic']."WHERE Serialnum ='$cardID'"); Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329724 Share on other sites More sharing options...
itsmeArry Posted August 21, 2007 Share Posted August 21, 2007 try to echo the query... and see whether the query is correct or not.. try this and check out the result echo "UPDATE gamecard SET Ownerid = '".$_SESSION['ic']."' where Serialnum ='$cardID'"; Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329750 Share on other sites More sharing options...
zgkhoo Posted August 21, 2007 Author Share Posted August 21, 2007 echo query result SET Ownerid = 'testing888' where Serialnum ='5' Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329765 Share on other sites More sharing options...
bache Posted August 21, 2007 Share Posted August 21, 2007 Are you sure you have a row with Serialnum which is 5? Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329769 Share on other sites More sharing options...
zgkhoo Posted August 21, 2007 Author Share Posted August 21, 2007 Shot at 2007-08-21 or it cause by my Serialnum declare as varchar? there is no PK for my table. Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329771 Share on other sites More sharing options...
MadTechie Posted August 21, 2007 Share Posted August 21, 2007 Sighs mysql_query("UPDATE gamecard SET `Ownerid`= '{$_SESSION['ic']}' WHERE Serialnum =$cardID") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329774 Share on other sites More sharing options...
zgkhoo Posted August 21, 2007 Author Share Posted August 21, 2007 it work!!!!!!!! really super genius!! super guru!! thanks you very much ;D but why `Ownerid`= '{$_SESSION['ic']}' ??? Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329778 Share on other sites More sharing options...
MadTechie Posted August 21, 2007 Share Posted August 21, 2007 wasn't sure if ownerid was a reserved word the {} same the ".var." and the Serialnum is an int not a string so no quotes needed Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329785 Share on other sites More sharing options...
zgkhoo Posted August 21, 2007 Author Share Posted August 21, 2007 blurr ???, u meant "Ownerid" <--is a reserved word for mysql? the quote for php and mysql very mess $_SESSION['ic'] <---sometime i put $_SESSION[ic] also can work..weird... ??? Quote Link to comment https://forums.phpfreaks.com/topic/65814-solved-mysql-problem/#findComment-329788 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.