Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP & MYSQL Variable Checker 1

Status
Not open for further replies.

vexer007

IS-IT--Management
Aug 8, 2003
10
GB
Hi,

I've run into absolute brickwall and am really desprate for your help please. I have a MYSQL Database with two Tables called user_comment and the second user_table. When a user register with the site, their details are kept in the user_table. the second table user_comment is so that users who are registered on the user_table can leave comments which will be passed into the user_comment table. HERE IS THE CODE FOR THE SECOND PART, CHECKING IF A USER'S EMAIL EXIST IN the user_table IF SO, PUX THESE DATA INTO user_comment TABLE. PLEASE CAN ANYONE SPOT WHAT IS WRONG WITH THE CODE???
undefined

<?php require 'db.private'; ?>
<html>
<head>
<title> Gizmo&reg; Electronics - Login</title>

</head>
<body>


<table width="100%">
<tr><td>

<?php

$connection = mysql_connect($hostname,$username,$password);
mysql_select_db($databaseName, $connection);


$submit = $_POST['submit'];
$comment = $_POST['comment'];
$email = $_POST['email'];

if(isset($submit)) {

//if(isset($submit)) {
// check if user exists in the database
$query = mysql_query("SELECT email FROM user_table WHERE email = '".$email."'");
//$num_rows = mysql_num_rows($query_email);
//if(!$num_rows) die('Gizmerror!! Either you have typed your USERNAME and or Your PASSWORD incorrectly or you have not registered to access this pages. <p><font color="red" size="+1"><center> Please Try Again</center> </font></p>');

//mysql_query ( "INSERT INTO user_comment (email, comment) VALUES ('$email', '$comment');

$insert = "INSERT INTO user_comment SET
email = '$email',
comment = '$comment'";

//mysql_query($insert);
//$row_comment = mysql_fetch_Array($query);
die("<META http-equiv=\"Refresh\" content=\"0;url=commentdisplay.php\">");

//die("Thank you for registering. Your Registration was Successful! You can now login");



//$insert = "INSERT INTO user_comment SET
//comment = '$comment'";

//mysql_query($insert);

die("Thank you for registering. Your Registration was Successful! You can now login");

//}

//echo mysql_error();
//mysql_close();
}
?>

<center>


<form action="comment.php" method="post">
<table summary="comment page">

<tr>
<td><label for="comment">Your Comment:</label></td>
<td><textarea name="comment" cols="70" rows="5" wrap="VIRTUAL" id="comment" value="comment"></textarea><br /></td>
</tr>

<tr>
<td><label for="email">Email Address:</label></td>
<td><input type="text" id="email" name="email" value="type ur email here"></td>
</tr>

<tr>
<td><input type="submit" name="submit" /></td>
</tr>

</table>
</form>

<p><a href="home.htm">...or return to our Homepage</a></p>


</td>
</tr>
</table>
</body>
</html>

<b> ( PS THIS PAGE IS NAMED comment.php) </b>

THANK YOU, I REALLY APPRECIATE YOUR TIME AND EFFORT.
 
vexer007:

You posted this into the MySQL forum, too. Please don't cross-post.


After removing all the lines that were HTML pass through (more on that in a minute) and all the lines that were commented out, we are left with:

Code:
<?php require 'db.private'; ?>
<?php

	$connection = mysql_connect($hostname,$username,$password);
	mysql_select_db($databaseName, $connection); 
	
	
	$submit = $_POST['submit'];
	$comment = $_POST['comment'];
	$email = $_POST['email'];
	
	if(isset($submit))
	{
		$query = mysql_query("SELECT email FROM user_table WHERE email = '".$email."'");
		$insert = "INSERT INTO user_comment SET email = '$email', comment = '$comment'";
	  
		die("<META http-equiv=\"Refresh\" content=\"0;url=commentdisplay.php\">");
		die("Thank you for registering.  Your Registration was Successful! You can now login");
	}		
?>

I see no code in what's left which passes the insert query to the database server. If you don't do that, the query will never be run and the data will never be inserted into the table.


In more general comments on your code:
You are performing no error-checking on your database-access code. This can lead to squirrely performance from your scripts.

In this section of your original post:
Code:
<?php require 'db.private'; ?>
<html>
<head>
<title> Gizmo&reg; Electronics - Login</title>

</head>
<body>


<table width="100%">
    <tr><td>

<?php
, I see you switching back and forth between PHP-interpretation mode and HTML output mode. This slows down scripts. Use print or echo statements instead.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
sleipnir214,

I notcied in your last post you said:

I see you switching back and forth between PHP-interpretation mode and HTML output mode. This slows down scripts. Use print or echo statements instead.
 
Sorry, I accidentally hit the submit button. I was wondering if you could elaborate on making the script slower. Does this cause a larger server load?
 
Larger server load? That I cannot answer.

I can state that my own research has shown that a script which stays in PHP mode and uses print statements for all output runs faster than a script that switches back and forth between throughput and PHP modes for output. At least with PHP 4.3.6, although I expect my experience to hold with other versions of PHP.

Read thread434-843309 .




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
sleipnir214,

You state:
I can state that my own research has shown that a script which stays in PHP mode and uses print statements for all output runs faster than a script that switches back and forth between throughput and PHP modes for output. At least with PHP 4.3.6, although I expect my experience to hold with other versions of PHP.

But, states:
for outputting large blocks of text, dropping out of PHP parsing mode is generally more efficient than sending all of the text through echo() or print() or somesuch.
The above can be found just above the user contribution area on that page.

This is a contridiction.

Yes, I did read the thread you referenced.

I'm just showing the difference, so people don't take one way are another as gospel. As the auto makers like to say YMMV. (Your Mileage May Vary).

Ken
 
kenrbnsn:
Not a contradiction -- a special case. The operative word, I think, in the text you've quoted is large. Unfortunately, the manual doesn't define what large is as it's used in this context.

I can speak only for my own code, but most of its output tends to be output a couple of dozen bytes at a time. For example, it is not uncommon for my scripts to output an HTML table which consists of hard-coded HTML text strings interspersed with PHP variable values.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
As yet, I haven't been able to figure out what large means.

On my LAMP (RH9/2.0.50/4.1.7/5.02) box, it is significantly faster to output a 1,000,000-byte string using a print statement than it is to use context-switching.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top