|
-
Jun 16th, 2013, 07:23 PM
#1
Thread Starter
Frenzied Member
nserting the record
Hello,
I was wondering if any of you can help me please.
My problem is im trying to get this code to insert the record in to my table it says its been added to the database but when i check its not can anyone see whats wrong please?.
PHP Code:
<?php $title = "MBAPPZ.com - Create A New Message"; ?>
<?php require("styles/top.php"); ?>
<div id='left'>
<?php
if($username){
echo "Create New Message<br /><br />";
$form = "<form action='create_message.php' method='POST'><table>
<tr>
<td><input type='text' name='sendtouser' size='30' class='textbox'></td>
</tr>
<tr>
<td><input type='text' name='subject' size='30' class='textbox'></td>
</tr>
<tr>
<td><textarea name='content' cols='45' rows='7' class='textbox'></textarea></td>
</tr>
<tr>
<td><input type='submit' name='sendbutton' value='Send Message' class='button'></td>
</tr>
</table></form>";
if ($_POST['sendbutton']){
$sendtouser = $_POST['sendtouser'];
$subject = $_POST['subject'];
$content = $_POST['content'];
if ($sendtouser && $subject && $content){
require('scripts/connect.php');
$query = mysql_query("SELECT * FROM users WHERE username='$sendtouser'");
$numrows = mysql_num_rows($query);
if ($numrows == 1){
$row = mysql_fetch_assoc($query);
$to_user = $row['username'];
$to_id = $row['id'];
$date = date("M d, Y");
$query = mysql_query("SELECT * FROM messages WHERE content='$content' AND to_id='$to_id' AND from_id='$userid' AND date='$date'");
$numrows = mysql_num_rows($query);
if ($numrows == 0){
mysql_query("INSERT INTO messages VALUES ('', '$to_user', '$to_id', '$username', '$userid', '$subject', '$content', '$date')");
echo "Your message has been sent. <a href='inbox.php'>Click Here</a> to return to your inbox.";
}
else
echo "You can not resend the same message again. $form";
}
else
echo "The username you have entered is invalid please try again. $form";
}
else
echo "You did not fill the entire message form. $form";
}
else
echo "$form";
}
else
echo "You must be logged in to view this page sorry.";
?>
</div>
<div id='right'>
Advertisements Coming Soon.
</div>
<?php require("styles/bottom.php"); ?>
Thanks in advance.
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Jun 16th, 2013, 09:22 PM
#2
Re: nserting the record
What are the fields you are inserting the data into?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jun 17th, 2013, 03:40 AM
#3
Re: nserting the record
Replace you insert line with this to see if it throws an error message:
PHP Code:
mysql_query("INSERT INTO messages VALUES ('', '$to_user', '$to_id', '$username', '$userid', '$subject', '$content', '$date')") or DIE(mysql_error());
What that will do is stop your script and display an error message, if an error occurs. Sounds like your form data is OK but there is something wrong with that line.
-
Jun 17th, 2013, 04:37 AM
#4
Thread Starter
Frenzied Member
Re: nserting the record
I added what u said and I get an error saying.
Column count doesn't match value count at row 1
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Jun 17th, 2013, 05:59 AM
#5
Re: nserting the record
 Originally Posted by Jamie_Garland
I added what u said and I get an error saying.
Column count doesn't match value count at row 1
Hence my question in post #2. You are being asked to supply the same amount of cells as data, in this case 8 columns, 8 values.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jun 17th, 2013, 07:56 AM
#6
Thread Starter
Frenzied Member
Re: nserting the record
I have 2 extra things in my database that are not in my query.
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Jun 17th, 2013, 07:25 PM
#7
Re: nserting the record
It would be wise to insert like this:
Code:
INSERT INTO table ('id', 'name', 'lastname', 'phonenumber', 'etc') VALUES ('1', 'john', 'doe', '7141234567', 'taco')
or
Code:
INSERT INTO table SET id = '1', name='john', lastname='doe'.... etc
-
Jun 20th, 2013, 01:50 PM
#8
Fanatic Member
Re: nserting the record
irrelevant to the question but i would suggest using this way to determine if the form was posted
PHP Code:
if ($_SERVER['REQUEST_METHOD'] == "POST") {
}
relevant:
what you need to do is
PHP Code:
mysql_query("INSERT INTO messages ('field1', 'field2') VALUES ('value1', 'value2')");
also you need to have a way to determine if the database did update at all. mysql_affected_rows
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|