mark103 Posted October 1, 2010 Share Posted October 1, 2010 Hi guys, I have a problem of prints of the data from table1. I am checking out the data of username and password in the url to go through in members table and then checking the username in table1 to get matching data and select rows with the fields id of teststrings1, teststrings2 and teststrings3, then print out the data. Here it is the code <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myusername'); define('DB_PASSWORD', 'password'); define('DB_DATABASE', 'mydatabasetable'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); if($username == '') { $errmsg_arr[] = 'username ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD ID missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if($result) { $qrytable1="SELECT teststrings1, teststrings2, teststrings3 FROM table1 WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); echo "<p id='teststrings1'>"; echo $row['teststrings1'] . "</p>"; echo "<p id='teststrings2'>"; echo $row['teststrings2'] . "</p>"; echo "<p id='teststrings3'>"; echo $row['teststrings3'] . "</p>"; } } ?> When I am am checking the data of username and password through in members table and then checking the username in table1 before select the rows with the fields id of teststrings1, teststrings2 and teststrings3 to prints out, but it have print out as blank on php page. Any idea? Quote Link to comment Share on other sites More sharing options...
schilly Posted October 1, 2010 Share Posted October 1, 2010 echo out $qry and $qrytable1 and make sure they look right. This if($result) { should probably be if(mysql_num_rows($result) > 0) { Quote Link to comment Share on other sites More sharing options...
mark103 Posted October 1, 2010 Author Share Posted October 1, 2010 bumpppp Quote Link to comment Share on other sites More sharing options...
mark103 Posted October 1, 2010 Author Share Posted October 1, 2010 echo out $qry and $qrytable1 and make sure they look right. This if($result) { should probably be if(mysql_num_rows($result) > 0) { Thank you very much for your help which it much appreicated. However, I need the last things before I will mark this thread as resolve. How can add the delete button on php page for each row so I can select the button and delete it?? Quote Link to comment Share on other sites More sharing options...
schilly Posted October 1, 2010 Share Posted October 1, 2010 add an input submit button in with the id of the row you want to delete as part of the button name (eg. name='submit-12'). Then when the form posts grab the id from the button name and delete the row. Quote Link to comment Share on other sites More sharing options...
mark103 Posted October 1, 2010 Author Share Posted October 1, 2010 add an input submit button in with the id of the row you want to delete as part of the button name (eg. name='submit-12'). Then when the form posts grab the id from the button name and delete the row. Well, there are automatically ids which it will be too much to work on and grab for each rows. If there is a one line code for the button to grab each ids then I would appreciate it if you could post it? Quote Link to comment Share on other sites More sharing options...
schilly Posted October 2, 2010 Share Posted October 2, 2010 what are you trying to delete? Quote Link to comment Share on other sites More sharing options...
mark103 Posted October 2, 2010 Author Share Posted October 2, 2010 what are you trying to delete? I am trying to delete to correct row that come with the same id. Here it is for example what it have print out on php page: </p><p id='data1'>this is the test 2</p></p><p id='data1'>this is the test 2</p> You can see that both data have got the same id, so I need to add the buttons for each data in php page and I want the button to come next to the data so I can delete the correct rows. Hope you can help! Quote Link to comment 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.