Jump to content

sprintf();


Miss-Ruth

Recommended Posts

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. \-)

Link to comment
https://forums.phpfreaks.com/topic/221730-sprintf/
Share on other sites

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);
}

Link to comment
https://forums.phpfreaks.com/topic/221730-sprintf/#findComment-1147560
Share on other sites

That did not solve the problem. I believe the syntax is correct  :shrug:

 

<?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.

Link to comment
https://forums.phpfreaks.com/topic/221730-sprintf/#findComment-1147799
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.