• cant find error in my php echo input code
    10 replies, posted
Where is the error in this? <?php if ($_POST['username']) $username=$_POST['username']; $password=$_POST['password']; $Code=$_POST['Code']; if ($password== NULLresult) { echo "A password was not supplied"; }else{ $query = mysql_query("SELECT 'username','password','Code' FROM profile or die(mysql_error()); $result = mysql_query($row) or die(mysql_error()); while($row = mysql_fetch_array( $result )) echo "$row['username']. " - ". $row['Code']"; } ?>
[QUOTE=Krzystylez;18145020]Where is the error in this? <?php if ($_POST['username']) $username=$_POST['username']; $password=$_POST['password']; $Code=$_POST['Code']; if ($password== NULLresult) { echo "A password was not supplied"; }else{ $query = mysql_query("SELECT 'username','password','Code' FROM profile or die(mysql_error()); $result = mysql_query($row) or die(mysql_error()); while($row = mysql_fetch_array( $result )) echo "$row['username']. " - ". $row['Code']"; } ?>[/QUOTE] [php]if ($password== NULLresult) {[/php] I don't think this line is correct. [php] $query = mysql_query("SELECT 'username','password','Code' FROM profile or die(mysql_error()); [/php] This query is wrong. You're missing an end quote.
[QUOTE=Senney;18145133][php]if ($password== NULLresult) {[/php] I don't think this line is correct. [php] $query = mysql_query("SELECT 'username','password','Code' FROM profile or die(mysql_error()); [/php] This query is wrong. You're missing an end quote.[/QUOTE] I cannot find the missing quote. Do you mind if you told me the location of it? [editline]07:43PM[/editline] <?php if ($_POST['username']) $username=$_POST['username']; $password=$_POST['password']; $Code=$_POST['Code']; if ($password== NULL (result)) { echo "A password was not supplied"; }else{ $query = mysql_query("SELECT 'username','password','Code' FROM profile or die(mysql_error()); $result = mysql_query($row) or die(mysql_error()); while($row = mysql_fetch_array( $result )) echo "$row['username']. " - ". $row['Code']"; } ?> is that better than the previous code? thats all i can see in the factor of errors.
[code]$query = mysql_query("SELECT 'username','password','Code' FROM profile") or die(mysql_error());[/code] Should work. Oh, you should also make a habit of indenting, it will make reading code A LOT more easier. I did it for you, this should work. [php]<?php if ($_POST['username']){ $username = $_POST['username']; $password = $_POST['password']; $Code = $_POST['Code']; if ($password== NULL (result)) { echo "A password was not supplied"; }else{ $query = mysql_query("SELECT 'username','password','Code' FROM profile or die(mysql_error()); $result = mysql_query($row) or die(mysql_error()); while($row = mysql_fetch_array( $result )){ echo "$row['username']. " - ". $row['Code']"; } } } ?> [/php] Ignore that. deadeye536 has a better solution. Always protect from SQL injections.
This is worth a try, I explained the errors I found in comments that you may remove if you wish. Also, read the comment about what [noparse][php][/noparse] tags do to the empty() function. [php]<?php if ($_POST['username']) { // Missing bracket $username=mysql_real_escape_string($_POST['username']); //Let's prevent some SQL injection now $password=mysql_real_escape_string($_POST['password']); //Read above line $Code=mysql_real_escape_string($_POST['Code']); //Read 2 lines above if (empty($password)) { // YES, I know in facepunch it appears as "emptyempty($password)", but it's really supposed to be "empty($password)" echo "A password was not supplied"; }else{ $query = mysql_query("SELECT username,password,Code FROM profile" or die(mysql_error()); //No quotes around columns in SELECT, or in the table name, missing end quote. //Uhhh... What? $row doesn't exist... you already performed the query...? while($row = mysql_fetch_array($query)) { // You need a bracket here, and chage result to query because of the removed line. echo $row['username']. " - ". $row['Code']; //Uhh... Remove the quote in the begining, and the end. } // and one here... } } // and one more here. ?>[/php] Yes, I do understand that you don't use any of those variables in the query, it's just safe to do that.
[QUOTE=bl4h;18145384][code]$query = mysql_query("SELECT 'username','password','Code' FROM profile") or die(mysql_error());[/code] Should work. Oh, you should also make a habit of indenting, it will make reading code A LOT more easier. I did it for you, this should work. [php]<?php if ($_POST['username']){ $username = $_POST['username']; $password = $_POST['password']; $Code = $_POST['Code']; if ($password== NULL (result)) { echo "A password was not supplied"; }else{ $query = mysql_query("SELECT 'username','password','Code' FROM profile or die(mysql_error()); $result = mysql_query($row) or die(mysql_error()); while($row = mysql_fetch_array( $result )){ echo "$row['username']. " - ". $row['Code']"; } } } ?> [/php] Ignore that. deadeye536 has a better solution. Always protect from SQL injections.[/QUOTE] Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/giacjrdi/public_html/rohan/user.php on line 26 still doesnt work [editline]08:26PM[/editline] <?php if ($_POST['username']) { $username=mysql_real_escape_string($_POST['username']); if (empty($password)) { echo "A password was not supplied"; }else{ $query = mysql_query("SELECT" 'username','password','Code' FROM "profile" or die(mysql_error()); while($row = mysql_fetch_array($query)) { echo $row['username']. " - ". $row['Code']; } } } ?> Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/giacjrdi/public_html/rohan/user.php on line 20 still doesnt work
Why are you asking for a username & password and then don't use it? Anyway, this should work (didn't test it): [php]<?php if(isset($_POST['username']) && !empty($_POST['username'])) { if(!isset($_POST['password']) || empty($_POST['password'])) { echo "A password was not supplied"; } else { $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $query = mysql_query("SELECT username, password, Code FROM profile") or die(mysql_error()); while($row = mysql_fetch_array($query)) { echo $row['username'] . " - " . $row['Code']; } } } ?>[/php] Don't forget: emptyempty() should be emtpy() Please indent your code, and use [noparse][php]<code>[/php][/noparse] tags to make the code you post readable.
[QUOTE=MD1337;18154005]Why are you asking for a username & password and then don't use it? Anyway, this should work (didn't test it): [php]<?php if(isset($_POST['username']) && !empty($_POST['username'])) { if(!isset($_POST['password']) || empty($_POST['password'])) { echo "A password was not supplied"; } else { $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $query = mysql_query("SELECT username, password, Code FROM profile") or die(mysql_error()); while($row = mysql_fetch_array($query)) { echo $row['username'] . " - " . $row['Code']; } } } ?>[/php] Don't forget: emptyempty() should be emtpy() Please indent your code, and use [noparse][php]<code>[/php][/noparse] tags to make the code you post readable.[/QUOTE] Ok thanks so much that works without any errors but it doesnt echo the code and username?
-woops, didn't read-
[QUOTE=bl4h;18162528]-woops, forgot to read-[/QUOTE] lolk I know it says: { echo $row['username'] . " - " . $row['Code']; } But still there is no echo..
Dude, serously nobody is going to take you serious if you don't even bother to 1. Put your goddamm code in [php] tags. 2. INDENT YOUR CODE 3. Go and learn some more php first, you obviously haven't put any work into this. You just keep asking on how do I do this and THEH IZ A ERROZ PLEASE FIX. Try it yourself, search your errorcode on google etc.
Sorry, you need to Log In to post a reply to this thread.