slappyjaw 08-29-2009, 01:29 AM Hey guys, Ok.. either i dont know how to code or there is a problem with the mysql server but its probably me.. anyway this script will not display the output by the echo command that i stated, can someone please help me solve this.ITS DRVIN ME CRAZY:eek:.haha than for any help.:thumbsup:<?php include("Connections/mysql.php"); ?>
<?
mysql_select_db('rubygir_slappyjaw', $mysql);
$myid = $_SESSION['kt_login_id'];
$result = mysql_query("SELECT * FROM friendreqs WHERE foridus2=$myid;");
while($row = mysql_fetch_array($result))
{
$userfrom = $row['userfrom'];
$usertime = $row['time'];
}
mysql_close($mysql);
$title = "Friend request";
//INCLUDE THE HEADER!
include("user_header.php");
?>
<html>
<body>
<table width="200" border="1">
<tr>
<td><? echo $userfrom;?> </td>
<td><? echo $usertime;?></td>
</tr>
</table>
</body>
</html>
whizard 08-29-2009, 01:33 AM 1st off:
CHange
$result = mysql_query("SELECT * FROM friendreqs WHERE foridus2=$myid;");
to
$result = mysql_query("SELECT * FROM friendreqs WHERE foridus2=$myid;") or die(mysql_error());
Secondly, what is the semicolon for at the end of the query?
Dan
_Aerospace_Eng_ 08-29-2009, 01:33 AM Its likely a scope issue. I believe anything declared within the loop won't be available to the rest of the page however I don't think a loop is necessary here.
<?php
include("Connections/mysql.php");
mysql_select_db('rubygir_slappyjaw', $mysql);
$myid = $_SESSION['kt_login_id'];
$result = mysql_query("SELECT * FROM friendreqs WHERE foridus2=$myid") or die(mysql_error());
$row = mysql_fetch_array($result);
$userfrom = $row['userfrom'];
$usertime = $row['time'];
mysql_close($mysql);
$title = "Friend request";
//INCLUDE THE HEADER!
include("user_header.php");
?>
<html>
<body>
<table width="200" border="1">
<tr>
<td><?php echo $userfrom;?> </td>
<td><?php echo $usertime;?></td>
</tr>
</table>
</body>
</html>
Also STOP using short open e.g. <? as to <?php. They only cause problems. When PHP6 is released your code won't work.
slappyjaw 08-29-2009, 01:34 AM yea idk why i put that there i removed it but it throws the error 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 '' at line 1
Also even if i try to create something like this with dreamweaver it will not show the results.
whizard 08-29-2009, 01:37 AM Where is $myid coming from? Can you echo it out to see if it is set?
I realize its a session var but i mean where is it being set
Odd though, usually the mysql error prints out some context so you can see where the error is.
Dan
slappyjaw 08-29-2009, 01:41 AM hmmmm dan i see what you mean the myid is not set for some reasion. it is set when you log in. will a session variable stay registered through out the site when you are logged in?
whizard 08-29-2009, 01:43 AM oh, duh lol.
You need session_start() at the top of every page. I swear I make that mistake at least twice every time i work on a site
To answer your question, yes a SESSION var will stay set as long as the SESSION hasn't expired. I believe there can also be some issues across subdomains as well.
Dan
slappyjaw 08-29-2009, 01:44 AM oh ok hahaha ill try that now. thanks
slappyjaw 08-29-2009, 01:45 AM oh yea now its working wow i am going to add that to all my headers, thanks a lot dan!
whizard 08-29-2009, 01:46 AM no problem!
slappyjaw 08-29-2009, 04:13 AM <?php require_once('../../Connections/mysql.php'); ?>
<?php
$userid1 = $_POST['userid15'];
$userid2 = $_POST['userid25'];
$username1 = $_POST['username15'];
$username2 = $_POST['username25'];
$idremove = $_POST['idremove5'];
mysql_select_db('rubygir_slappyjaw', $mysql);
mysql_query("INSERT INTO friends (userid1, userid2, username1, username2) VALUES ($userid1, $userid2, $username1, $username2)") or die(mysql_error());
mysql_query("DELETE FROM friendreqs WHERE id = $idremove") or die(mysql_error());
?> I used some of the same rules but i think that there is something wrong in the mysql query part. the error says Unknown column 'slappyjaw' in 'field list' and slappyjaw is the $username1 submitted data.
Is it ok that i am trying to insert and delete something in the file. Its for my friend request system.
whizard 08-29-2009, 04:40 AM Are you sure that's the exact and total code...it doesn't seem like that error is possible from that code. The error is saying that you are trying to put something into a column named 'slappyjaw', which you are not trying to do in that code.....
This error could happen easily if you accidentally put a dollar sign in front of the username1 column name...
slappyjaw 08-29-2009, 04:43 AM yes thats what i said because it makes no scene.
whizard 08-29-2009, 04:44 AM OK, do this.
<?php require_once('../../Connections/mysql.php'); ?>
<?php
$userid1 = $_POST['userid15'];
$userid2 = $_POST['userid25'];
$username1 = $_POST['username15'];
$username2 = $_POST['username25'];
$idremove = $_POST['idremove5'];
mysql_select_db('rubygir_slappyjaw', $mysql);
$query = "INSERT INTO friends (userid1, userid2, username1, username2) VALUES ($userid1, $userid2, $username1, $username2)";
mysql_query($query) or die(mysql_error());
print $query;
mysql_query("DELETE FROM friendreqs WHERE id = $idremove") or die(mysql_error());
?>
That way it will print out the query, and we can at least see what its sending
slappyjaw 08-29-2009, 04:47 AM mm its still displays that error. could it be the server
whizard 08-29-2009, 04:48 AM oops, my bad i put the print after the die() move it before the die() command so it will print out the query you are using
slappyjaw 08-29-2009, 04:53 AM oh ok
whizard 08-29-2009, 04:53 AM OK let me know how it turns out
slappyjaw 08-29-2009, 04:57 AM INSERT INTO friends (userid1, userid2, username1, username2) VALUES (1, 2, slappyjaw, cuakster)Unknown column 'slappyjaw' in 'field list' thats what it displayed
whizard 08-29-2009, 05:07 AM Well thats just stupid. Try putting backticks around the table and column names and single quotes around the variables.
Dan
slappyjaw 08-29-2009, 05:11 AM yep ok i got it working thanks dan for all the help!
whizard 08-29-2009, 05:19 AM :thumbsup:
slappyjaw 08-29-2009, 05:24 AM ok haha one last question. in a sql query can you make it so that the WHERE clause can either equal one thing or another.
whizard 08-29-2009, 05:37 AM yup
http://forums.digitalpoint.com/showthread.php?t=132300
Dan
|
|