Jump to content

Dark-Hawk

Members
  • Posts

    46
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Dark-Hawk's Achievements

Member

Member (2/5)

0

Reputation

  1. Good catch, thanks! Been a while since I've worked in PHP :/. Any insight as to why it is simply grabbing the contents of the included file as opposed to simply utilizing the variables?
  2. This may be fairly odd architecture with how this script is ultimately being ran. I'm attempting to run a PHP script through an Enterprise job scheduler client on Windows, with an Agent on Fedora Linux. I have Apache/PHP/MySQL configured properly. I was originally having issues determining the path to place the config file on Fedora but determined it needed to be placed in /usr/share/php. The issue I'm having however, is my script is just printing the include file information in the script, rather than simply utilizing the variables within it for the MySQL DB. So the config.php file is fairly straight forward and just contains: <? $host = "0.0.0.0"; $username = "root"; $password = "*****"; $db = "processid"; ?> The script itself is: <?include '/usr/share/php/config.php'; $con = mysqli_connect('$host','$username','$password','$db'); // Check connectionif (mysqli_connect_errno()){ echo "Failed to connect to MySQL: " . mysqli_connect_error();} for($x = 0; $x < 15; $x++) {mysqli_query($con,"INSERT INTO idnumbers (ID)VALUES ('$x')");} mysqli_close($con);?> The output from my job scheduler is: <? $host = "0.0.0.0"; $username = "root"; $password = "****"; db = "processid"; ?> PHP Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 5 PHP Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 5 Failed to connect to MySQL: php_network_getaddresses: getaddrinfo failed: Name or service not knownPHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 15 PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 15 PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 15 PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 15 PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 15 PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 15 PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 15 PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 15 PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 15 PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 15 PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 15 PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 15 PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 15 PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 15 PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 15 PHP Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in /root/.jams/job/07/cd0400-9b56-4409-a49b-52dc5b425016 on line 18
  3. The difference between ASP and PHP is quite a bit. Here's the login section of my script: <? // start session session_start(); // start output buffering ob_start(); // File includes include "cfg.php"; include "functions.php"; include "variables.php"; // has form been submitted if ($_POST['Submit'] == 'Login') { $md5pass = md5(sanitize($_POST['password'])); $sql = mysql_query(sprintf("SELECT email, level FROM $tbl_name WHERE email='%s' and password='%s' and confirm='%d'", sanitize($_POST['email']), $md5pass, (int)1)); // we have a match if (mysql_num_rows($sql) > 0) { // A matching row found (thus the name/pass found) - authenticated list($email, $level) = mysql_fetch_row($sql); //list($level) = mysql_fetch_row($sql); // set user session $_SESSION['user'] = $email; // set session level - this is for security $_SESSION['level'] = $level; // redirect if ($_SESSION['level'] == 1) { // the user is logged in as non-admin header("Location: calendar.php?msg=Logged In"); exit(); } if ($_SESSION['level'] == 2) { // the user is logged in as an admin header("Location: admin/index.php"); exit(); } } else { // Add to DB that a failed login attempt occured mysql_query(sprintf("INSERT into $tbl_logins (email, password, date, ip, id) VALUES ('%s', '%s', '%s', '%s', '%d')", sanitize($_POST['email']), sanitize($_POST['password']), $today, $ip, '')) or die('SQL Error : ' . mysql_error()); $error = mysql_error(); header("Location: login.php?msg=Invalid Login"); exit(); } } else { ShowLogin(); } ?> <link href="styles.css" rel="stylesheet" type="text/css"> <?php $msg = htmlentities(trim($_GET['msg'])); $msg = (isset($msg)) ? true : false; if ($msg) { echo "<div class='msg'> $_GET[msg] </div>"; } // release output buffer ob_end_flush(); ?>
  4. You're going to need to post the code and let us know what errors you're having for anyone to help out.
  5. I'm assuming this is to update a user record in the admin control panel. I have something similar I do, here's the update part of the script: // edit $edit = $_GET['edit']; $edit_first = $_POST['edit_first']; $edit_last = $_POST['edit_last']; $edit_addr = $_POST['edit_addr']; $edit_city = $_POST['edit_city']; $edit_zip = $_POST['edit_zip']; $edit_phone = $_POST['edit_phone']; $edit_answer = $_POST['answer']; $edit_pw = md5($_POST['edit_pw']); $edit_level = $_POST['edit_level']; $edit_email = $_POST['edit_email']; if ($post == "edit") { $query = "UPDATE $tbl_name SET first_name='$edit_first', last_name='$edit_last', password='$edit_pw', address='$edit_addr', city='$edit_city', zip='$edit_zip', phone='$edit_phone', answer='$edit_answer', email='$edit_email', level='$edit_level' WHERE id='$edit_id'"; mysql_query($query); echo "<div align=center><b>Editied $edit_first $edit_last</b></div><br><br>"; } $query = "SELECT * FROM $tbl_name WHERE id='$edit'"; $result = mysql_query($query); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_array($result); ?> <form method="post" action="<? echo $PHP_SELF; ?>"> <table cellpadding=3 cellspacing=0 border=0 width="100%"> <tr><td colspan=4><b>Edit User</b></td></tr> <tr><td class="dots" colspan=4></td></tr> <tr> <td><b>First Name:</b></td> <td><b>Last Name:</b></td> <td><b>Password:</b></td> <td><b>Admin:</b></td> <td><b>E-Mail:</b></td> </tr> <tr> <td><input type="text" name="edit_first" value="<? echo $row['first_name']; ?>" size=25></td> <td><input type="text" name="edit_last" value="<? echo $row['last_name']; ?>" size=25></td> <td><input type="text" name="edit_pw" value="<? echo $row['password']; ?>" size=25></td> <td><input checked="<? if ($row['level'] == 1) { echo "checked"; } else { echo ""; } ?>" name="level" type="checkbox" value="1" /></td> <td><input type="text" name="edit_email" value="<? echo $row['email']; ?>" size=25></td> </tr> <tr> <td colspan=4 align=right> <input type="hidden" value="<? echo $row['id']; ?>" name="edit_id"> <input type="hidden" value="edit" name="post"> <input type="submit" value="Edit User"> </td> </tr> </table> </form> <? } Connection is handled in the cfg file as: <? $server = "server"; $sqluser = "user"; $sqlpass = "pass"; $db = "db name"; $tbl_name = "table"; // Standard SQL connection $mysql_link = mysql_connect("$server", "$sqluser", "$sqlpass") or die("Unable to connect to MySQL server"); mysql_select_db("$db") or die( "It's connecting to the MySQL server, but unable to select database");
  6. Alright, here is part of a script I'm working on that simply wont post or edit a number of fields to the DB. It's not returning any errors, but simply put it's not doing anything at all and I cannot see why. I basically reused another part of the application here and just changed the fields as it's all the same. Other one works fine .. this one, not so much. So here's part of the script that's applicable, I can post the entire thing if wanted: include "header.php"; include "menu.php"; // add $range_time = $_GET['range_time']; // Time range IE: 4pm to 5pm $range_days = $_GET['range_days']; // Range of days in the month to display $amount = $_GET['amount']; // this is the amount of sign ups per time slot $duration = $_GET['duration']; // duration of meetings $group = $_GET['group']; // group name $month = $_GET['month']; // numerical representation of month for group if ($post == "add") { $range_time = $hour1 . ':' . $minute1 . '-' . $hour2 . ':' . $minute2; $range_days = $day1 . "-" . $day2; if ( ($range_time) && ($range_days) && ($amount) && ($duration) && ($group) && ($month) ) { mysql_query(sprintf("INSERT into groups (range.time, range.days, amount, duration, group, month, id) VALUES ('%s', '%s', '%d', '%d', '%s', '%d', '%d')", $_POST['range_time'], $_POST['range_days'], $_POST['amount'], $_POST['duration'], $_POST['group'], $_POST['month'], '')) or die('SQL Error : ' . mysql_error()); $error = mysql_error(); echo $error; echo "<div align=center><b>Added $group</b></div><br><br>"; } } <form method="post" action="<? echo $PHP_SELF; ?>"> <table cellpadding=3 cellspacing=0 border=0 width="100%"> <tr> <th></th> <th>Time Range</th> <th>Range of Days</th> <th>Sign Ups per Time</th> <th>Duration of Meeting</th> <th>Group</th> <th>Month</th> <th>ID</th> <th></th> </tr> <? if ($month_search == "all") { $mon = "month='1' OR month='2' OR month='3' OR month='4' OR month='5' OR month='6' OR month='7' OR month='8' OR month='9' OR month='10' OR month='11' OR month='12' "; } else { $mon = "month='$month_search' "; } $sort = "ORDER BY $sort $order"; if ($group) { $group = "WHERE group LIKE '%$group%' AND "; } else { $group = "WHERE "; } $query = "SELECT * FROM groups ".$group.$mon.$sort; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $bgcolor = ($bgcolor == "#F0F0F0"?"#DFDFDF":"#F0F0F0"); ?> <tr bgcolor="<? echo $bgcolor; ?>"> <td align=center><a href="<? echo $PHP_SELF."?edit=".$row['id']; ?>" class="blue">Edit</a></td> <td align=center><? echo $row['range.time']; ?></td> <td align=center><? echo $row['range.days']; ?></td> <td align=center><? echo $row['amount']; ?></td> <td align=center><? echo $row['duration']; ?></td> <td align=center><? echo $row['group']; ?></td> <td align=center><? echo $row['month']; ?></td> <td align=center><? echo $row['id']; ?></td> <td align=center><input type="checkbox" name="del[]" value="<? echo $row['id']; ?>" class="checkbox"></td> </tr> <? } mysql_free_result($result); ?> <tr> <td colspan=7 align=right> <input type="hidden" value="del" name="post"> <input type="submit" value="Delete Checked"> </form> </td> </tr> </table> <? } ?> <br><br> <form method="post" action="<? echo $PHP_SELF; ?>"> <table cellpadding=3 cellspacing=0 border=0 width="100%"> <tr><td colspan=4><b>Add Group</b></td></tr> <tr><td class="dots" colspan=4></td></tr> <tr> <td><b>Time Range:</b></td> <td><b>Day Range:</b></td> <td><b>Sign Ups:</b></td> <td><b>Duration:</b></td> <td><b>Group Name:</b></td> <td><b>Month:</b></td> </tr> <tr> <td><select name="edithour1"> <? for($x = 1; $x <= 12; $x++) { echo "<option value='$x'>$x</option>"; } ?> </select><b>:</b> <select name="editminute1"><? for($a=0; $a < 6; $a++){ for($b=0; $b < 10; $b++){ echo "<option value='$a$b'>$a$b</option>"; } }?> </select> <b>-</b> <select name="edithour2"> <? for($z = 1; $z <= 12; $z++) { echo "<option value='$z'>$z</option>"; } ?> </select><b>:</b> <select name="editminute2"> <?for($a=0; $a < 6; $a++){ for($b=0; $b < 10; $b++){ echo "<option value='$a$b'>$a$b</option>"; } }?> </select> </td> <td> <select name="editday1"> <option selected="selected" value="sun">Sunday</option> <option value="mon">Monday</option> <option value="tue">Tuesday</option> <option value="wed">Wednesday</option> <option value="thu">Thursday</option> <option value="fri">Friday</option> <option value="sat">Saturday</option> </select> <b>-</b> <select name="editday2"> <option selected="selected" value="sun">Sunday</option> <option value="mon">Monday</option> <option value="tue">Tuesday</option> <option value="wed">Wednesday</option> <option value="thu">Thursday</option> <option value="fri">Friday</option> <option value="sat">Saturday</option> </select> </td> <td> <select name="edit_amount"> <?php for($x = 1; $x <= 10; $x++) { echo "<option value='$x'>$x</option>"; } ?> </select> </td> <td> <select name="edit_duration"> <?php for ($y = 5; $y <= 60; $y += 5) { echo "<option value='$y'>$y</option>"; } ?> </select> </td> <td> <input type="text" name="edit_group" value="<?php echo $row['group']; ?>" size=20> </td> <td> <?php $month_names = array( 'Jan'=> '', 'Feb'=>'', 'Mar'=>'','Apr'=>'', 'May'=> '', 'Jun'=>'', 'Jul'=>'','Aug'=>'', 'Sep'=> '', 'Oct'=>'', 'Nov'=>'', 'Dec'=>''); $month_names[date('M')] = ' selected'; echo '<select name="month"> '; foreach($month_names as $month=> $selected){ echo '<option value="'.$month.'"'.$selected.'> '.$month.'</option>'; } echo '</select> '; ?> </td> </tr> <tr> <td colspan=4 align=right> <input type="hidden" value="add" name="post"> <input type="submit" value="Add Group"> </td> </tr> </table> </form> config file is included in the header. This is the SQL structure: CREATE TABLE `groups` ( `range.time` varchar(128) NOT NULL default '', `duration` varchar(128) NOT NULL default '', `amount` varchar(128) NOT NULL default '', `group` varchar(128) NOT NULL default '', `month` varchar(12) NOT NULL default '0', `range.days` varchar(48) NOT NULL default '', `id` int(255) NOT NULL auto_increment, PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=2 ;
  7. I'll keep that in mind and possibly just store them in separate tables due to the way the script will be running. Thanks though!
  8. Yeah I know, you're missing what I'm saying though... Once they're in the table it will ONLY be the range of all of them combined, thus I wont be able to reference back to $hour1, $hour2, etc. For an entirely different part of the script I will need to split them back into the initial 4 variables...
  9. Sorry, so after combining the two times, they will go into one table on a database in the format of the aforementioned final variable. However, the range for the time is merely used to allow people to sign up in that given time range for an event. Thus, I'll need to take it once again and have it as hour1, hour2, minute1 and minute2 to keep the range properly set in a drop down box. Subsequently it'll give people incremental values of every 10 minutes that they can sign up in that time range ... I'm hoping that makes sense?
  10. I actually just figured that part out right as you posted, thanks! Any idea on then splitting it up when I pull it from the DB?
  11. Also any advice on splitting it, I'm presuming I'll have to use preg_match()?
  12. I'm having a little difficulty combining these variables. Just a test I set this up. I have 4 drop down boxes to select a particular time to set the range it will be displayed, however when it uploads to the database I need it to upload in the range like 1:30-4:55 for instance rather than uploading to 4 separate tables. <? $hour1 = 1; $minute1 = 30; $hour2 = 4; $minute2 = 55; $range_time = echo "$hour1 . ":" . $minute1 . "-" . $hour2 . ":" . $minute2"; echo "$range_time"; ?> Once doing the actual range I'll just split it all back up at the :'s and -'s. Thanks for the help in advance!
×
×
  • 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.