Jump to content

thereaper87

Members
  • Posts

    49
  • Joined

  • Last visited

    Never

Everything posted by thereaper87

  1. Hello there, here is my page I'm having problem with.. <?php session_start(); require_once 'database.php'; include("header.php"); $username="***"; $password = "****"; $hostname = "localhost"; $database = "***"; $id = $_GET['id']; // Connect to MySQL... $conn = mysql_connect($hostname, $username, $password) or die("Connecting to MySQL failed"); mysql_select_db($database, $conn) or die("Selecting MySQL database failed"); // Run our query, see if session username exists in session field... $sql="select username,gang,gangid from user where username='{$_SESSION['user']}' limit 1"; $result=mysql_query($sql,$conn); // Parse our results into $data (as an associative array)... $data=mysql_fetch_assoc($result); $gangsql="select id,to,gang,gangid from ganginv where id='$id' limit 1"; $gangresult=mysql_query($gangsql,$conn); // Parse our results into $data (as an associative array)... $data2=mysql_fetch_assoc($gangresult); // This is line 24 if ( $data['username'] == $data2['to'] ){ $gang = $data2['gang']; $gangid = $data2['gangid']; $insertelse="UPDATE user SET gang='$gang', gangid='$gangid' WHERE username='{$_SESSION['user']}'"; $insertresultelse=mysql_query($insertelse); }else{ echo "This invite was not for you."; } ?> What this does is it performs to queries to two different tables. Then it matches the usernames ( to make sure it's the same) and then update the table "user" to the column "gang" and "gangid". Here is the error it gives me: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home2/******/ganginv.php on line 24 This invite was not for you. Line 24 is marked. I appreciate all the help/info you have to offer!
  2. Sweet I just added: $db_name.$tbl_name [/code and it works! Thanks all 3 of you for your help!
  3. I changed it to this: $sql="DELETE FROM $tbl_name WHERE id=$id"; Still no go.
  4. Hello there, I have this bit of code: <?php $host="localhost"; // Host name $un="**"; // Mysql username $password="**"; // Mysql password $db_name="**"; // Database name $tbl_name="weddingpics"; // Table name // Connect to server and select database. mysql_connect("$host", "$un", "$password")or die("cannot connect"); $id = intval($_POST['id']); $sql="DELETE id='$id' FROM $tbl_name WHERE id=$id"; $result=mysql_query($sql); if($result){ echo "Successful"; echo "<BR>"; echo "<a href='weddingcakes.php'>View result</a>"; } else { echo "Error"; } ?> I've tried to reword the delete query but still no avail. If you are wondering where it pulls the `id` variable, it is on the previous page as a hidden attribute.
  5. Thank you so much! It works like a dream! I have accredited you on the page. Thanks again
  6. Still one horizontal line Should I move echo "<td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td>"; That line somewhere else? Inside this IF statement maybe?
  7. Thank you for the reply! Here is what I've changed the code to: $numCols = 5; $counter = 1; echo "<table>"; echo "<tr>"; //the table while($r = mysql_fetch_array($sql)) { $id = $r['id']; $title = $r['title']; $url = $r['url']; echo "<td>Cell content</td>"; echo "<td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td>"; if ($resultNum % $numCols == false) { echo "</tr>"; echo "<tr>"; } // end if } // end while echo "</tr>"; echo "</table></div>"; Is this correct? I hope not. It is just displaying a single horizontal line down the page.
  8. I have tried this: <?php echo $r['url']; ?><br /> <?php echo $r['title']; ?> But that will not work either.
  9. Hello there, I am working on a pagination script and have hit a bit of a wall. Here is the script: <?php include("header.php"); ?> <?php $host = "localhost"; // $user = ""; //username to connect to database $pass = ""; //password to connect to database $db = ""; //the name of the database mysql_connect($host,$user,$pass) or die("ERROR:".mysql_error()); mysql_select_db($db) or die("ERROR DB:".mysql_error()); $max = 25; //amount of articles per page. $p = $_GET['p']; if(empty($p)) { $p = 1; } $limits = ($p - 1) * $max; //view the article! if(isset($_GET['act']) && $_GET['act'] == "view") { $id = $_GET['id']; $sql = mysql_query("SELECT * FROM 3dpics WHERE id = '$id'"); while($r = mysql_fetch_array($sql)) { $title = $r['title']; $url = $r['url']; echo "<div align='center'><img src='$url' width='500' height='500'><br />$title<br /><br /><a href='test.php'>Back</a></div>"; } }else{ //view all the articles in rows $sql = mysql_query("SELECT * FROM 3dpics LIMIT ".$limits.",$max") or die(mysql_error()); //the total rows in the table $totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM 3dpics"),0); $totalpages = ceil($totalres / $max); echo "<table name='myTable' cellpadding='5' cellspacing='5'>"; echo "<tr>"; //the table while($r = mysql_fetch_array($sql)) { $id = $r['id']; $title = $r['title']; $url = $r['url']; echo "<div id='piccontentalign' align='center'>"; echo "<td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td>"; } echo "</tr></table></div>"; //close up the table for($i = 1; $i <= $totalpages; $i++){ //this is the pagination link echo "<a href='test.php?p=$i'>$i</a>|"; } } ?> All this does is pull the url's of the images out of the database. But, it all shows up on 1 line across the screen! I tried echoing the rows instead, but then it just shows up as 1 line going horizontal. So i'm trying to figure out a way to get 5 pictures per row. This is the code that displays them on the main page: echo "<table name='myTable' cellpadding='5' cellspacing='5'>"; echo "<tr>"; //the table while($r = mysql_fetch_array($sql)) { $id = $r['id']; $title = $r['title']; $url = $r['url']; echo "<div id='piccontentalign' align='center'>"; echo "<td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td>"; } echo "</tr></table></div>"; //close up the table Thanks for all your help!
  10. This will be a little difficult to explain, but keep with me. On the profile.php page. It starts a new session. // Connect to MySQL... $conn = mysql_connect($hostname, $username, $password) or die("Connecting to MySQL failed"); mysql_select_db($database, $conn) or die("Selecting MySQL database failed"); // Run our query, see if session username exists in session field... $sql="select username,email from user where username='{$_SESSION['user']}' limit 1"; $result=mysql_query($sql,$conn); // Parse our results into $data (as an associative array)... $data=mysql_fetch_assoc($result); // If one row was found in the result set, username exists... if (mysql_num_rows($result)==1) { $_SESSION['sellername'] = $data['username']; So what I am hoping that is doing, is the session named "sellername" is stored with the variable of the logged in user. In this example "testuser". Now the page updates.php will have an id attached to like so: updates.php?id=13. Which will have info only available for testuser's eyes. On the page it does this. // Connect to MySQL... $conn = mysql_connect($hostname, $username, $password) or die("Connecting to MySQL failed"); mysql_select_db($database, $conn) or die("Selecting MySQL database failed"); // Run our query, see if session username exists in session field... $sql="select username from user where username='{$_SESSION['user']}' limit 1"; $result=mysql_query($sql,$conn); // Parse our results into $data (as an associative array)... $data=mysql_fetch_assoc($result); // If one row was found in the result set, username exists... if (mysql_num_rows($result)==1) { $query='select seller from listings where seller = "'.$data['username'].'"'; $queryresult=mysql_query($query,$conn); while($info = mysql_fetch_assoc($queryresult)){ if ( $_SESSION['sellername'] == $info['seller'] ){ The if statement should process: "If the session variable for 'sellername' equals the database entry 'seller' then display the rest of the page." However, no matter what user is logged, it will display the page. Any ideas?
  11. Sorry for not showing much code. But you are awesome and it now works! Thanks a mil!
  12. Hello there, I have this snippet of code echo "<td><a href='inc/browse.php?act=view&id=$id'>$title</a></td><td>$author</td>"; } } //close up the table echo "</tr></table>"; This is the code that actually displays the links that go to the listing. The problem is, they all show on one line across the screen. How can it be configured to where the next listing is displayed below the previous one. I tried putting: echo "<br />" But didn't do it. Any ideas?
  13. Also, it worked! Thanks a mil for your help!
  14. So, the initial query has to be ran first before it can do the if statement?
  15. Hello there, I have this snipped of code I have been trying to create since tuesday. So far there has been little success. What this does is, if the logged in user has 20,000,000 xp or more, it completes the mysql query which subtracts the 20,000,000. But if the user has less than 20,000,000 xp, it will echo "Do not have enough xp"....here is the code: <?php session_start(); include('../database.php'); $userid = $_SESSION['user']; $userxp = "SELECT xp FROM user WHERE username = '$userid'"; $amount = 19999999; if ($userxp > $amount){ $query = "UPDATE `user` SET `xp`=(`xp`-20000000) WHERE `username` = '$userid' LIMIT 1"; $result = mysql_query($query) or die('Query: ' . $query . '<br />Failed with: ' . mysql_error()); echo "You have purchased this item"; } else { echo "You do not have enough xp!"; } ?> If you need any additional info please ask! Right now I'm on an airplane so I may not be able to respond quickly.
  16. I think I love you. I know, but I have been working on this for 2 weeks and you are just amazing! Thank you so much!!!
  17. With putting that line instead, it now gave this error when ran: Query: UPDATE `user` SET `xp`=(`xp`+100) WHERE `id` = Limit 1 Failed with: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Limit 1' at line 1
  18. Any idea where to go from here? Maybe use this? $sql="select username,xp from user where username='{$_SESSION['user']}' limit 1"; That is on my profile page that I put together. Not sure if that is useful.
  19. It gives this, which I have no idea what it is saying. Query: UPDATE user SET xp=(xp+100) WHERE 'id' = ksystem LIMIT 1 Failed with: Unknown column 'ksystem' in 'where clause' ksystem is the profile i'm logged into. Is that the problem? Since, shouldn't it be a number? Because my MySql table is set up like this: `id` int(4) unsigned NOT NULL auto_increment, `username` varchar(32) NOT NULL, `password` varchar(32) NOT NULL, `xp` int(11) default '0', PRIMARY KEY (`id`)
  20. I ran that exact code and it said "Query Failed". Just from the limited experience, should this "UPDATE `user` have the apostrophe? Would instead it go like "UPDATE user SET... ?
  21. Well using that code I posted above didn't give any errors, but it also didn't add the 100.
  22. So it would look like this?? Sorry I am very new to PHP. 3rd week actually <?php session_start(); include('../database.php'); $userid = $_SESSION['user']; $result = mysql_query("SELECT xp, level FROM user WHERE id=$userid"); (UPDATE `user` SET `xp`=(`xp`+100) WHERE `id` = $userid") ?> Is that how to do it?
  23. Hello there, first post! I have two pages: This one is submitxp.php <?php include("../../tophead.php"); ?> <form id="addxp" method="post" action="addxp.php"> <input type="submit" value="Add"> </form> Then the process page addxp.php <?php include("../../tophead.php"); ?> <?php include('../database.php'); $userid = $_SESSION['user']; $result = mysql_query("SELECT xp, level FROM user WHERE id=$userid"); row 7 $row = mysql_num_rows($result); while($row = mysql_fetch_assoc($result)) row9 { $exp = $row['xp']; } if (surfed){ $newexp += 100; } $inputexp = mysql_query("UPDATE user SET xp='$newexp' WHERE id='$userid'"); ?> What this supposed to do, is the person presses the submit button on submitxp.php it will take the logged in user, find their row in the database and add 100 to their total xp amount. It gives at least two errors that say: mysql_num_rows(): supplied argument is not a valid MySQL result resource in row 7 and mysql_num_rows(): supplied argument is not a valid MySQL result resource in row 9
×
×
  • 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.