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. Link to comment https://forums.phpfreaks.com/topic/229053-undefined-variables-getting-error-messages/ 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) Link to comment https://forums.phpfreaks.com/topic/229053-undefined-variables-getting-error-messages/#findComment-1180472 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 Link to comment https://forums.phpfreaks.com/topic/229053-undefined-variables-getting-error-messages/#findComment-1180476 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. Link to comment https://forums.phpfreaks.com/topic/229053-undefined-variables-getting-error-messages/#findComment-1180478 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 Link to comment https://forums.phpfreaks.com/topic/229053-undefined-variables-getting-error-messages/#findComment-1180485 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. Link to comment https://forums.phpfreaks.com/topic/229053-undefined-variables-getting-error-messages/#findComment-1180488 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. Link to comment https://forums.phpfreaks.com/topic/229053-undefined-variables-getting-error-messages/#findComment-1180508 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 Link to comment https://forums.phpfreaks.com/topic/229053-undefined-variables-getting-error-messages/#findComment-1180629 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. Link to comment https://forums.phpfreaks.com/topic/229053-undefined-variables-getting-error-messages/#findComment-1180655 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 Link to comment https://forums.phpfreaks.com/topic/229053-undefined-variables-getting-error-messages/#findComment-1180658 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? Link to comment https://forums.phpfreaks.com/topic/229053-undefined-variables-getting-error-messages/#findComment-1180672 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? Link to comment https://forums.phpfreaks.com/topic/229053-undefined-variables-getting-error-messages/#findComment-1180919 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.