jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
For de-bugging purposes, lets show the query: Change this line: $result = mysql_query("UPDATE `profilepicture` SET `default` ='$default' WHERE `big` ='$picture'"); To: $sql = "UPDATE `profilepicture` SET `default` ='$default' WHERE `big` ='$picture'" $result = mysql_query($sql) or trigger_error($sql . ' has failed. <br /> ' . mysql_error()); echo 'DEBUG -> ' . $sql . '<br />'; Now, try selecting the radio button, and then try it with the button un-selected. The query should change from 1 to 0. [/code]
-
Cant Find a Single Login Script Tutorial That Works!!!
jcbones replied to batstanggt's topic in PHP Coding Help
Even though it says registration failed, you probably still have the registered username and password in the database. Try changing the addNewUser() function to: function addNewUser($username, $password){ global $conn; $q = "INSERT INTO users VALUES ('$username', '$password')"; mysql_query($q,$conn); return mysql_affected_rows(); } -
Variable Scope in PHP
-
Did you set the content-type to 'text/html' ?
-
Cant Find a Single Login Script Tutorial That Works!!!
jcbones replied to batstanggt's topic in PHP Coding Help
YES! -
Are you wanting to the total of all of the points? ie 150 + 180 + 210? With the name of the team, or do you want the team with a listing of the points?
-
PHP & MySQL: Best function for last post time
jcbones replied to Clarkeez's topic in PHP Coding Help
There are two ways to do this: 1. Use the mysql function NOW() to insert the current timestamp into a timestamp column. INSERT INTO table (column1,column2,lastpost) VALUES ('column','column',NOW()); 2. You can set the column to default to the current timestamp. This will eliminate the need to tell mysql to put anything in that column. CREATE TABLE IF NOT EXISTS `table` ( `column1` varchar(20) NOT NULL, `column2` varchar(20) NOT NULL, `lastpost` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ); My suggestions at least. -
It looks to me like you are setting the value of your radio button to the current default setting, thereby never changing it's value. //change: value="<?php echo $default; ?>" /> //to value="1" />
-
PHP & MySQL: Best function for last post time
jcbones replied to Clarkeez's topic in PHP Coding Help
Why not make lastpost a timestamp column in mysql, then just order it by the lastpost? -
$query120 = "SELECT frenusername, username FROM friendship WHERE username='{$username2}' OR frenusername='{$username2}' "; $result = mysql_query($query120) or trigger_error(mysql_error()); if(mysql_num_rows($result) > 0) { while($row = mysql_fetch_assoc($result)) { if($row['frenusername'] == $username2) { $friends[] = $row['username']; } elseif($row['username'] == $username2) { $friends[] = $row['frenusername']; } } } echo $username2 . ' has ' . count($friends) . ' friends. They are ' . implode(', ',$friends); Surely there is a better way to design your friends system.
-
Why not just run your query like? $query120 = "SELECT frenusername, username FROM friendship WHERE username='{$username2}' OR frenusername='{$username2}' ";
-
Have you tried something along the lines of? Although your question (albeit non-existent) is very vague. $query1 ="SELECT jitem.*, jloc.jloc_id, jloc.jloc_loc FROM jitem LEFT JOIN jloc ON jloc.jloc_id IN(jitem.jitem_location)"; //SELECT ALL MY jitem items //$query2 ="SELECT jloc_id, jloc_loc FROM jloc"; //SELECT from a reference table for the select input options list if( $r = mysql_query($query1) ) { while( $row = mysql_fetch_assoc($r) ) { print "<tr>"; print "<td align=center valign=top><img src='thumbs/{$row['jitem_thumb']}' alt='{$row['jitem_title']}' /></td>"; print "<td align=center valign=top><input size=25 type=text name=jitem_title value='{$row['jitem_title']}'></td>"; print "<td align=center valign=top><textarea name=jitem_desc maxlength=1000 cols=35 rows=5>{$row['jitem_desc']}</textarea></td>"; print "<td align=center valign=top>\$<input size=5 type=text name=jitem_price value='{$row['jitem_price']}'></td>"; $selected = (!empty($row['jloc_id'])) ? 'selected="selected"' : NULL; $option[] = "<option $selected value={$row['jloc_id']} name=jloc_id>{$row['jloc_loc']}</option>"; } print "<td align=center valign=top><select>"; foreach($option as $value) { echo $value . "\n"; } print "</select></td>"; }
-
Parse error: syntax error, unexpected T_LOGICAL_OR
jcbones replied to yogen's topic in PHP Coding Help
That error should give you a line number, what is it? -
Pass search parameters when the links of pagination are clicked
jcbones replied to olinroger's topic in PHP Coding Help
Or, set them in a session variable. -
Are you suggesting I put my parameters in an array? I love to learn so please explain. Yes, that is what he is saying. On to another note, you should code functions so they are usable in a variety of situations. When you code a function so that it can only be used in one place of your code, it defeats the purpose of building a function. You could (and should) just write it out in the script. But, you can change this function (using arrays) so that you could run ANY update query through it, and make it work. Since you are having to type out the values anyway, just put them in a associative array, and let the function do the rest of the work. Example: function update(string $table, array $data, array $where) { foreach($data as $key => $value) { //go through the $data array. $info[] = $key . ' = \'' . mysql_real_escape_string(strip_tags($value)) . '\''; //build the column = value for each of the array members. } foreach($where as $key => $value) { //now go through the where array. $find[] = $key . ' = \'' . mysql_real_escape_string($value) . '\''; //building these columns like those above. } $sql = "UPDATE $table SET " . implode(', ',$info) . ' WHERE ' . implode(' AND ',$find); //build our query, turning the new info array into a comma separated string, and our where array into a string separated by AND. if(mysql_query($sql)) { //if the query executes. return mysql_affected_rows(); //return the affected rows. } return false; //if it doesn't return false. } //set the fields and the values inside an array. $arr['firstname'] = $firstname; $arr['lastname'] = $lastname; $arr['dateofbirth'] = $dateofbirth; $arr['city'] = $city; $arr['state'] = $state; $arr['country'] = $country; $arr['personalweb'] = $personalweb; //etc. //now set you where clause in an array. $find['username'] = $username; //now pass all this info to the function, with the table name; update('users',$arr,$find); if(!empty($capitalavailable)) { $arr['capital_available'] = $capitalavailable; $find['uid'] = $GLOBALS['user_info']['uid']; //update the investor info table, update('investor_info',$arr,$find); } //Now this function is NOT dependent on this specific use. As we can now pass any table, and any columns to it. $arr['make'] = 'Ford'; $arr['model'] = 'F250'; $arr['price'] = 49,999; $find['city'] = 'Memphis'; $find['state'] = 'Tenn'; update('cars',$arr,$find);
-
<?php $query = "select * from gamedata ORDER BY gamedata . score DESC"; $result = mysql_query($query); $rank = mysql_num_rows($result); $i = 0; //set $i as 0; ?> </header> <h2>Rankings</h2> <div> <table width="100%"> <tr> <th align="left">Rank</th> <th align="left">Username</th> <th align="left">Score</th> </tr> <?php while($row = mysql_fetch_array($result)) { echo '<tr>'; echo '<td>'; echo ++$i; //increment $i and then echo it out. echo '</td>'; echo '<td>'; echo '<form name=view method=get action=viewprofile.php>'; echo "<input type=hidden name=username value="; echo $row['username']; echo "/>"; echo "<a href=viewprofile.php?username="; echo $row['username']; echo ">"; echo $row['username']; echo "</a></td></form>"; echo '<td>'; echo $row['score']; echo '</td>'; echo '</tr>'; } ?> </table>
-
Help Please, New at PhP and ran into an issue
jcbones replied to seetheworldsecond's topic in PHP Coding Help
So, being un-familiar with the ebay API. Does it accept item id's as a comma separated list? OR, do you have to call each item id individually? There are a lot of way to get the id's back from an array. $comma_separated_list = implode(',',$items); -
You are qualified, as you just gave some great advice.
-
Is this the whole script?
-
WebStyles missed changing this line: echo "<tr bgcolor=\"{$bgColors[$row['sex']]}\">\n"; //should be echo "<tr bgcolor=\"{$bgColors}\">\n"; If the column 'note_end_date' is a date, datetime, or timestamp column.
-
A couple of notes. 1. You need to limit it somehow, so that one person cannot sign up a bunch of accounts under one user. 2. I would set up a trigger that occurred AFTER the registration process, that would add the credit to the user. That would save from a user getting credits on referrals that didn't complete the process. Mysql Trigger
-
getimagesize() list($width,$height,$type) = getimagesize('image.jpg'); echo 'Image of type: ' . $type . ' has a width of: ' . $width . ' and a height of: ' . $height; If you want to resize the image, do a google search for 'php simple image'. White-hat-webdesign has a great little class that is easy to implement. Ah, webstyles beat me.
-
Cant figure why this wont insert to my database
jcbones replied to cjohnson9's topic in PHP Coding Help
You should probably define $query before you try to use it in the mysql_query() function. IE, move it ABOVE your database call. -
LEFT JOIN will return empty results from table 2, if none exist for the corresponding row in table 1. You should use just JOIN, this will omit results that do not exist in both tables.
-
Zip Code Database Project with Zip Code Distance Calculator