Jump to content

Recommended Posts

hi could someone tell me how to write out the value of a query to screen, as in to debug it

 

i get this line when trying to add a user

 

Unknown column 'Admin' in 'where clause'

 

my code

 

i figured somethings wrong with the sql so, theres somewhere to start, just dont know how to write it out

 

Cheers

 

<?php

include($_SERVER['DOCUMENT_ROOT'] . '/includes/connection.php');

  switch($_GET['mode']){
  
    case 'done':
      include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php');
      echo "Account has been created.";
      include($_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php');
      break;
  
    case 'add':
  $strUserName = mysql_real_escape_string($_POST["txtUserName"]);
      $strFirstName = mysql_real_escape_string($_POST["txtFirstName"]);
      $strlastName = mysql_real_escape_string($_POST["txtLastName"]);		
      $strTel = mysql_real_escape_string($_POST["txtTel"]);
      $strHomePage = mysql_real_escape_string($_POST["txtHomePage"]);		
      $strCompanyName = mysql_real_escape_string($_POST["txtCompanyName"]);
      $strUserPass = md5($_POST["txtUserPass"]);
      $strEmail = mysql_real_escape_string($_POST["txtEmail"]);
      $strDate = date("d/m/y");
  
      if(!strlen($strUserName)) {  $error = '<p style="color:#FF0000;">Error: Username Was Left Blank</p>';   }
  
  elseif(!strlen($strEmail)){  $error = '<p style="color:#FF0000;">Error: Email Was Left Blank</p>';  }
  
  else{	
  		if (mysql_query("SELECT UserName From tblUsers Where UserName=". $strUserName ." ")or die(mysql_error()) )  
	  	{  $error = '<p style="color:#FF0000;">Error: Username Taken</p>'; }
	   	else{ 
mysql_query("INSERT INTO tblUsers (UserName, UserPassword, UserEmail, UserCompanyName, UserFirstName, UserLastName, UserTel, UserHomePage, UserDateAdded, UserSuspend)
Values(  '".$strUserName."', '".$strUserPass."', '".$strEmail."', '".$strCompanyName."', '".$strFirstName."', '".$strLastName."', '".$strTel."', '".$strHomePage."', '".$strDate."', '1')") or die(mysql_error());

          header('Location: ?mode=done');
          exit; }
      	}
  
  break;
    default:
      include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php');
}
  
?>
<b>Register for an account</b>
<form id="Profile" method="post" action="?mode=add">
  <table width="100%" border="0" style="padding:0px; margin:0px;">
    <tr>
      <td>Username: </td>
      <td><input type="text" name="txtUserName" size="50" /></td>
    </tr>
    <tr>
      <td>Password:</td>
      <td><input type="password" name="txtUserPass" size="25" /></td>
    </tr>
    <tr>
      <td>Confirm Password:</td>
      <td><input type="password" name="txtUserPass2" size="25" /></td>
    </tr>
    <tr>
      <td>Email Address:</td>
      <td><input type="text" name="txtEmail" size="50" /></td>
    </tr>
    <tr>
      <td>Company Name</td>
      <td><input type="text" name="txtCompanyName"	size="50" /></td>
    </tr>
    <tr>
     <td>First Name:</td>
      <td><table width="100%" border="0" style="padding:0px; margin-left:-3px;">
        <tr>
          <td><input type="text" name="txtFirstName" size="20" /></td>
          <td> 
Last Name:</td>
          <td><input type="text" name="txtLastName" size="20" /></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td>Website Address</td>
      <td><input type="text" name="txtHomePage" size="50" /></td>
    </tr>
    <tr>
      <td>Tel: </td>
      <td><input type="text" name="txtTel" size="15" /></td>
    </tr>
    <tr>
      <td colspan="2" style="text-align:center;"><input type="submit" name="Submit" value="Submit Registration" alt="Enter" />
 
<input type="Reset" name="Reset" value="Cancel" alt="Cancel" /></td>
    </tr>
  </table>
  </form>
* a valid working email is required as your login and activation information will be sent there, thankyou.
<?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php'); ?>

Link to comment
https://forums.phpfreaks.com/topic/92280-echo-a-myql-query/
Share on other sites

sure just set the query into a variable then use the variable for the query, eg

 

 

instead of this:

mysql_query("SELECT UserName From tblUsers Where UserName=". $strUserName ." ")or die(mysql_error());

 

do this:

$query = "SELECT UserName From tblUsers Where UserName=". $strUserName;
mysql_query($query)or die(mysql_error());

 

---- btw make sure the correct Case in characters is supplied to mysql, eg "Admin" is not the same as "admin"

 

 

hope this helps,

Link to comment
https://forums.phpfreaks.com/topic/92280-echo-a-myql-query/#findComment-472765
Share on other sites

heres the code now

 

<?php

include($_SERVER['DOCUMENT_ROOT'] . '/includes/connection.php');

switch($_GET['mode']){

    case 'add':
  $strUserName = mysql_real_escape_string($_POST["txtUserName"]);
      $strFirstName = mysql_real_escape_string($_POST["txtFirstName"]);
      $strlastName = mysql_real_escape_string($_POST["txtLastName"]);		
      $strTel = mysql_real_escape_string($_POST["txtTel"]);
      $strHomePage = mysql_real_escape_string($_POST["txtHomePage"]);		
      $strCompanyName = mysql_real_escape_string($_POST["txtCompanyName"]);
      $strUserPass = md5($_POST["txtUserPass"]);
      $strEmail = mysql_real_escape_string($_POST["txtEmail"]);
      $strDate = date("d/m/y");
  
      if(!strlen($strUserName)) {  $error = '<p style="color:#FF0000;">Error: Username Was Left Blank</p>';   }
  
  elseif(!strlen($strEmail)){  $error = '<p style="color:#FF0000;">Error: Email Was Left Blank</p>';  }
  
  else{	
  		if (mysql_query("SELECT UserName From tblUsers Where UserName='". $strUserName ."' ")or die(mysql_error()) )  
	  	{  $error = '<p style="color:#FF0000;">Error: Username Taken</p>'; }
	   	else{ 
mysql_query("INSERT INTO tblUsers (UserName, UserPassword, UserEmail, UserCompanyName, UserFirstName, UserLastName, UserTel, UserHomePage, UserDateAdded)
Values(  '".$strUserName."', '".$strUserPass."', '".$strEmail."', '".$strCompanyName."', '".$strFirstName."', '".$strLastName."', '".$strTel."', '".$strHomePage."', '".$strDate."')") or die(mysql_error());

          header('Location: ?mode=done');
          exit; }
      	}
  
    case 'done':
      include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php');
      echo "Account has been created.";
      include($_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php');
      break;
  
  break;
    default:
      include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php');
}
  
?>
<b>Register for an account</b>
<form id="Profile" method="post" action="?mode=add">
  <table width="100%" border="0" style="padding:0px; margin:0px;">
    <tr>
      <td>Username: </td>
      <td><input type="text" name="txtUserName" size="50" /></td>
    </tr>
    <tr>
      <td>Password:</td>
      <td><input type="password" name="txtUserPass" size="25" /></td>
    </tr>
    <tr>
      <td>Confirm Password:</td>
      <td><input type="password" name="txtUserPass2" size="25" /></td>
    </tr>
    <tr>
      <td>Email Address:</td>
      <td><input type="text" name="txtEmail" size="50" /></td>
    </tr>
    <tr>
      <td>Company Name</td>
      <td><input type="text" name="txtCompanyName"	size="50" /></td>
    </tr>
    <tr>
     <td>First Name:</td>
      <td><table width="100%" border="0" style="padding:0px; margin-left:-3px;">
        <tr>
          <td><input type="text" name="txtFirstName" size="20" /></td>
          <td> 
Last Name:</td>
          <td><input type="text" name="txtLastName" size="20" /></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td>Website Address</td>
      <td><input type="text" name="txtHomePage" size="50" /></td>
    </tr>
    <tr>
      <td>Tel: </td>
      <td><input type="text" name="txtTel" size="15" /></td>
    </tr>
    <tr>
      <td colspan="2" style="text-align:center;"><input type="submit" name="Submit" value="Submit Registration" alt="Enter" />
 
<input type="Reset" name="Reset" value="Cancel" alt="Cancel" /></td>
    </tr>
  </table>
  </form>
* a valid working email is required as your login and activation information will be sent there, thankyou.
<?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php'); ?>

 

when i hit submit reg, i get accout craeted all good yes? no, checked my mysql db nothing there, it hasnt added a new user :(

 

how do i debug to get some error messages?

Link to comment
https://forums.phpfreaks.com/topic/92280-echo-a-myql-query/#findComment-472793
Share on other sites

i debugged the sql thats fine...

 

INSERT INTO tblUsers (UserName, UserPassword, UserEmail, UserCompanyName, UserFirstName, UserLastName, UserTel, UserHomePage, UserDateAdded) Values( 'Admin', '202cb962ac59075b964b07152d234b70', '', '', '', '', '', '', '21/02/08') 

 

i cant see whats wrong ???

Link to comment
https://forums.phpfreaks.com/topic/92280-echo-a-myql-query/#findComment-472839
Share on other sites

right nearly fixed it now, i figured it all out atleast :)

 

im having trouble trying to fatham out how to do this though

 

this line

 

	  		if (mysql_query("SELECT UserName FROM tblUsers WHERE UserName='". $strUserName ."' ")or die(mysql_error()) )  
	  	{ echo "<p style=\"color:#FF0000;\">Error: Username Taken</p>"; }

 

what this is doing is selecting the username where username = then just writing name taken anwayay,

 

i need it to check that the username already exsits not to select it

 

so if strUserName = a user name already in the table then write username taken, at the moment im gettgin that ar and just writing username taken..

 

soo how do i check for existance?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/92280-echo-a-myql-query/#findComment-472879
Share on other sites

im not quite sure what you mean but try this:

 

	  	$result = mysql_query("SELECT UserName FROM tblUsers WHERE UserName='". $strUserName ."' ") or die(mysql_error());
	  	if (mysql_num_rows($result)  > 0)
	  	{ echo "<p style=\"color:#FF0000;\">Error: Username Taken</p>"; }

 

 

hope this helps,

Link to comment
https://forums.phpfreaks.com/topic/92280-echo-a-myql-query/#findComment-472892
Share on other sites

Search the forums for my name as the author and checkunique as the text, and you'll find a function that does this for you.

 

right nearly fixed it now, i figured it all out atleast :)

 

im having trouble trying to fatham out how to do this though

 

this line

 

	  		if (mysql_query("SELECT UserName FROM tblUsers WHERE UserName='". $strUserName ."' ")or die(mysql_error()) )  
	  	{ echo "<p style=\"color:#FF0000;\">Error: Username Taken</p>"; }

 

what this is doing is selecting the username where username = then just writing name taken anwayay,

 

i need it to check that the username already exsits not to select it

 

so if strUserName = a user name already in the table then write username taken, at the moment im gettgin that ar and just writing username taken..

 

soo how do i check for existance?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/92280-echo-a-myql-query/#findComment-472918
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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