Staredit Network > Forums > Technology & Computers > Topic: Some PHP Questions
Some PHP Questions
Jan 2 2009, 9:58 pm
By: Devourer  

Jan 2 2009, 9:58 pm Devourer Post #1

Hello

Hi again,
yea, I've got another glitch in one of my PHP codes and I already googled, but all I found seems to be the same as I have.

I want to set a mysql column named "shouts" +1, so for each shout it gets +1. the coloumn "is null".
I've got an index.php where the shoutbox is displayed, and when you press the submit button the information is sent to the insertshout.php

here the file, insertshout.php
<?php

//This will start a session
session_start();

$username = $_SESSION['user'];


$con = mysql_connect("localhost","youdontneedtoknowthis","youdontneedtoknowthiseither");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("browsergamesc", $con);



if ("$_POST[message]"=="")
{ echo "No Message to post! <a href=index.php> Back </a>"; }
else {
if ("$username"=="") { echo "You are not logged in! <a href=index.php>Back</a>"; }
else {

$time = date('H:i:s');

mysql_query("UPDATE users SET shouts=shouts+1
WHERE username = $username");


$sql="INSERT INTO shoutbox (time, username, color, message)
VALUES
('$time','$username','$_POST[color]','$_POST[message]')";

}
}
if (!mysql_query($sql,$con))
{
die;
}

echo "Shouted, <a href=index.php> back </a>";
mysql_close($con);
?>


anyone help me? :)
I colord the thing which seems that doesn't work.

Post has been edited 2 time(s), last time on Jan 3 2009, 1:32 pm by DeVouReR.



Please report errors in the Staredit.Network forum.

Jan 3 2009, 2:23 am Forsaken Archer Post #2



Make sure the column is an integer type set to 0? I'm not completely sure what you mean by the column is null. Do you get an errors?



None.

Jan 3 2009, 11:20 am Devourer Post #3

Hello

Quote from name:isolatedpurity
Make sure the column is an integer type set to 0? I'm not completely sure what you mean by the column is null. Do you get an errors?
No errors, the message even get shouted, that works.

I mean in the MySQL Database the coloumn "shouts" has "null" checked (there is a otpion "is null?" the selections are "Null" or "Not Null")



Please report errors in the Staredit.Network forum.

Jan 3 2009, 1:24 pm Forsaken Archer Post #4



Oh. Duh. You need to encase $username in some type of quotes because it's not an integer.
mysql_query("UPDATE users SET shouts=shouts+1 WHERE username = '{$username}'");
You should generally try to get all sql commands to give an error if they fail for testing, like the "if (!mysql_query($sql,$con)) {die;}" after.



None.

Jan 3 2009, 1:31 pm Devourer Post #5

Hello

Oh, thank you IP, it works now :)
but here's another glitch I want to fix.
The shout-count only "refreshs" when you re-login.
Help me (again) please :)

Here is the "currentmember.php" which shows the data's of your current logged in user.
<html>
<head>
<LINK href="style.css" rel="stylesheet" type="text/css">
<title> Member </title>
</head>
<body background=bilder/background.jpg>
<center>
<table border=1 width=90% height=99%>
<tr><td bgcolor=black height=5%><center><font color="FF0033"> <a href=register.php>Register</a> ::
<a href=login.php>Login</a> :: <a href=index.php>Index</a></font></center></td></tr>
<tr><td bgcolor=black><center><font color="FF0033">



<table border=1>
<tr><td bgcolor=black><center><font color=white> Username: </font></center></td>
<td bgcolor=black><center><font color=white> <?php session_start(); echo "".$_SESSION['user'].""; ?> </font></center></td>

<tr><td bgcolor=black><center><font color=white> Geld: </font></center></td>
<td bgcolor=black><center><font color=white> <?php session_start(); echo "".$_SESSION['geld'].""; ?> </font></center></td>

<tr><td bgcolor=black><center><font color=white> Avatar: </font></center></td>
<td bgcolor=black><center><font color=white> <?php session_start(); echo "<img src=avatars/".$_SESSION['avatar'].">"; ?> </font></center></td>

<tr><td bgcolor=black><center><font color=white> Joined: </font></center></td>
<td bgcolor=black><center><font color=white> <?php session_start(); echo "".$_SESSION['joined'].""; ?> </font></center></td>

<tr><td bgcolor=black><center><font color=white> Posts: </font></center></td>
<td bgcolor=black><center><font color=white> <?php session_start(); echo "".$_SESSION['posts'].""; ?> </font></center></td>

<tr><td bgcolor=black><center><font color=white> Topics: </font></center></td>
<td bgcolor=black><center><font color=white> <?php session_start(); echo "".$_SESSION['topics'].""; ?> </font></center></td>

<tr><td bgcolor=black><center><font color=white> Shouts: </font></center></td>
<td bgcolor=black><center><font color=white> <?php session_start(); echo "".$_SESSION['shouts'].""; ?> </font></center></td>
</table>
<table border=1><tr height=30%><colgroup width=500></colgroup>
<td bgcolor=black <center>



<?php
$username = $_SESSION['user'];
$password = $_SESSION['pass'];
$geld = $_SESSION['geld'];


$con = mysql_connect("localhost","sadsadsadsadsadsada","sdfffffffffffsdf");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("browsergamesc", $con);

$result = mysql_query("SELECT * FROM shoutbox ORDER BY `id` DESC LIMIT 0 , 5");


while($row = mysql_fetch_array($result))
{
echo "<bgcolor=grey><font color='0000FF'> " . $row['time'] . " </font>- ";
echo "<bgcolor=grey><font color='66FF00'> " . $row['username'] . " </font>- ";
echo "<bgcolor=grey><font color=' " . $row['color'] . " '> ";
echo "<bgcolor=grey> " . $row['message'] . " </font> </br>";
}

echo '<form action="index.php" method="post"></br>';
echo '<select name="color" size="">';
echo '<option value="FFFFFF"> <font color="FFFFFF"> White </font></option>';
echo '<option value="FF0000"> <font color="FF0000"> Red </font></option>';
echo '<option value="00CC00"> <font color="00CC00"> Green </font></option>';
echo '<option value="0000FF"> <font color="0000FF"> Blue </font></option>';
echo '</select>';
echo ' - ';
echo '<font color="FF0033">Message: <input type="text" name="message" /> </br>';
echo '<input type="submit" value="Shout"/>';
echo '</form>';
?>




<?php

//This will start a session
session_start();

$username = $_SESSION['user'];


$con = mysql_connect("localhost","bsdfsdfsdfdsmdsfsdc","dfssdfsdfsdfsdf");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("browsergamesc", $con);



if ("$_POST[message]"=="")
{ echo " "; }
else {
if ("$username"=="") { echo "You are not logged in!"; }
else {

$time = date('H:i:s');

mysql_query("UPDATE users SET shouts=shouts+1
WHERE username = $username");

$sql="INSERT INTO shoutbox (time, username, color, message)
VALUES
('$time','$username','$_POST[color]','$_POST[message]')";

}
}
if (!mysql_query($sql,$con))
{
die;
}


mysql_close($con);
?>





</font></center></td></tr>
</table>
</body>
<foot>
</foot>
</html>


Post has been edited 1 time(s), last time on Jan 3 2009, 5:55 pm by DeVouReR.



Please report errors in the Staredit.Network forum.

Jan 3 2009, 1:34 pm Forsaken Archer Post #6



Because you are storing shouts into a session variable. Unless you call the query every time the page loads, outside of the login, it will only refresh when the variable is made again. Something to do would be after the +1 shout query, add $_SESSION['shouts']++;



None.

Jan 3 2009, 1:40 pm Devourer Post #7

Hello

Wow, thank you IP, but I even got more questions x)
When I shout something It only appears after the next refresh, how do I change that?
thx for helping.



Please report errors in the Staredit.Network forum.

Jan 3 2009, 1:43 pm Forsaken Archer Post #8



Make it refresh for them in an iframe or the whole page if the page is just a shoutbox.
Or learn ajax.



None.

Jan 3 2009, 1:55 pm Devourer Post #9

Hello

Quote from name:isolatedpurity
Make it refresh for them in an iframe or the whole page if the page is just a shoutbox.
Or learn ajax.
I cannot find in w3schools how to refresh an iframe. Can you explain it please? :-(



Please report errors in the Staredit.Network forum.

Jan 3 2009, 1:58 pm Forsaken Archer Post #10



google.
http://bytes.com/groups/javascript/468654-refresh-iframe
http://www.codingforums.com/showthread.php?t=78821



None.

Jan 3 2009, 2:07 pm Devourer Post #11

Hello

oh, my fault, anyway I tried this, here is the code
the iframe is colord and the java script too
<html>
<head>


<script type="text/javascript">

function Reload () {
var f = document.getElementById('iframe1');
f.src = f.src;
}

</script>


<LINK href="style.css" rel="stylesheet" type="text/css">

<title> Portal </title>
</head>
<body background=bilder/background.jpg>
<center>
<table border=1 width=90% height=99%>
<tr><td bgcolor=black height=5%><center><font color="FF0033"> <a href=register.php>Register</a> ::
<a href=login.php>Login</a> :: <a href=memberlist.php>Members</a> </font></center></td></tr>
<tr><td bgcolor=black><center><font color="FF0033"> Momentan keine Portal-News vorhanden.</font></center></td></tr></table>
<table border=1><tr height=30%><colgroup width=500></colgroup>
<td bgcolor=black <center>


<iframe id="iframe1">
<?php
$username = $_SESSION['user'];
$password = $_SESSION['pass'];
$geld = $_SESSION['geld'];


$con = mysql_connect("localhost","sdadadadadadadadadadadadada","dsafsafsadsadsafsaf");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("browsergamesc", $con);

$result = mysql_query("SELECT * FROM shoutbox ORDER BY `id` DESC LIMIT 0 , 5");


while($row = mysql_fetch_array($result))
{
echo "<bgcolor=grey><font color='0000FF'> " . $row['time'] . " </font>- ";
echo "<bgcolor=grey><font color='66FF00'> " . $row['username'] . " </font>- ";
echo "<bgcolor=grey><font color=' " . $row['color'] . " '> ";
echo "<bgcolor=grey> " . $row['message'] . " </font> </br>";
}

echo '<form action="index.php" method="post"></br>';
echo '<select name="color" size="">';
echo '<option value="FFFFFF"> <font color="FFFFFF"> White </font></option>';
echo '<option value="FF0000"> <font color="FF0000"> Red </font></option>';
echo '<option value="00CC00"> <font color="00CC00"> Green </font></option>';
echo '<option value="0000FF"> <font color="0000FF"> Blue </font></option>';
echo '</select>';
echo ' - ';
echo '<font color="FF0033">Message: <input type="text" name="message" /> </br>';
echo '<input type="submit" value="Shout"/>';
echo '<input type="button" value="Refresh" onclick="Reload();">';
echo '</form>';
?>




<?php

//This will start a session
session_start();

$username = $_SESSION['user'];


$con = mysql_connect("localhost","sadddddddddddddddddddd","sadsadsadsadsad");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("browsergamesc", $con);



if ("$_POST[message]"=="")
{ echo " "; }
else {
if ("$username"=="") { echo "You are not logged in!"; }
else {

$time = date('H:i:s');

mysql_query("UPDATE users SET shouts=shouts+1
WHERE username = '{$username}'");

$_SESSION['shouts']++;

$sql="INSERT INTO shoutbox (time, username, color, message)
VALUES
('$time','$username','$_POST[color]','$_POST[message]')";

}
}
if (!mysql_query($sql,$con))
{
die;
}


mysql_close($con);
?>
</iframe>


</table>
</body>
<foot>
</foot>
</html>



and here is the solution:

the shoutbox is in the bottom <td> (table data) which is smaller than the one above.

Post has been edited 1 time(s), last time on Jan 3 2009, 4:39 pm by DeVouReR.



Please report errors in the Staredit.Network forum.

Jan 3 2009, 6:30 pm Forsaken Archer Post #12



So what's the problem?



None.

Jan 3 2009, 7:02 pm Devourer Post #13

Hello

Quote from name:isolatedpurity
So what's the problem?
The Shoutbox isn't displayed anymore... there is just another <td> inside the down <td>



Please report errors in the Staredit.Network forum.

Jan 3 2009, 9:00 pm Jello-Jigglers Post #14



and here is the solution:

the shoutbox is in the bottom <td> (table data) which is smaller than the one above.[/quote]

Why did you blur your toolbar?? Why don't you just use code from another websites shoutbox(assuming you get permission?)



None.

Jan 3 2009, 9:02 pm Devourer Post #15

Hello

Quote from Jello-Jigglers
and here is the solution:

the shoutbox is in the bottom <td> (table data) which is smaller than the one above.

Why did you blur your toolbar?? Why don't you just use code from another websites shoutbox(assuming you get permission?)

This post from you should be deleted... not helpfull.
Because noone should know the address of the page lol
Because I want LEARN it.



Please report errors in the Staredit.Network forum.

Jan 5 2009, 1:05 pm Forsaken Archer Post #16



Quote
Because I want LEARN it.
Then learn it? Asking for help on every little thing isn't doing much for you.
Take the code out of the iframe code and make the iframe link to a page. The page is your shoutbox. A page inside a page.



None.

Jan 5 2009, 1:26 pm Devourer Post #17

Hello

Quote from name:isolatedpurity
Quote
Because I want LEARN it.
Then learn it? Asking for help on every little thing isn't doing much for you.
Take the code out of the iframe code and make the iframe link to a page. The page is your shoutbox. A page inside a page.

I ask for help when something doesn't works...



Please report errors in the Staredit.Network forum.

Jan 8 2009, 1:26 pm Devourer Post #18

Hello

Please finally help me... the <iframe> just doesn't work...



Please report errors in the Staredit.Network forum.

Jan 8 2009, 9:51 pm Forsaken Archer Post #19



It should be something like <iframe src="shoutbox.php"></iframe>



None.

Jan 9 2009, 12:48 am Centreri Post #20

Relatively ancient and inactive

Tips:

1) Simple things first. Eliminate the PHP until you get the basic HTML working.
2) Google how you use a) functions b) tags. You're using iFrame incorrectly, where a single search would've fixed it.
3) If you're learning it, try to be a bit independent...



None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[03:45 am]
Sylph-Of-Space -- Does the shoutbox get disabled when there's spammers?
[06:47 am]
NudeRaider -- lil-Inferno
lil-Inferno shouted: nah
strong
[05:41 am]
Ultraviolet -- 🤔 so inf is in you?
[04:57 am]
O)FaRTy1billion[MM] -- my name is mud
[04:35 am]
Ultraviolet -- mud, meet my friend, the stick
[2024-5-16. : 10:07 pm]
lil-Inferno -- nah
[2024-5-16. : 8:36 pm]
Ultraviolet -- Inf, we've got a job for you. ASUS has been very naughty and we need our lil guy to go do their mom's to teach them if they fuck around, they gon' find out
[2024-5-16. : 5:25 pm]
NudeRaider -- there he is, right on time! Go UV! :D
[2024-5-16. : 5:24 pm]
lil-Inferno -- poopoo
[2024-5-16. : 5:14 pm]
UndeadStar -- I wonder if that's what happened to me. A returned product (screen) was "officially lost" for a while before being found and refunded. Maybe it would have remained "lost" if I didn't communicate?
Please log in to shout.


Members Online: Sylph-Of-Space, 1madisonc911rb1