Jump to content

T strings.


dean7

Recommended Posts

when you setup the database you had to select a type (ex. varchar, int, date). Basically what is happening is that something in the query has an invalid character which can be fixed by mysql_real_escape_string, but if the date you are entering is a date field it wont work. you can try this though:

 

<?php
///////////// Start Of New Code ///////////////
///////////// Add Comment On Profile //////////

include ("config.php");
include ("makelogin.php");

////////////// Includes //////////////////

$username = $logged['username'];
$ul = $logged['userlevel'];
$msg=strip_tags($_POST['msg']);
$date = gmdate('Y-m-d h:i:s');

$username = mysql_real_escape_string($username);
$msg = mysql_real_escape_string($msg);
$date = mysql_real_escape_string($date);

///////////// Starting Varibals //////////////////

$query=mysql_query("SELECT * FROM users WHERE username='$username' LIMIT 1");
$fetch=mysql_fetch_object($query);

///////////// Querys /////////////////////////

if ($_POST['submit'])
{
///////////////////// Line 158 is The One BELOW This ////////////////////////////////// 
mysql_query("INSERT INTO pmessages (id,title,from,message,date,unread) VALUES('','Profile Comment','$username','$msg','$date','unread')") or die(mysql_error());
echo "<font color='black'>Comment Sent To $username!";
}


///////////// Sending The Comment They Sent ///////////////////
?>

<html>
<form method="post" action="">
<table width='80%' cellspacing='0' cellpadding='0' border='1' bordercolor='#000000'>
<tr>
<td>
  <p align="center">Comment To Send: <br>
</td>
</tr>
<tr>
<td>
    <textarea name="msg" cols="40" rows="8" id="msg"></textarea>
</td>

   


</tr>
<tr>
</td>
    <input type="submit" name="submit" value="Send Comment">
</td>
</tr>
</table>
</form>
</html>

Link to comment
https://forums.phpfreaks.com/topic/174063-t-strings/page/2/#findComment-917574
Share on other sites

when you setup the database you had to select a type (ex. varchar, int, date). Basically what is happening is that something in the query has an invalid character which can be fixed by mysql_real_escape_string, but if the date you are entering is a date field it wont work. you can try this though:

 

<?php
///////////// Start Of New Code ///////////////
///////////// Add Comment On Profile //////////

include ("config.php");
include ("makelogin.php");

////////////// Includes //////////////////

$username = $logged['username'];
$ul = $logged['userlevel'];
$msg=strip_tags($_POST['msg']);
$date = gmdate('Y-m-d h:i:s');

$username = mysql_real_escape_string($username);
$msg = mysql_real_escape_string($msg);
$date = mysql_real_escape_string($date);

///////////// Starting Varibals //////////////////

$query=mysql_query("SELECT * FROM users WHERE username='$username' LIMIT 1");
$fetch=mysql_fetch_object($query);

///////////// Querys /////////////////////////

if ($_POST['submit'])
{
///////////////////// Line 158 is The One BELOW This ////////////////////////////////// 
mysql_query("INSERT INTO pmessages (id,title,from,message,date,unread) VALUES('','Profile Comment','$username','$msg','$date','unread')") or die(mysql_error());
echo "<font color='black'>Comment Sent To $username!";
}


///////////// Sending The Comment They Sent ///////////////////
?>

<html>
<form method="post" action="">
<table width='80%' cellspacing='0' cellpadding='0' border='1' bordercolor='#000000'>
<tr>
<td>
  <p align="center">Comment To Send: <br>
</td>
</tr>
<tr>
<td>
    <textarea name="msg" cols="40" rows="8" id="msg"></textarea>
</td>

   


</tr>
<tr>
</td>
    <input type="submit" name="submit" value="Send Comment">
</td>
</tr>
</table>
</form>
</html>

that still displays the error. But if i have to i could do it so i dont have the date there?

Link to comment
https://forums.phpfreaks.com/topic/174063-t-strings/page/2/#findComment-917576
Share on other sites

other than what I have show you there is no reason why this shouldnt be working unless there is something in the code that I am missing. if you want to insert the date I would suggest that you use an int as the type for the date and insert a timestamp. for example:

 

$date = timestamp();

 

Then when you want the show the date you would do:

$date = timestamp(); //you would pull the date here but just as an example
$actual_date = date("m/d/y",$date);

 

If I were you I would make sure that the tables you are trying to insert to are the correct type (check in phpmyadmin). The username and msg should be varchar and date if you use what i said should be int. Also you can remove the strip_tags() from $msg as long as you use mysql_real_escape_string(). mysql_real_escape_string should be run on any data that is put in a query because it makes it database safe thus preventing mysql errors. I would try taking the date out for now and see if it works without it and if so then it has something to do with the type or the actual date that you are trying to insert. Any more questions just ask

Link to comment
https://forums.phpfreaks.com/topic/174063-t-strings/page/2/#findComment-917579
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.