-
February 14th, 2008, 12:38 PM
#1
mysql query submitted without onclick
Hello,
I thought this bit of Ajax was working perfectly.
However, I just discovered that the mysql query in div ID "highslide-html-contactform1" gets executed without being clicked as long as the user is logged in (that is, if($my->id) is true).
Is there any way to limit execution to only the "onclick" event.
Many thanks,
Patty
PHP Code:
<?
$Request_Date=date("m-d-Y");
$contact="literature";
?>
Code:
<a href="#" style =" font-size:14px; color:#B5404D; text-decoration:underline;" onclick="return hs.htmlExpand(this, { contentId: 'highslide-html-contactform1' } )" title="Request Information"> RFI</a>
<div id='highslide-html-contactform1' class="highslide-html-content" style="width: 350px">
<div class="highslide-body">
PHP Code:
<?
global $my;
global $SERVER_NAME,$REQUEST, $_POST, $_GET,$SCRIPT_NAME,$QUERY_STRING;
$server = mysql_connect($dbhost, $dbusername, $dbpass)or die(mysql_error());
$server1 = mysql_connect($dbhost1, $dbusername1, $dbpass1);
$connection = mysql_select_db($dbname, $server)or die("Can't connect to database1.");
$connection1 = mysql_select_db($dbname1, $server1)or die("Can't connect to database2.");
if (isset($_GET[action])){
// Retrieve the GET parameters and executes the function
foreach($_GET as $key => $value)
{
$$key=$value;
}
} else if (isset($_POST[action])){
// Retrieve the POST parameters and executes the function
foreach($_POST as $key => $value)
{
$$key=$value;
}
}
$user=$my->id;
$contact="contact";
if($my->id) {
$query = "SELECT .etc.. WHERE jos_users.id = $user";
$res=mysql_query ($query) or die(mysql_error());
while($row=mysql_fetch_array($res)){
$name=$row["name"];
$userid=$row["user_id"];
$company=$row["company"];
$address=$row["address"];
$city=$row["city"];
$state=$row["state"];
$zipcode=$row["zipcode"];
$phone=$row["phone"];
$email=$row["email"];
}
$query1 = "insert into directory.requests (record, showid, userid,user_name,company,address, city, state, zip, phone, email, vendor_id, request,date) Values(NULL,'$showid','$userid', '$name','$company','$address', '$city','$state', '$zip', '$phone', '$email','$vendorid','$contact','$Request_Date') ";
$result=mysql_query($query1) or die(mysql_error());
$query2 = "select supplierName from vendor where supplierid = $vendorid";
$res2=mysql_query ($query2) or die(mysql_error());
while($row=mysql_fetch_array($res2)){
$vendornamename=$row["supplierName"];
}
echo "Thank You for your request " . $my->name ." (" . $my->username . ").<br>";
echo"<br>Your request for information has been submitted to $vendornamename";
}
else{
echo"You must first log in (or register) in order to request information <BR>Use your login on the right. No Account? <a href=\\">
Register Now.</a>";
}
?>
Code:
<div class="highslide-html-content-header">
<div class="highslide-move" title="<?php echo $cd_login_lang_move; ?>">
<a href="#" onclick="return hs.close(this)" class="control" title="close">close</a>
</div>
</div>
</div>
</div>
<p></p>
Last edited by pneb; February 14th, 2008 at 06:03 PM.
-
February 14th, 2008, 12:57 PM
#2
Re: mysql query submitted without onclick
There is not really enough information/code posted to fully grasp your problem. It sounds to me as though you have your PHP and HTML all in the same file. Well, naturally the server with execute the PHP first. So, I would suggest making two separate files. One should be the HTML file. Then other should be the PHP script called by the AJAX. Then the onclick event would be easy to call.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
February 14th, 2008, 01:09 PM
#3
Re: mysql query submitted without onclick
sorry for not being clear. This is all one file.
On clicking the RFI link, script creates a popup which either requests the use to login or (if logged in) submits the user rquest for information.
The problem is that if the user is already logged in, the user request is submitted without the link beling clicked
thank you for any help
-
February 14th, 2008, 02:04 PM
#4
Re: mysql query submitted without onclick
Which is why I suggested that you split them into two files. Or, you need to start using isset() with session variables to see if the user is already logged in.
PHP Code:
if (isset($_SESSION['user'])) {
// user must be logged in
// run script accordingly
}
else {
// user is not logged in
// make login happen
}
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
February 14th, 2008, 04:18 PM
#5
Re: mysql query submitted without onclick
thank you I will give that a try
-
February 14th, 2008, 06:02 PM
#6
Re: mysql query submitted without onclick
That worked perfectly--thank you so much
-
February 14th, 2008, 08:30 PM
#7
Re: mysql query submitted without onclick
Glad to hear it.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|