illkillyouforfun Posted February 27, 2011 Share Posted February 27, 2011 This is what I'm getting... Notice: Undefined variable: sitetitle in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: ADcode in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: email in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: url in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: charge in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: currency in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: price in /home/vehiclep/public_html/functions.php on line 121 this is functions.php function sitesets() { $sql = "select * from settings limit 1"; $rs = mysql_query($sql); $row = @mysql_fetch_array($rs); extract($row); $sitesets = array("title"=>$sitetitle, "ADcode"=>$ADcode, "email" => $email, "url" => $url, "charge" => $charge, "currency" => $currency, "price" => $price); return $sitesets; } Ive tried going into phpMyadmin and creating a row and entering the info manualy but it doesnt work. I don't know much about coding so this may be a dumb question but it has me stumped. I hope somebody can tell me what I'm missing here. Quote Link to comment Share on other sites More sharing options...
silkfire Posted February 27, 2011 Share Posted February 27, 2011 Replace: $row = @mysql_fetch_array($rs); extract($row); with list($sitetitle, $ADcode, $email, $url, $charge, $currency, $price) = mysql_fetch_row($rs) Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 27, 2011 Share Posted February 27, 2011 You should be selecting just the fields you want. Then you can use msql_fetch_assoc and just return the the row. <?php function sitesets() { $sql = "select sitetitle, ADcode, email, url, charge, currency, price from settings limit 1"; $rs = mysql_query($sql); $sitesets = mysql_fetch_assoc($rs); return $sitesets; } ?> Ken Quote Link to comment Share on other sites More sharing options...
illkillyouforfun Posted February 27, 2011 Author Share Posted February 27, 2011 @ken I used what you gave me there and the error messages stopped coming up but there wasnt a new row created in the database with the information I entered. @silkfire I tried the code you gave me too and now I only get a blank page. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 27, 2011 Share Posted February 27, 2011 The code you posted doesn't insert a new row, it retrieves an existing row. What are you trying to accomplish? Ken Quote Link to comment Share on other sites More sharing options...
illkillyouforfun Posted February 27, 2011 Author Share Posted February 27, 2011 I am trying to insert a row. This is a settings area for my website's script where I enter the title, url, etc to be used as variables throughout it. Sorry if I am not being clear this is the first time I've worked with php or mySQL I am a newbie. I am thinking now there may be errors in two places now you've said that. I think the code you gave me corrected the function.php but I have to see another index.php file as well. <?php if(isset($_GET['page'])) { $page = $_GET['page']; switch ($page) { case "settings": print $utils->h1("Settings", ""); $settings = sitesets(); if(isset($_POST['sb'])) { $update = $query->update("update settings set sitetitle = '".addentities($_POST['title'])."', url = '".addentities($_POST['url'])."', email = '".addentities($_POST['email'])."', ADcode = '".$_POST['adcode']."'"); if($update != 0) { print "Update took place successfully"; refreshPage(3, $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']); exit(); }else{ print "Error in trying to update!"; } } ?> <style> input{width:300px} textarea{width:300px; height:80px} </style> <form action="" method="POST"> <table> <tr><td>Website title</td><td><input type="text" name="title" value="<?=$settings['title'];?>"></td></tr> <tr><td>Website URL (include last slash "/")</td> <td><input type="text" name="url" value="<?=$settings['url'];?>"></td></tr> <tr><td>Email</td><td><input type="text" name="email" value="<?=$settings['email'];?>"></td></tr> <tr><td>Ad code</td><td><textarea name="adcode"><?=htmlentities($settings['ADcode']);?></textarea></td></tr> </table> <input type="submit" name="sb" id="sb" value="Update" style="width:100px"> </form> That is the code from the page where I am entering those variables. Quote Link to comment Share on other sites More sharing options...
illkillyouforfun Posted February 27, 2011 Author Share Posted February 27, 2011 Is there any errors in the script I just posted? Or in the HTML maybe. I really dont have a clue here I just need this to work so my site will function properly. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 28, 2011 Share Posted February 28, 2011 Unless you have your own function called addentities, there is no such function. You really should be using the function mysql_real_escape_string() on any user supplied data that is being used in a mysql query. Also, don't use "<?=", use "<?php echo " instead. If "short-tags" are disabled on your site, the "<?=" short cut won't work. <?php if(isset($_GET['page'])) { $page = $_GET['page']; switch ($page) { case "settings": print $utils->h1("Settings", ""); $settings = sitesets(); if(isset($_POST['sb'])) { $update = $query->update("update settings set sitetitle = '".mysql_real_escape_string($_POST['title'])."', url = '".mysql_real_escape_string($_POST['url'])."', email = '".mysql_real_escape_string($_POST['email'])."', ADcode = '".mysql_real_escape_string($_POST['adcode'])."'"); if($update != 0) { print "Update took place successfully"; refreshPage(3, $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']); exit(); }else{ print "Error in trying to update!"; } } ?> <style> input{width:300px} textarea{width:300px; height:80px} </style> <form action="" method="POST"> <table> <tr><td>Website title</td><td><input type="text" name="title" value="<?php echo $settings['title'];?>"></td></tr> <tr><td>Website URL (include last slash "/")</td> <td><input type="text" name="url" value="<?php echo $settings['url'];?>"></td></tr> <tr><td>Email</td><td><input type="text" name="email" value="<?php echo $settings['email'];?>"></td></tr> <tr><td>Ad code</td><td><textarea name="adcode"><?php echo htmlentities($settings['ADcode']);?></textarea></td></tr> </table> <input type="submit" name="sb" id="sb" value="Update" style="width:100px"> </form> Ken Quote Link to comment Share on other sites More sharing options...
illkillyouforfun Posted February 28, 2011 Author Share Posted February 28, 2011 I have no idea why this isn't working but even with the code you just gave me it still isn't creating a new row. I appreciate the help though. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 28, 2011 Share Posted February 28, 2011 Using the MySQL update command doesn't create new rows, it updates existing rows. To create new rows, you need to using the insert command. Ken Quote Link to comment Share on other sites More sharing options...
illkillyouforfun Posted February 28, 2011 Author Share Posted February 28, 2011 Ok, so I change the $update to $insert? Will that work? Quote Link to comment Share on other sites More sharing options...
illkillyouforfun Posted February 28, 2011 Author Share Posted February 28, 2011 So is there anyway that I can add this row manually or anything at all I can do to make this happen? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.