Jump to content

ramone_johnny

Members
  • Posts

    50
  • Joined

  • Last visited

About ramone_johnny

  • Birthday 04/27/1973

Contact Methods

  • Website URL
    http://www.worksmedia.com.au

Profile Information

  • Gender
    Male
  • Location
    Sydney, NSW

ramone_johnny's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi guys, I'm trying to pull a value from the database and assign it to a variable, of which I then need to populate another table. My background is ASP/MSSQL so I'm not overly familiar with how to do this. I have the following query, which is erroring out. I need help here. $r=query_wrapper("SELECT pcode_area, pcode_postcode, pcode_city FROM tblnew_cities WHERE pcode_area = ?",$share_suburb . " AND pcode_postcode = ?",share_postcode); $rstDBEdit=mysql_fetch_assoc($r); $a = array(); $a["pcode_city"] = $pcode_city; echo $pcode_city; exit(); Then of course once I have the $pcode_city I need to insert it into the tblshare_adverts table. (see below) $r=query_wrapper("SELECT * FROM tblshare_adverts"); $rstDBEdit=mysql_fetch_assoc($r); $a = array(); $a["share_number"] = $share_number; $a["share_street"] = $share_street; $a["share_suburb"] = $share_suburb; ....etc etc $a["share_city"] = $pcode_city; ...etc etc query_wrapper("INSERT INTO tblshare_adverts SET ?%",$a); $share_ID = mysql_insert_id(); I'm guessing this could be simplified by perhaps using an inner join and running just one query? Or is this way okay?
  2. Sorry, here's the query_wrapper stuff. // // sql_placehloder() + mysql_query(). // function query_wrapper() { global $linkScript; $args = func_get_args(); $tmpl = array_shift($args); if(is_resource($tmpl)) { $link=$tmpl; $tmpl = array_shift($args); } else $link=$linkScript; $query = sql_placeholder_ex($tmpl, $args, $error); if ($query === false) { $error = "Placeholder substitution error. Diagnostics: \"$error\""; if (function_exists("debug_backtrace")) { $bt = debug_backtrace(); $error .= " in ".@$bt[0]['file']." on line ".@$bt[0]['line']; } trigger_error($error, E_USER_ERROR); return false; } $r = mysql_query($query,$link); if (!$r) { echo "<hr>$query<hr>"; $error = "Mysql_query error: ".mysql_error(); if (function_exists("debug_backtrace")) { $bt = debug_backtrace(); $error .= " in ".@$bt[0]['file']." on line ".@$bt[0]['line']; } trigger_error($error, E_USER_ERROR); } return $r; } ?>
  3. Well when I run this, I get an error that indicates that its pulling those a$ values the second time round. My best guess was that I might need to change the second query to use something like b$, but that would be a complete guess.
  4. That's a good question - lol I *think* it prevents sql injection attacks.
  5. Sorry guys, I'm relatively new at PHP, and as I've never done this before, I need to ask. How do I correctly format the syntax below in order to insert to 2 separate tables, one after the other? $r=query_wrapper("SELECT * FROM tblmembers WHERE mem_email = ?",$mem_email); $rstDBEdit=mysql_fetch_assoc($r); if($rstDBEdit) redirect("/message.php?message=already_a_member"); $a["mem_name"] = $mem_name; $a["mem_password"] = $mem_password; $a["mem_email"] = $mem_email; .... query_wrapper("INSERT INTO tblmembers SET ?%",$a); $mem_ID = mysql_insert_id(); ---------------------------------------------------- $r=query_wrapper("SELECT * FROM tblshare_adverts"); $rstDBEdit=mysql_fetch_assoc($r); $a["share_available"] = $share_available; $a["share_header"] = $share_header; $a["share_description"] = $share_description; .... query_wrapper("INSERT INTO tblshare_adverts SET ?%",$a); $share_ID = mysql_insert_id();
  6. I have the following snippet of code that I *think* is right, but being new to PHP I just wanted if someone could let me know if this is indeed correct. I'm simply redirecting the user if they are already a member (email exists in the db) $r=query_wrapper("SELECT * FROM tblmembers WHERE mem_email = ?",$mem_email); $rstDBEdit=mysql_fetch_assoc($r); if($rstDBEdit) redirect("/message.php?message=already_a_member");
  7. Well this might be a separate question, but I'm not sure I want null values for any of these request variables. Infact, I know I dont. Certainly not in the DB. Is there a better way to write this? $_SESSION['start'] = isset($_REQUEST["start"]) ? $_REQUEST["start"] : ""; Can I strip that stuff off the end and make sure isset($_REQUEST["start"]) actually holds a value?
  8. Yeah I don't really understand what : ""; actually means on the end there. Sorry, working with someone elses code. Is that simply setting a base (default) value if nothing is passed?
  9. Sorry I just realised I was killing the session and then resetting it. My apologies. *doh! I'm not quite sure where I set $_SESSION[''start'] to ''? I'm debugging it to screen and it's showing 1 based upon the previous page. <input type="hidden" name="start" value="1" id="start" />
  10. Hey guys, I have the following snippet of code that I'm *trying* to use in order to redirect users based upon a session time out. As I've relatively new to PHP and never written a redirect before, I just wanted to check that it's okay. $_SESSION['start'] = isset($_REQUEST["start"]) ? $_REQUEST["start"] : ""; if (!isset($_SESSION['start'])) { header('Location:http://localhost/advertise/placeanad.php'); session_destroy(); exit(); } The page doesn't redirect, it just sits there - even upon refreshing it. Is there something I'm missing? Do I need to use an !empty statement or something?
  11. Ahh, perfect! Thanks dude, appreciate it.
  12. Thanks man. Sorry, I'm not intending to be lazy - I'm just completely new at PHP. Here's what i ended up with. It seems to work, but I'd say it could be written more efficiently. <?php $prefage_options = ''; $selected_value = false; if (!isset($_SESSION['share_prefage']) || !ctype_digit($_SESSION['share_prefage'])) { // no session value or session value is text $prefage_options .= "<option value='Doesnt Matter'>Doesnt Matter</option>\n"; } else { $selected_value = $_SESSION['share_prefage']; } for ($i=18; $i<=99; $i++) { $selected = ($i == $selected_value) ? ' selected="selected"' : ''; $prefage_options .= "<option value='{$i}'{$selected}>Around {$i}</option>\n"; } ?> <select name="share_prefage" class="textarea" style="width:150px"> <?php if (isset($_SESSION['share_prefage']) AND ctype_digit($_SESSION['share_prefage'])) { //Session value is number. Set selected value $prefage_options .= "<option value='Doesnt Matter'>Doesnt Matter</option>\n"; } echo $prefage_options; ?> </select> Here's what I changed/added. <?php if (isset($_SESSION['share_prefage']) AND ctype_digit($_SESSION['share_prefage'])) { //Session value is number. Set selected value $prefage_options .= "<option value='Doesnt Matter'>Doesnt Matter</option>\n"; } echo $prefage_options; ?>
  13. The error is .... Warning: in_array() expects parameter 2 to be array, string given in C:\xampp\htdocs\advertise\placeanad.php on line 336 Which is... $checked = (in_array($r['cat_ID'], $selectedCategories)) ? ' checked' : ''; Because $_SESSION['share_category'] has no value.
×
×
  • 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.