PDA

View Full Version : how to incorporate 2 mysql tables on delete???


nanny
01-06-2007, 01:48 AM
Hi I am using Dreamweaver mx 2004 and php 4. I have been trying to delete two tables together.
I have the users registration table (regid) and their listings table (class_ad), when a user deletes their registration I am wanting them to delete their listings along with.
I have tried a few things but getting mysql errors.

if ((isset($_GET['regid'])) && ($_GET['regid'] != "")) {
$deleteSQL = sprintf("DELETE FROM regid, class_ad INNER JOIN class_ad ON regid.regid = class_ad.regid WHERE regid=%s",
GetSQLValueString($_GET['regid'], "int"));

How can I include the $_GET['classid'] from the class_ad table???
Thanks for taking reading.

davidj
01-06-2007, 12:01 PM
just write a normal delete without any joins on your first table

where regid ="$var"

run the script and make sure that delete is working and is removing that record

then copy that first delete script and paste it directly underneith the first (renameing the nessessary values to point to the second table)

NOTE: you have used DW code so the examples below are just a guide and wont work if you paste it
example...

/////////////////////////////////////////////////
$query = sprintf("DELETE FROM table1 where field1_id='$del'");
mysql_query($query)or die(mysql_error());
/////////////////////////////////////////////////

/////////////////////////////////////////////////
$query = sprintf("DELETE FROM table2 where field1_id2='$del2'");
mysql_query($query)or die(mysql_error());
/////////////////////////////////////////////////

nanny
03-25-2007, 03:38 AM
hi davidj
I am bringing this one back because I had it working, I changed my database and had to change pages and now it won't work.
This is the two tables I am trying to use:

if ((isset($_GET['regid'])) && ($_GET['regid'] != "")) {
$deleteSQL = sprintf("DELETE FROM regid WHERE regid=%s",
GetSQLValueString($_GET['regid'], "int"));

mysql_select_db($database_config, $config);
$Result1 = mysql_query($deleteSQL, $config) or die(mysql_error());


if ((isset($_GET['classid'])) && ($_GET['classid'] != "")) {
$deleteSQL = sprintf("DELETE FROM class_ad WHERE classid=%s",
GetSQLValueString($_GET['classid'], "int"));
mysql_select_db($database_config, $config);
$Result1 = mysql_query($deleteSQL, $config) or die(mysql_error());

Sorry for this but no matter which way I try to change it the php debugger says a parse error.

davidj
03-25-2007, 10:39 AM
try this...

$deleteSQL = sprintf("DELETE FROM regid WHERE regid='%s'"
notice the single quotes around the '%s'

if this doesnt work then try echo-ing the delete

echo $deleteSQL = sprintf("DELETE FROM regid WHERE regid='%s'"

then post what you get back from the page.

You are using dreamweaver to write your code!! this is your problem

nanny
03-30-2007, 08:31 AM
Hi davidj
what difference does the single quotes around the %S do?
I know I am using the Dreamweaver code because everytime I change it I get blank screens and errors and my css goes out of whack. When I use it and then play with the code it works well. Otherwise I see no point in using Dreamweaver at all.
The weird thing is I changed something from the code you gave me a while ago and it worked.
I am not sure how I can echo the delete sql. I am redirected from the page that has the delete link straight to the index page.
Thanks all the help is appreciated.

davidj
03-30-2007, 01:56 PM
%s is a data type place holder to discribe the datatype to expect and handle which; in this case, is a string

yo also have...


% - a literal percent character. No argument is required.
b - the argument is treated as an integer, and presented as a binary number.
c - the argument is treated as an integer, and presented as the character with that ASCII value.
d - the argument is treated as an integer, and presented as a (signed) decimal number.
e - the argument is treated as scientific notation (e.g. 1.2e+2). The precision specifier stands for the number of digits after the decimal point since PHP 5.2.1. In earlier versions, it was taken as number of significant digits (one less).
u - the argument is treated as an integer, and presented as an unsigned decimal number.
f - the argument is treated as a float, and presented as a floating-point number (locale aware).
F - the argument is treated as a float, and presented as a floating-point number (non-locale aware). Available since PHP 4.3.10 and PHP 5.0.3.
o - the argument is treated as an integer, and presented as an octal number.
s - the argument is treated as and presented as a string.
x - the argument is treated as an integer and presented as a hexadecimal number (with lowercase letters).
X - the argument is treated as an integer and presented as a hexadecimal number (with uppercase letters).



Otherwise I see no point in using Dreamweaver at all.


i love dreamweaver for producing x/d/HTML. Its a great time saver
If you want to develop PHP in a professional environment then leave the wizards alone coz your going out grow them very quickly.

the trouble is this... The user starts to get into PHP by ticking some boxes and selecting some dropdowns ... viola... the code appears as if by magic.

updates, deletes, inserts all dropping in magically... great...

now the user has an application but he requires a different function which dreamweaver doesnt support. This is the moment that the user has to start learning PHP or when he posts asking for someone to do it for him... Now to be honest i dont mind doing it but i do mind becoming a dreamweaver extension! if you know what i mean.

nanny
03-31-2007, 08:49 AM
hi davidj
yes I do know what you mean, but to ask those who have knowledge and experience is why we ask - to learn from. I am slowly learning php but I have had to teach myself design, css, photoshop, mysql, installing php and apache and learning php at once whilst working full-time and looking after children.
Having not even know how to send an email or search the internet previously to this, I am a slow learner.
But I admire those who can do this so quickly and understand the logic.
Some things I ask about, a while later I think - why couldn't I see that for myself. I guess it takes a while.
Thanks I will try a few options - although I have to get it working.

davidj
03-31-2007, 10:31 AM
nanny

this wasnt a poke. I just want you to understand just how easy it is to get into trouble with DW produced code. Far better take a week or two to learn how code by hand than to take 2 weeks scratching your head looking for an extension to do the task for you.

I enjoy helping others, i really do but i hate wasting my time fixing buggy code that the user has no interest in, just as long as it works!

I will give 110% of my time if the student takes time to understand what they are doing.

I like intellegent questions.


I am slowly learning php but I have had to teach myself design, css, photoshop, mysql, installing php and apache and learning php at once whilst working full-time and looking after children.



I commend you. i did this the same way but always enjoyed the learning process


Thanks I will try a few options - although I have to get it working.

you are at a level where you should not put yourself through stress.

nanny
04-01-2007, 09:16 AM
Hi thanks davidj
I know you weren't giving me a poke, I just thought I better let you know I am slow at learning.
I accomplished the delete by changing the above:
$deleteSQL = sprintf("DELETE regid,class_ad FROM regid INNER JOIN class_ad ON regid.regid=class_ad.regid WHERE regid.regid=%s",
GetSQLValueString($_GET['regid'], "int"));

It will take me a while to get to know the datatypes, nobody talks about them much.
While I have you though, if I have a form that I want to only produce within a session, is the right way to reproduce the form by using echo or print.
I gather the echo will give me all of the string and all the css on the page whereas the print will give me only the information I want to print without the css?
When I use
if (!isset($_SESSION['form'])) {
$_SESSION['form'] = 1;
}
else {
$_SESSION['form']++;
}
if ($_SESSION['form'] > 2) {
echo 'Sorry that was wrong please try again.'
}
else {
// display form
}

I get the echo on top of the page and not where I want it. I also get parse errors when I place the code where the form is.
I have heard of people using a function to say display form()
Is this a better option. If so I will try and play with it that way.

Thanks again.

davidj
04-01-2007, 11:17 AM
dont use php to display html

let html handle itself

example...


<?php
if(session['form'] == 1){ ?>

<form ...

html here. No PHP here

</form ...

<?php } ?>

nanny
04-03-2007, 01:58 AM
Thanks davidj
I will try this, but the counter is what I want in the conditional statement. I am only allowing this form to be shown up to two times only otherwise it disappears and they are given a link.
Cheers.....

davidj
04-03-2007, 09:57 AM
look at what i wrote

the condition will still work

nanny
04-04-2007, 07:32 AM
Hi davidj
I did the php before the form and the <?php } ?> after the form.
I notice this is after show if conditionals I have used with the extensions.
I guess it is like a do up until............?>
What has happened is that in the browser you can't see the form.
So how do I make it show for two times only then. When I try to apply any other coding it has parse errors.
Do I place the count above the doc type and html?

Thanks - learning bit by bit.

davidj
04-04-2007, 08:15 AM
post the code including the form and also explain what your wanting to do


Do I place the count above the doc type and html?


you need to start from the begining. Did you try the tutorials.

nanny
04-04-2007, 09:43 AM
Hi davidj
It is my signin page:

<h2>Please sign into your account below: <br />
<span> </span></h2><?php if($_SESSION['form'] == 1){ ?>
<form action="<?php echo $loginFormAction; ?>" method="post" name="passForm" class="right_articles" id="passForm">
<?php if (isset($_GET["badlogin"])) { ?>
<div align="center"><span class="errmsg1"><img src="../images/topicicon_ann_unread.gif" alt="error" width="25" height="25" /> You have entered a bad password <br />
or username. <br />
Please try again. </span> </div>
<p></p>
<?php } ?>
<br />
<p><span class="style2"><span>* asterisk means this section must be filled out</span> <br />
*</span>Email: <font face="Arial" size="2">
<input name="reg_username" type="text" size="20" maxlength="100" />
</font></p>
<p><span class="style2">*</span>Password: <font face="Arial" size="2">
<input name="reg_password" type="password" size="6" maxlength="6" />
<input name="savepass" type="checkbox" onclick="return savePass('salon','search',username.value,password. value,30)" value="true" checked="checked" />
<font face="Arial" size="1">Save Pass</font> </font></p>
<p>
<input name="submit" type="submit" style="padding:0;background-color:#000000;border: 1px solid #990000;color:#FFFFFF;width:55px;font-weight:bold" onclick="return savePass('salon','search',username.value,password. value,30)" value="Enter" />
</p>
<p><a href="password.php">Lost Password? </a>- <a href="reg.php">Need to Register?</a> </p>
</form><?php } ?>

I am wanting to show the form only twice and then give the link to lost password page.
I already have the error showing up when the id session is wrong.
Yes I have looked at the tutorials, they are great.

davidj
04-04-2007, 09:50 AM
ah right

you want a "3 strikes then your out" login system

ok

you need to give this function a memory so you need to store the count in db.. Are you doing this

nanny
04-04-2007, 10:21 AM
Thanks for the prompt reply davidj
Yes I want to give two strikes and then you can be sent to retreive your password.
I am not sure I follow you on how to store the count in the database, unless you mean by collecting the ip and not allowing that ip in etc.
The reason I didn't worry about the ip is that when I am blocking ip addresses from spam etc. I notice the same company has a hoard of domains.
I just thought a simpler and more effective way was to eliminate the times the form is shown and for the type of user that I will be having will not wait to enter again, they will give up, so that is why the link to retreive password is required. I have to think of security as well as convenience for my user.
They are people who don't get a chance to be on the net often so time is an issue.
Thanks

davidj
04-04-2007, 02:47 PM
I just thought a simpler and more effective way was to eliminate the times the form is shown and for the type of user that I will be having will not wait to enter again, they will give up, so that is why the link to retreive password is required


thats all well and good but if a user navigates away then back the site resumes as if they hadnt been there so the for will be available to key. This defeats having a security system in the first place

best thing would be to have a three field login

user, password, maiden name

if 2 fields are found in the db that is enough to get the users details so you would do a search on the user and password or user and maiden name and try and match 2. Once you have identifyed who they are you just want to confirm who they are by the third and last field. If this field is wrong then count++ and do an update in the attempt field with the Count value. This value will increment and overwrite the last value. You can use this value to display attempts made and also use this value to do...


if ($row['attempt'] < 3){

// show form here

}

nanny
04-05-2007, 08:36 AM
Hi davidj
Actually I do have on the register table a security question: their favourite food, though I hadn't used it on the login page as that was what I was going to use for the lost password page.
That is easily changed I can do that and change the select statement to include it. With the error validation would I then need to have $_POST['user'] && $_POST['secquestion'] etc.?
In the register page I also have a hidden variable for the restricted page access. The welcome page includes the various access levels and works fine.
It is the login page I want to make more secure but user friendly.
You see the users will only use this service between clients and they may only have a few minutes to do so. The computer at work will differ from the one at home, if they have one at home.
OK so to inplement the count and display the form, this is where I started from.
Is it an idea to incorporate a captcha? It works on sessions.
With the form would I do it as a function() or echo each line?

Thanks for your help.

nanny
04-09-2007, 09:46 AM
OK David - how do we match 2 and do all the above?
Cheers and happy easter