HDFilmMaker2112
Members-
Posts
547 -
Joined
-
Last visited
Never
Everything posted by HDFilmMaker2112
-
Issue solved. I missed the second = sign in the do=process if statement.
-
The following should be redirecting to a certain page based upon the variables given. If someone is logged into the admincp but enters the address index.php?admincp=users, all that shows up is a blank page, it should re-direct back to the admincp main page; aka index.php?admincp. Everything other than this is working... It's just not going back to the admincp when index.php?admincp=users is entered. <?php require_once 'db_select.php'; require_once 'func.php'; session_start(); $cadmin2=$_SESSION['admin_check']; if($cadmin2=="4" && isset($_SESSION['mypassword3']) && $_SESSION['mypassword3']==$_SESSION['mypassword2']){ $SQL1="SELECT position FROM $tbl_name4 WHERE film_number='1' ORDER BY ABS(cost) ASC"; $result1=mysql_query($SQL1) or die(mysql_error()); if($_GET['do']=="add"){ $section.=' - Add User'; $content.=' <div class="main"> <div class="main_header">Add New User</div> <div class="user_form"> <form action="./index.php?admincp=users&do=process&source=new" method="post"> <p><label>Name:</label> <input type="text" name="name" size="30" /></p> <p><label>E-Mail:</label> <input type="email" name="email" size="32" /></p> <p><label>Amount:</label> <input type="text" name="amount" size="8" /></p> <p><label>Username:</label> <input type="text" name="username" size="30" /></p> <p> <label>Level:</label> <select name="level"> <option value=""></option> <option value="nickel">Nickel</option> <option value="copper">Copper</option> <option value="bronze">Bronze</option> <option value="silver">Silver</option> <option value="gold">Gold</option> <option value="platinum">Platinum</option> <option value="palladium">Palladium</option> </select> </p> <p> <label>User Level:</label> <select name="user_level"> <option value="0">No Account</option> <option value="1">Credit Purchase</option> <option value="2">Donation</option> <option value="3">Moderator</option> <option value="4">Admin</option> </select> </p> <p><label>Credit:</label> <select name="credit"> <option value=""></option>'; while($row1=mysql_fetch_array($result1)){ extract($row1); $content.='<option value="'.ucfirst($position).'">'.ucfirst($position).'</option>'; } $content.=' </select> <!--<label>Film Number:</label> <select name="film_number"> <option value=""></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select>--> </p> <p><label>Password:</label> <input type="text" name="password" size="30" /></p> <p><input type="submit" value="Submit" name="Submit" /></p> </form> </div> </div> '; } elseif($_GET['do']=="edit"){ if(isset($_GET['id'])){ $id=(int)$_GET['id']; $edit_user_query="SELECT * FROM $tbl_name WHERE $tbl_name.donor_id=$id"; $edit_user_result=mysql_query($edit_user_query); while($edit_user_row=mysql_fetch_array($edit_user_result)){ extract($edit_user_row); } $credits_query="SELECT * FROM donors_credits WHERE donor_id=".$id." ORDER BY id"; $credits_result=mysql_query($credits_query); while($credits_row=mysql_fetch_array($credits_result)){ $credits[]=$credits_row['credit']; } if(count($credits) > 0){ $credit=implode(", ",$credits); } if(!empty($amount)){ $amount=number_format($amount, 2, '.', ','); } $section.=' - Edit User: '.$username.''; $content.=' <div class="main"> <div class="main_header">Edit User - '.(!empty($username) ? ''.$username.'' : ''.$name.'').'</div> <div class="user_form"> <form action="./index.php?admincp=users&do=process&source=edit&id='.$id.'" method="post"> <p><label>Name:</label> <input type="text" name="name" size="30" value="'.$name.'" /></p> <p><label>E-Mail:</label> <input type="email" name="email" size="32" value="'.$email.'" /></p> <p><label>Amount:</label> <input type="text" name="amount" size="8" value="'.$amount.'" /></p> <p><label>Username:</label> <input type="text" name="username" size="30" value="'.$username.'" /></p> <p> <label>Level:</label> <select name="level"> <option value=""'.(empty($level) ? ' selected="selected"' : '').'></option> <option value="nickel"'.($level=="nickel" ? ' selected="selected"' : '').'>Nickel</option> <option value="copper"'.($level=="copper" ? ' selected="selected"' : '').'>Copper</option> <option value="bronze"'.($level=="bronze" ? ' selected="selected"' : '').'>Bronze</option> <option value="silver"'.($level=="silver" ? ' selected="selected"' : '').'>Silver</option> <option value="gold"'.($level=="gold" ? ' selected="selected"' : '').'>Gold</option> <option value="platinum"'.($level=="platinum" ? ' selected="selected"' : '').'>Platinum</option> <option value="palladium"'.($level=="palladium" ? ' selected="selected"' : '').'>Palladium</option> </select> (Blank if something other than Donation) </p> <p> <label>User Level:</label> <select name="user_level"> <option value="0"'.($admin=="0" ? ' selected="selected"' : '').'>No Account</option> <option value="1"'.($admin=="1" ? ' selected="selected"' : '').'>Credit Purchase</option> <option value="2"'.($admin=="2" ? ' selected="selected"' : '').'>Donation</option> <option value="3"'.($admin=="3" ? ' selected="selected"' : '').'>Moderator</option> <option value="4"'.($admin=="4" ? ' selected="selected"' : '').'>Admin</option> </select> </p> <p><label>Credit:</label> <input type="text" name="credit_old" size="30" value="'.$credit.'" disabled="disabled" /></p> <p><label>New Credit:</label> <select name="credit"> <option value=""></option>'; while($row1=mysql_fetch_array($result1)){ extract($row1); $content.='<option value="'.ucfirst($position).'">'.ucfirst($position).'</option>'; } $content.=' </select> <!--<label>Film Number:</label> <select name="film_number"> <option value=""></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select>--> </p> <p><input type="submit" value="Submit" name="Submit" /></p> </form> </div> </div> '; } else{ $user_list_query="SELECT * FROM $tbl_name"; $user_list_result=mysql_query($user_list_query); $content=''; while($user_list_row=mysql_fetch_array($user_list_result)){ extract($user_list_row); $content.='<div class="center"><a href="./index.php?admincp=users&do=edit&id='.$donor_id.'">'.(!empty($username) ? ''.$username.'' : ''.$name.'').'</a></div>'; } } } elseif($_GET['do']="process"){ $source=sanitize($_GET['source']); $name=sanitize($_POST['name']); $email=sanitize($_POST['email']); $amount=amount_verify(sanitize($_POST['amount'])); $username=sanitize($_POST['username']); $level=sanitize($_POST['level']); $password=kam3($_POST['password']); $admin=sanitize($_POST['user_level']); //$film_number=sanitize($_POST['film_number']); $credits=sanitize($_POST['credit']); $credits=explode(",",$credits); array_walk($credits, 'trim_value'); if($amount=="00" || $amount==".00"){ $amount=""; } if($_GET['source']=="new"){ $add_user_query="INSERT INTO $tbl_name (username, name, level, amount, password, admin, email) VALUES ('$username', '$name', '$level', '$amount', '$password', '$admin', '$email')"; mysql_query($add_user_query); $insert_id=mysql_insert_id(); if(!empty($credits)){ $CreditArray = array(); foreach($credits as $credit){ $CreditArray[] = "('$credit',$insert_id)"; } if(mysql_affected_rows()==1){ $content.='<div class="center">User Added.</div>'; } if (count($CreditArray) > 0 ){ $credit_array_query="INSERT INTO $tbl_name2 (credit,donor_id) VALUES " . implode(',',$CreditArray); mysql_query($credit_array_query); } } } elseif($_GET['source']=="edit"){ $insert_id=$_GET['id']; $edit_user_query="UPDATE $tbl_name SET username='$username', name='$name', level='$level', amount='$amount', admin='$admin', email='$email' WHERE donor_id='$insert_id'"; mysql_query($edit_user_query); if(!empty($credits)){ $CreditArray = array(); foreach($credits as $credit){ $CreditArray[] = "('$credit',$insert_id)"; } if(mysql_affected_rows()==1){ $content.='<div class="center">User Edited.</div>'; } if (count($CreditArray) > 0 ){ $credit_array_query="INSERT $tbl_name2 (credit,donor_id) VALUES " . implode(',',$CreditArray); mysql_query($credit_array_query); } } } } else{ header('Location: ./index.php?admincp'); } } else{ header("Location: ./index.php?usercp"); } ?>
-
I would do that how? I barely use Javascript, so I have no idea how to do that.
-
? I didn't even include my second_credit.php page. That's here: <?php session_start(); $myusername=$_SESSION['myusername2']; $mypassword=$_SESSION['mypassword2']; require_once 'db_select.php'; $credit=$_GET['credit']; $credit=explode('-',$credit); $credit=$credit[0]; $id=$_GET['id']; $sql_films="SELECT $tbl_name4.position,$tbl_name4.film_number FROM $tbl_name4 LEFT JOIN $tbl_name2 ON $tbl_name4.item_id=$tbl_name2.item_id LEFT JOIN $tbl_name ON $tbl_name.donor_id=$tbl_name2.donor_id AND $tbl_name.donor_id='$id' WHERE $tbl_name4.position='$credit' AND $tbl_name2.item_id IS NULL"; $result_films=mysql_query($sql_films) or die(mysql_error()); $select.='<select name="new_credit">'."\n"; $select.='<option value="">Select Credit</option>'."\n"; while($row_films=mysql_fetch_array($result_films)){ extract($row_films); $select.='<option value="'.$position.'-'.$film_number.'" >'.ucwords($position).' - Film # '.$film_number.'</option>'."\n"; } $select.='</select> '; echo $select; ?> The page I posted in my first post is credit.php which contains the HTML where the AJAX is supposed to print out. I didn't include second_credit.php because I didn't think it was really relative to the situation. As you can see here: http://www.makethemoviehappen.com/second_credit.php?credit=gaffer&id=2 second_credit.php works fine.
-
In index.php... index.php is essentially the layout and everything else is generated separately and then included.
-
For some reason the AJAX output on this page is not working. <script type="text/javascript"> function requestObj() { var reqObj; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ reqObj = new ActiveXObject("Microsoft.XMLHTTP"); }else{ reqObj = new XMLHttpRequest(); } return reqObj; } var http = requestObj(); function sndReq(action,id) { http.open('get', 'second_credit.php?credit='+action+'&id='+id, true); http.onreadystatechange = handleResponse; http.send(null); } function handleResponse() { if(http.readyState == 4){ var response = http.responseText; document.getElementById("ajaxout").innerHTML = response; } } </script> $content.=' <form action="" method="post"> <p><label>Name Credit is Listed Under:</label> <input type="text" name="name" size="30" /></p> <p><label>E-Mail of Original Purchase:</label> <input type="text" name="email" size="32" /></p> <p><label>Original Credit Purchased:</label>'; $sql_credit="SELECT $tbl_name2.credit,$tbl_name.donor_id,$tbl_name2.film_number FROM $tbl_name JOIN $tbl_name2 USING (donor_id) WHERE $tbl_name.username='$myusername' AND $tbl_name.password='$mypassword'"; $result_credit=mysql_query($sql_credit) or die(mysql_error()); $menu_generate=""; while($credit_rows=mysql_fetch_array($result_credit)){ extract($credit_rows); $menu_generate.='<option value="'.$credit.'-'.$film_number.'" >'.ucwords($credit).' - Film # '.$film_number.'</option>'."\n"; } $id=$_GET['donor_id']; $content.="<select name=\"credit\" onchange=\"sndReq(this.value,$id);\">"; $content.='<option value="">Select Credit</option>'."\n"; $content.=$menu_generate; $content.="</select>"; $content.='<p><label>Second Credit to Purchase:</label> <span id="ajaxout"></span></p>'; $content.='<p><input type="submit" value="Submit" name="Submit" /></p> </form> '; When I check the page called by ajax (second_credit.php), it loads properly. So the issue with the ajax call or the display.
-
Query to get item not assigned to a user
HDFilmMaker2112 replied to HDFilmMaker2112's topic in MySQL Help
Updated Query/PHP: I know this isn't the php forum, but I'm including my php so I can show what the query results will be used for. $tbl_name has donor_id and username $tbl_name2 has item_id and donor_id $tbl_name4 has item_id and the item details <?php session_start(); $myusername=$_SESSION['myusername2']; $mypassword=$_SESSION['mypassword2']; require_once 'db_select.php'; $credit=$_GET['credit']; $credit=explode('-',$credit); $credit2=$credit[0]; $id=$_GET['id']; $sql_films=" SELECT $tbl_name4.position,$tbl_name4.film_number FROM $tbl_name4 LEFT JOIN $tbl_name2 ON $tbl_name4.item_id=$tbl_name2.item_id LEFT JOIN $tbl_name ON $tbl_name.donor_id=$tbl_name2.donor_id AND $tbl_name.donor_id='$id' WHERE $tbl_name4.item_id IS NULL"; $result_films=mysql_query($sql_films) or die(mysql_error()); $select.='<select name="new_credit">'."\n"; $select.='<option value="">Select Credit</option>'."\n"; while($row_films=mysql_fetch_array($result_films)){ extract($row_films); $select.='<option value="'.$position.'-'.$film_number.'" >'.ucwords($position).' - Film # '.$film_number.'</option>'."\n"; } $select.='</select> '; echo $select; ?> -
I'm trying to write a query to get an item not assigned to user. Would this be anywhere near close: SELECT $tbl_name4.item_id FROM $tbl_name4 JOIN $tbl_name2 ON ($tbl_name2.credit=$tbl_name4.position AND $tbl_name2.film_number=$tbl_name4.film_number) WHERE $tbl_name4.item_id IS NULL; My table structure is as such: $tbl_name4="credits_listing"; id | cost | position | item_id | quantity | film_number $tbl_name2="donors_credits"; id | credit | film_number | donor_id The only issue I can see with the query I have above is how to I select the specific user to choose the data from? I do have donor_id value available from a previous query. Should I add this value as a second WHERE condition?
-
Any ideas? Basically I need some way to get the credits that haven't already been bought. That could be up two credits. If they already bought film 1, then options for 2 and 3 should be there. If they already bought 1 and 2 then an option for only 3 should be there.
-
Most recent: <?php session_start(); $myusername=$_SESSION['myusername2']; $mypassword=$_SESSION['mypassword2']; require_once 'db_select.php'; $credit=$_GET['credit']; $credit=explode('-',$credit); $credit2=$credit[0]; $sql_films="SELECT $tbl_name2.credit,$tbl_name.donor_id,$tbl_name2.film_number,$tbl_name4.item_id FROM $tbl_name JOIN $tbl_name2 JOIN $tbl_name4 ON ($tbl_name2.donor_id=$tbl_name.donor_id AND $tbl_name2.credit=$tbl_name4.position AND $tbl_name2.film_number=$tbl_name4.film_number) WHERE $tbl_name.username='$myusername' AND $tbl_name.password='$mypassword'"; $result_films=mysql_query($sql_films) or die(mysql_error()); while($films_row=mysql_fetch_array($result_films)){ extract($films_row); if($film_number==1 && $film_number==3){ $where="film_number='2'"; } elseif($film_number==1 && $film_number==2){ $where="film_number='3'"; } elseif($film_number==3 && $film_number==2){ $where="film_number='1'"; } elseif($film_number==1){ $where="film_number='2' AND film_number='3'"; } elseif($film_number==2){ $where="film_number='1' AND film_number='3'"; } elseif($film_number==3){ $where="film_number='1' AND film_number='2'"; } } $sql_find_other_credits="SELECT $tbl_name4.*,$tbl_name2.* FROM $tbl_name4 JOIN $tbl_name2 ON($tbl_name4.position=$tbl_name2.credit) WHERE $where AND credit='$credit2'"; $result_find_other_credits=mysql_query($sql_find_other_credits); $where2=""; while($other_credits_row=mysql_fetch_array($result_find_other_credits)){ extract($other_credits_row); $where2.="item_id='$item_id'"; } $sql_second_credit="SELECT * FROM $tbl_name4 WHERE $where2"; $result_second_credit=mysql_query($sql_second_credit) or die(mysql_error()); $select.='<select name="new_credit">'."\n"; $select.='<option value="">Select Credit</option>'."\n"; while($second_row_credits=mysql_fetch_array($result_second_credit)){ extract($second_row_credits); $select.='<option value="'.ucfirst($item_id).'">'.ucfirst($position).' - Film # '.$film_number.'</option>'."\n"; } $select.='</select> '; echo $select; ?> Still having same issues.
-
Here's my most recent updated code: <?php session_start(); $myusername=$_SESSION['myusername2']; $mypassword=$_SESSION['mypassword2']; require_once 'db_select.php'; $credit=$_GET['credit']; $credit=explode('-',$credit); $credit=$credit[0]; $sql_films="SELECT $tbl_name2.credit,$tbl_name.donor_id,$tbl_name2.film_number,$tbl_name4.item_id FROM $tbl_name JOIN $tbl_name2 JOIN $tbl_name4 ON ($tbl_name2.donor_id=$tbl_name.donor_id AND $tbl_name2.credit=$tbl_name4.position AND $tbl_name2.film_number=$tbl_name4.film_number) WHERE $tbl_name.username='$myusername' AND $tbl_name.password='$mypassword'"; $result_films=mysql_query($sql_films) or die(mysql_error()); while($films_row=mysql_fetch_array($result_films)){ extract($films_row); if($film_number==1 && $film_number==3){ $where="item_id='Seq$credit'"; } elseif($film_number==1 && $film_number==2){ $where="item_id='Tril$credit'"; } elseif($film_number==3 && $film_number==2){ $where="item_id='$credit'"; } elseif($film_number==1){ $where="item_id='Seq$credit' OR item_id='Tril$credit'"; } elseif($film_number==2){ $where="item_id='$credit' OR item_id='Tril$credit'"; } elseif($film_number==3){ $where="item_id='$credit' OR item_id='Seq$credit'"; } } $sql_second_credit="SELECT * FROM $tbl_name4 WHERE $where"; $result_second_credit=mysql_query($sql_second_credit) or die(mysql_error()); $select.='<select name="new_credit">'."\n"; $select.='<option value="">Select Credit</option>'."\n"; while($second_row_credits=mysql_fetch_array($result_second_credit)){ extract($second_row_credits); $select.='<option value="'.ucfirst($item_id).'">'.ucfirst($position).' - Film # '.$film_number.'</option>'."\n"; } $select.='</select> '; echo $select; ?> Still no luck in removing duplicates from the query. I have Credit A for Films 1 and 2 in the database and it's populating the Select menu with Credit A for Films 1 and 3, when it should only be for film 3.
-
I just decided second query. $sql_films="SELECT $tbl_name2.credit,$tbl_name.donor_id,$tbl_name2.film_number, $tbl_name4.item_id FROM $tbl_name JOIN $tbl_name2 JOIN $tbl_name4 ON ($tbl_name2.donor_id=$tbl_name.donor_id AND $tbl_name2.credit=$tbl_name4.position AND $tbl_name2.film_number=$tbl_name4.film_number) WHERE $tbl_name.username='$myusername' AND $tbl_name.password='$mypassword'"; $result_films=mysql_query($sql_films) or die(mysql_error()); while($films_row=mysql_fetch_array($result_films)){ extract($films_row); } That's working... now my question is I can get the film numbers, what do I do with them to process them to be used in this query: $sql_second_credit="SELECT * FROM $tbl_name4 WHERE item_id='Seq$credit' OR item_id='Tril$credit'"; Should I just do a bunch of if/else statements? Would seem like it could be done more efficiently, because I'd need about 6 different ones. 1,2,3, 1 and 2, 1 and 3, 2 and 3,
-
The below is code that is called from an AJAX function. It get's the additional credits available for purchase based on the credits already bought. Basically if you already bought Credit A for Film 1, it would list Credit A for films 2 and 3. Now I've run into problem... what would I do if they already bought Credit A for Films 1 and 2. How do I make it so it's only showing the third one as an additional purchase option? My table is currently set-up as follows: donors_credits id|credit|film_number|donor_id credits_listing (contains all the credits available for purchase) id | cost | position | item_id | quantity | film_number Should I add another query to donors_credit to find what films the person already bought or could I some how use the existing code below to pull that data without query the DB again? <?php require_once 'db_select.php'; $credit=$_GET['credit']; $credit=explode('-',$credit); $credit=$credit[0]; $film_number=$credit[1]; if($film_number==1){ } elseif($film_number==2){ } elseif($film_number==3){ } $sql_second_credit="SELECT * FROM $tbl_name4 WHERE item_id='Seq$credit' OR item_id='Tril$credit'"; $result_second_credit=mysql_query($sql_second_credit) or die(mysql_error()); $select.='<select name="new_credit">'."\n"; $select.='<option value="">Select Credit</option>'."\n"; while($second_row_credits=mysql_fetch_array($result_second_credit)){ extract($second_row_credits); $select.='<option value="'.ucfirst($item_id).'">'.ucfirst($position).' - Film # '.$film_number.'</option>'."\n"; } $select.='</select> '; echo $select; ?> This is the page where the AJAX call (calls the code above) is displayed: <?php session_start(); $myusername=$_SESSION['myusername2']; $mypassword=$_SESSION['mypassword2']; require_once 'db_select.php'; $content=' <div class="main"> <div class="main_header">Purchase Additional Credit</div>'; if($_GET['e']==t){ $content.='<p class="green clear"> Request Sent. You should be contact with a discounted crew credit button specifically for you, in the next two business days. </p> '; } else{ $content.=' <p> If you wish to purchase an additional credit, use the form below to select the credit you wish to buy, the name in which the original credit is listed under (as listed on the donors page), and the e-mail address in which the original purchase came from. This is a great to get your name back on the top 100 donors list. Once you submit this form, we will review the submitted material, create a new paypal purchase button specifically for you, and send you the link to that button. From there, you will be able to purchase the additional credit.'; if($_GET['e']==f){ $content.='<p class="red"> The email address you entered doesn\'t match the email in the database for this account. Please try again. <br /> If you keep having problems, please contact us at <a href="mailto:general@makethemoviehappen.com"> general@makethemoviehappen.com</a>. </p>'; } $content.=' <form action="" method="post"> <p><label>Name Credit is Listed Under:</label> <input type="text" name="name" size="30" /></p> <p><label>E-Mail of Original Purchase:</label> <input type="text" name="email" size="32" /></p> <p><label>Original Credit Purchased:</label>'; $sql_credit="SELECT $tbl_name2.credit,$tbl_name.donor_id,$tbl_name2.film_number FROM $tbl_name JOIN $tbl_name2 USING (donor_id) WHERE $tbl_name.username='$myusername' AND $tbl_name.password='$mypassword'"; $result_credit=mysql_query($sql_credit) or die(mysql_error()); $menu_generate=""; while($credit_rows=mysql_fetch_array($result_credit)){ extract($credit_rows); $menu_generate.='<option value="'.$credit.'-'.$film_number.'" >'.ucwords($credit).' - Film # '.$film_number.'</option>'."\n" ; } $content.="<select name=\"credit\" onchange=\"sndReq(this.value);\">"; $content.='<option value="">Select Credit</option>'."\n"; $content.=$menu_generate; $content.="</select>"; $content.='<p><label>Second Credit to Purchase:</label> <span id="ajaxout"></span></p>'; $content.='<p><input type="submit" value="Submit" name="Submit" /></p> </form> '; } $content.=" </div> <br />"; ?>
-
found the solution. this.value in sndReq();
-
Now, my issue is that I need to place the onchange option into each <option> tag. This doesn't seem possible. When I place the onchange="sndReq('$credit')" into the <select> tag it generates only the first $credit choice into sndReq. How can I make it change based on the selection?
-
It was because the $credit variable was declared after I was using it. Fix: $content.=' <form action="" method="post"> <p><label>Name Credit is Listed Under:</label> <input type="text" name="name" size="30" /></p> <p><label>E-Mail of Original Purchase:</label> <input type="text" name="email" size="32" /></p> <p><label>Original Credit Purchased:</label>'; $sql_credit="SELECT $tbl_name2.credit,$tbl_name.donor_id,$tbl_name2.film_number FROM $tbl_name JOIN $tbl_name2 USING (donor_id) WHERE $tbl_name.username='$myusername' AND $tbl_name.password='$mypassword'"; $result_credit=mysql_query($sql_credit) or die(mysql_error()); $menu_generate=""; while($credit_rows=mysql_fetch_array($result_credit)) { extract($credit_rows); $menu_generate.='<option value="'.$credit.'-'.$film_number.'" >'.ucwords($credit).' - Film # '.$film_number.'</option>'."\n" ; } $content.="<select name=\"credit\" onchange=\"sndReq('$credit');\">"; $content.='<option value="">Select Credit</option>'."\n"; $content.=$menu_generate; $content.="</select>"; $content.='<p><label>Second Credit to Purchase:</label> <span id="ajaxout"></span></p>'; $content.='<p><input type="submit" value="Submit" name="Submit" /></p> </form> '; }
-
When I access second_credit.php by itself with a variable in the URL it generates a select menu properly. When I try to do it with an AJAX call, it doesn't work. ajax in index.php head tag <script type="text/javascript"> function requestObj() { var reqObj; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ reqObj = new ActiveXObject("Microsoft.XMLHTTP"); }else{ reqObj = new XMLHttpRequest(); } return reqObj; } var http = requestObj(); function sndReq(action) { http.open('get', 'second_credit.php?credit='+action, true); http.onreadystatechange = handleResponse; http.send(null); } function handleResponse() { if(http.readyState == 4){ var response = http.responseText; document.getElementById("ajaxout").innerHTML = response; } } </script> second_credit.php <?php require_once 'db_select.php'; $credit=$_GET['credit']; $sql_second_credit="SELECT * FROM $tbl_name4 WHERE item_id='Seq$credit' OR item_id='Tril$credit'"; $result_second_credit=mysql_query($sql_second_credit) or die(mysql_error()); $content.='<select name="new_credit">'; $content.='<option value="">Select Credit</option>'; while($second_row_credits=mysql_fetch_array($result_second_credit)){ extract($second_row_credits); $content.='<option value="'.ucfirst($item_id).'">'.ucfirst($position).' - Film # '.$film_number.'</option>'."\n"; } $content.='</select> '; ?> credit.php <?php session_start(); $myusername=$_SESSION['myusername2']; $mypassword=$_SESSION['mypassword2']; require_once 'db_select.php'; $content=' <div class="main"> <div class="main_header">Purchase Additional Credit</div>'; if($_GET['e']==t){ $content.='<p class="green clear"> Request Sent. You should be contact with a discounted crew credit button specifically for you, in the next two business days. </p> '; } else{ $content.=' <p> If you wish to purchase an additional credit, use the form below to select the credit you wish to buy, the name in which the original credit is listed under (as listed on the donors page), and the e-mail address in which the original purchase came from. This is a great to get your name back on the top 100 donors list. Once you submit this form, we will review the submitted material, create a new paypal purchase button specifically for you, and send you the link to that button. From there, you will be able to purchase the additional credit.'; if($_GET['e']==f){ $content.='<p class="red"> The email address you entered doesn\'t match the email in the database for this account. Please try again. <br /> If you keep having problems, please contact us at <a href="mailto:general@makethemoviehappen.com"> general@makethemoviehappen.com</a>. </p>'; } $content.=' <form action="" method="post"> <p><label>Name Credit is Listed Under:</label> <input type="text" name="name" size="30" /></p> <p><label>E-Mail of Original Purchase:</label> <input type="text" name="email" size="32" /></p> <p><label>Original Credit Purchased:</label>'; $sql_credit="SELECT $tbl_name2.credit,$tbl_name.donor_id,$tbl_name2.film_number FROM $tbl_name JOIN $tbl_name2 USING (donor_id) WHERE $tbl_name.username='$myusername' AND $tbl_name.password='$mypassword'"; $result_credit=mysql_query($sql_credit) or die(mysql_error()); $content.="<select name=\"credit\" onchange=\"sndReq('$credit');\">"; $content.='<option value="">Select Credit</option>'."\n"; while($credit_rows=mysql_fetch_array($result_credit)) { extract($credit_rows); $content.='<option value="'.$credit.'-'.$film_number.'" >'.ucwords($credit).' - Film # '.$film_number.'</option>'."\n" ; } $content.='<p><label>Second Credit to Purchase:</label> <div id="ajaxout"></div></p>'; $content.='<p><input type="submit" value="Submit" name="Submit" /></p> </form> '; } $content.=" </div> <br />"; ?> EDIT: I've traced the issue to sndReq not have value set in it, but it doesn't make sense why it's not working. Checking the source code once the page is generate (after PHP parsing) it has sndReq('');
-
Any ideas? Updated Code: <script language="javascript"> function Inint_AJAX() { try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript alert("XMLHttpRequest not supported"); return null; }; function dochange(src, val) { var req = Inint_AJAX(); req.onreadystatechange = function () { if (req.readyState==4) { if (req.status==200) { document.getElementById(src).innerHTML=req.responseText; } } }; req.open("GET", "second_credit.php?data="+src+"&val="+val); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header req.send(null); } window.onLoad=dochange('new_credit', -1); function ViewCrossReference (selSelectObject) { if (selSelectObject.options[selSelectObject.selectedIndex].value != "") { location.href=selSelectObject.options[selSelectObject.selectedIndex].value } } </script> <?php session_start(); $myusername=$_SESSION['myusername2']; $mypassword=$_SESSION['mypassword2']; require_once 'db_select.php'; require_once 'func.php'; $sql_credit="SELECT $tbl_name2.credit,$tbl_name.donor_id,$tbl_name2.film_number FROM $tbl_name JOIN $tbl_name2 USING (donor_id) WHERE $tbl_name.username='$myusername' AND $tbl_name.password='$mypassword'"; $result_credit=mysql_query($sql_credit) or die(mysql_error()); $content=' <div class="main"> <div class="main_header">Purchase Additional Credit</div>'; if($_GET['e']==t){ $content.='<p class="green clear"> Request Sent. You should be contact with a discounted crew credit button specifically for you, in the next two business days. </p> '; } else{ $content.=' <p> If you wish to purchase an additional credit, use the form below to select the credit you wish to buy, the name in which the original credit is listed under (as listed on the donors page), and the e-mail address in which the original purchase came from. This is a great to get your name back on the top 100 donors list. Once you submit this form, we will review the submitted material, create a new paypal purchase button specifically for you, and send you the link to that button. From there, you will be able to purchase the additional credit.'; if($_GET['e']==f){ $content.='<p class="red"> The email address you entered doesn\'t match the email in the database for this account. Please try again. <br /> If you keep having problems, please contact us at <a href="mailto:general@makethemoviehappen.com"> general@makethemoviehappen.com</a>. </p>'; } $content.=' <form action="" method="post"> <p><label>Name Credit is Listed Under:</label> <input type="text" name="name" size="30" /></p> <p><label>E-Mail of Original Purchase:</label> <input type="text" name="email" size="32" /></p> <p><label>Original Credit Purchased:</label>'; $content.='<select name="credit" onChange="dochange(\'new_credit\', this.value)">'."\n". '<option value="">Select Credit</option>'."\n"; while($credit_row=mysql_fetch_array($result_credit)){ extract($credit_row); $content.='<option value="'.ucwords($credit).'-'.$film_number.'" >'.ucwords($credit).' - Film # '.$film_number.'</option>'."\n" ; } $content.='<p><label>Second Credit to Purchase:</label> <span id="new_credit"><select name="new_credit" onChange="ViewCrossReference(this)"> <option value="">Select Credit</option>'."\n". '</select></span></p>'."\n".' </p> <p><input type="submit" value="Submit" name="Submit" /></p> </form> '; } $content.=" </div> <br />"; ?> <?php require_once 'db_select.php'; $myusername=$_SESSION['myusername2']; $mypassword=$_SESSION['mypassword2']; $data=$_GET['data']; $credit=$_GET['val']; if ($data=='credit') { $sql_credit="SELECT $tbl_name2.credit,$tbl_name.donor_id,$tbl_name2.film_number FROM $tbl_name JOIN $tbl_name2 USING (donor_id) WHERE $tbl_name.username='$myusername' AND $tbl_name.password='$mypassword'"; $result_credit=mysql_query($sql_credit) or die(mysql_error()); echo '<select name="credit" onChange="dochange(\'new_credit\', this.value)">'."\n"; echo '<option value="">Select Credit</option>'."\n"; while($credit_row=mysql_fetch_array($result_credit)){ extract($credit_row); echo '<option value="'.$credit.'-'.$film_number.'" >'.$credit.' - Film # '.$film_number.'</option>'."\n" ; } } elseif($data=='new_credit') { echo '<select name="new_credit">'."\n"; echo '<option value="">Select Credit</option>'."\n"; $sql_second_credit="SELECT * FROM $tbl_name4 WHERE item_id='Seq$credit' OR item_id='Tril$credit'"; $result_second_credit=mysql_query($sql_second_credit) or die(mysql_error()); while($second_row_credits=mysql_fetch_array($result_second_credit)){ extract($second_row_credits); echo '<option value="'.ucfirst($item_id).'">'.ucfirst($position).' - Film # '.$film_number.'</option>'."\n"; } } echo "</select>\n"; ?> This results in this:
-
Here's updated code. Still can't get the second menu to update: <?php //set IE read from page only not read from cache header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header ("Cache-Control: no-cache, must-revalidate"); header ("Pragma: no-cache"); header("content-type: application/x-javascript; charset=tis-620"); require_once 'db_select.php'; $credit=$_GET['credit']; $sql_second_credit="SELECT * FROM $tbl_name4 WHERE item_id='Seq$credit' OR item_id='Tril$credit'"; $result_second_credit=mysql_query($sql_second_credit) or die(mysql_error()); echo '<select name="new_credit">'; echo '<option value="">Select Credit</option>'; while($second_row_credits=mysql_fetch_array($result_second_credit)){ extract($second_row_credits); echo '<option value="'.ucfirst($item_id).'">'.ucfirst($position).' - Film # '.$film_number.'</option>'."\n"; } echo "</select>\n"; ?> <script language="javascript"> function Inint_AJAX() { try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript alert("XMLHttpRequest not supported"); return null; }; function reload(form){ var val=form.credit.options[form.credit.options.selectedIndex].value; } function dochange(src) { var req = Inint_AJAX(); req.onreadystatechange = function () { if (req.readyState==4) { if (req.status==200) { document.getElementById(src).innerHTML=req.responseText; //retuen value } } }; req.open("GET", "second_credit.php?credit="+val); //make connection req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header req.send(null); //send value } window.onLoad=dochange('second'); // value in first dropdown </script> <?php session_start(); $myusername=$_SESSION['myusername2']; $mypassword=$_SESSION['mypassword2']; require_once 'db_select.php'; require_once 'func.php'; $sql_credit="SELECT $tbl_name2.credit,$tbl_name.donor_id,$tbl_name2.film_number FROM $tbl_name JOIN $tbl_name2 USING (donor_id) WHERE $tbl_name.username='$myusername' AND $tbl_name.password='$mypassword'"; $result_credit=mysql_query($sql_credit) or die(mysql_error()); $content=' <div class="main"> <div class="main_header">Purchase Additional Credit</div>'; if($_GET['e']==t){ $content.='<p class="green clear"> Request Sent. You should be contact with a discounted crew credit button specifically for you, in the next two business days. </p> '; } else{ $content.=' <p> If you wish to purchase an additional credit, use the form below to select the credit you wish to buy, the name in which the original credit is listed under (as listed on the donors page), and the e-mail address in which the original purchase came from. This is a great to get your name back on the top 100 donors list. Once you submit this form, we will review the submitted material, create a new paypal purchase button specifically for you, and send you the link to that button. From there, you will be able to purchase the additional credit.'; if($_GET['e']==f){ $content.='<p class="red"> The email address you entered doesn\'t match the email in the database for this account. Please try again. <br /> If you keep having problems, please contact us at <a href="mailto:general@makethemoviehappen.com"> general@makethemoviehappen.com</a>. </p>'; } $content.=' <form action="" method="post"> <p><label>Name Credit is Listed Under:</label> <input type="text" name="name" size="30" /></p> <p><label>E-Mail of Original Purchase:</label> <input type="text" name="email" size="32" /></p>'; $content.='<p><label>Original Credit Purchased:</label> <select name="credit" onchange="reload(this.form)"> <option value="">Select Credit</option>'."\n"; while($row_credits=mysql_fetch_array($result_credit)){ extract($row_credits); $content.='<option value="'.ucfirst($credit).'-'.$film_number.'">'.ucfirst($credit).' - Film # '.$film_number.'</option>'."\n"; } $content.='</select></p>'."\n"; $content.=' <p><label>Second Credit to Purchase:</label> <span id="second"><select name="new_credit"> <option value="">Select Credit</option>'."\n". '</select></span></p>'."\n".' </p> <p><input type="submit" value="Submit" name="Submit" /></p> </form> '; } $content.=" </div> <br />"; ?>
-
Alright this is what I went with the below. My issue is how do I pass the position name to the second page to include in the DB query. ajax <script language="javascript"> function Inint_AJAX() { try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript alert("XMLHttpRequest not supported"); return null; }; function dochange(src) { var req = Inint_AJAX(); req.onreadystatechange = function () { if (req.readyState==4) { if (req.status==200) { document.getElementById(src).innerHTML=req.responseText; //retuen value } } }; req.open("GET", "second_credit.php?data="+src); //make connection req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header req.send(null); //send value } window.onLoad=dochange('second'); // value in first dropdown </script> second_credit.php <?php //set IE read from page only not read from cache header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header ("Cache-Control: no-cache, must-revalidate"); header ("Pragma: no-cache"); header("content-type: application/x-javascript; charset=tis-620"); require_once 'db_select.php'; $data=$_GET['data']; $position=$_GET['position']; if($data=='second') { // second dropdown $sql_second_credit="SELECT * FROM $tbl_name4 WHERE position='Seq$position' OR position='Tril$position'"; $result_second_credit=mysql_query($sql_second_credit) or die(mysql_error()); echo '<select name="new_credit">'; echo '<option value="">Select Credit</option>'; while($second_row_credits=mysql_fetch_array($result_second_credit)){ extract($second_row_credits); echo '<option value="'.ucfirst($credit).'">'.ucfirst($credit).'</option>'."\n"; } } echo "</select>\n"; ?> credit.php <?php session_start(); $myusername=$_SESSION['myusername2']; $mypassword=$_SESSION['mypassword2']; require_once 'db_select.php'; require_once 'func.php'; $sql_credit="SELECT $tbl_name2.credit,$tbl_name.donor_id,$tbl_name.position FROM $tbl_name JOIN $tbl_name2 USING (donor_id) WHERE $tbl_name.username='$myusername' AND $tbl_name.password='$mypassword'"; $result_credit=mysql_query($sql_credit) or die(mysql_error()); $content=' <div class="main"> <div class="main_header">Purchase Additional Credit</div>'; if($_GET['e']==t){ $content.='<p class="green clear"> Request Sent. You should be contact with a discounted crew credit button specifically for you, in the next two business days. </p> '; } else{ $content.=' <p> If you wish to purchase an additional credit, use the form below to select the credit you wish to buy, the name in which the original credit is listed under (as listed on the donors page), and the e-mail address in which the original purchase came from. This is a great to get your name back on the top 100 donors list. Once you submit this form, we will review the submitted material, create a new paypal purchase button specifically for you, and send you the link to that button. From there, you will be able to purchase the additional credit.'; if($_GET['e']==f){ $content.='<p class="red"> The email address you entered doesn\'t match the email in the database for this account. Please try again. <br /> If you keep having problems, please contact us at <a href="mailto:general@makethemoviehappen.com"> general@makethemoviehappen.com</a>. </p>'; } $content.=' <form action="" method="post"> <p><label>Name Credit is Listed Under:</label> <input type="text" name="name" size="30" /></p> <p><label>E-Mail of Original Purchase:</label> <input type="text" name="email" size="32" /></p>'; $content.='<p><label>Original Credit Purchased:</label> <select name="credit"> <option value="">Select Credit</option>'."\n"; while($row_credits=mysql_fetch_array($result_credit)){ extract($row_credits); $content.='<option value="'.ucfirst($credit).'">'.ucfirst($credit).'</option>'."\n"; } $content.='</select></p>'."\n"; $content.=' <p><label>Second Credit to Purchase:</label> <span id="second"><select name="new_credit"> <option value="">Select Credit</option>'."\n". '</select></span></p>'."\n".' </p> <p><input type="submit" value="Submit" name="Submit" /></p> </form> '; } $content.=" </div> <br />"; ?>
-
The only way I know to use AJAX is to place what is being called into a second file... The second drop down menu would be placed into a separate file with the MySQL query. So therefore this code: while($row_credits=mysql_fetch_array($result_credit)){ extract($row_credits); $content.='<option value="'.ucfirst($credit).'">'.ucfirst($credit).'</option>'."\n"; } Would be in a second file along with the SQL query. And a div block would be placed in the first page where the second drop down menu would go. How would the second drop down menu submit with the form if it's done this way.
-
Not that I can see. This is working fine. $sql_credit="SELECT $tbl_name2.credit,$tbl_name.donor_id FROM $tbl_name JOIN $tbl_name2 USING (donor_id) WHERE $tbl_name.username='$myusername' AND $tbl_name.password='$mypassword'";