Miss-Ruth Posted December 15, 2010 Share Posted December 15, 2010 This looks perfect but for some reason it's not functioning. Could someone help fixing this. $resultF =sprintf("SELECT * FROM xy_db WHERE clubname ='%s'", mysql_real_escape_string($data3)); $resultFin = mysql_query($resultF); if (mysql_num_rows ($resultf) > 0){ $register = "Retry."; echo($register); } else { $go =sprintf("INSERT INTO ab_db (surnamez, firstnamez) VALUES ('%s', '%s'", mysql_real_escape_string($data1), mysql_real_escape_string($data2)); $result = mysql_query($go); Thank you. Ruth. \-) Quote Link to comment https://forums.phpfreaks.com/topic/221730-sprintf/ Share on other sites More sharing options...
scotmcc Posted December 15, 2010 Share Posted December 15, 2010 I have a few comments, but without setting up a database to test your code (which I am too tired to do at the moment), I am not sure if it solves your problem... your code with my comments: // I don't see any problem here.... and it seems to work fine. // it produces this: // SELECT * FROM xy_db WHERE clubname ='blah' (where blah is $data3) $resultF = sprintf("SELECT * FROM xy_db WHERE clubname ='%s'", mysql_real_escape_string($data3)); $resultFin = mysql_query($resultF); // Here I believe is a problem, you set "$resultFin" to the resource // data of the mysql query. However, when you go to look at the data, // you use the variable "$resultf" which is never defined in your code. // I assume this should be "$resultFin" if (mysql_num_rows ($resultf) > 0){ $register = "Retry."; echo($register); } else { $go =sprintf("INSERT INTO ab_db (surnamez, firstnamez) VALUES ('%s', '%s'", mysql_real_escape_string($data1), mysql_real_escape_string($data2)); $result = mysql_query($go); } Quote Link to comment https://forums.phpfreaks.com/topic/221730-sprintf/#findComment-1147560 Share on other sites More sharing options...
Miss-Ruth Posted December 15, 2010 Author Share Posted December 15, 2010 That did not solve the problem. I believe the syntax is correct <?php $link = mysql_connect("localhost","un","pw"); mysql_select_db("the_db"); $data1 = $_POST['data1']; $data2 = $_POST['data2']; $data3 = $_POST['data3']; $result =sprintf("SELECT * FROM my_db1 WHERE username ='%s'", mysql_real_escape_string($data1)); $resultf = mysql_query($result); if (mysql_num_rows ($resultf) > 0){ $register = "Retry."; echo($register); } else { $go =sprintf("INSERT INTO my_db1 (surname, firstname, username) VALUES ('%s', '%s', '%s'", mysql_real_escape_string($data1), mysql_real_escape_string($data2), mysql_real_escape_string($data3); $go1 =sprintf("INSERT INTO my_db2 (surname, firstname) VALUES ('%s', '%s'", mysql_real_escape_string($data1), mysql_real_escape_string($data2)); $resultg1 = mysql_query($go1); $go2 =sprintf("INSERT INTO my_db3 (surname, firstname) VALUES ('%s', '%s'", mysql_real_escape_string($data1), mysql_real_escape_string($data2)); $resultg2 = mysql_query($go2); $go3 =sprintf("INSERT INTO my_db4 (surname, firstname) VALUES ('%s', '%s'", mysql_real_escape_string($data1), mysql_real_escape_string($data2)); $resultg3 = mysql_query($go3); } ?> I appreciate any help. Thanks, Ruth. Quote Link to comment https://forums.phpfreaks.com/topic/221730-sprintf/#findComment-1147799 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.